Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@hammerstone/refine-stimulus

Package Overview
Dependencies
Maintainers
4
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@hammerstone/refine-stimulus - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

app/javascript/controllers/refine/toggle-controller.js

2

app/assets/javascripts/refine-stimulus.esm.js

@@ -1,2 +0,2 @@

import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as r,abnegate as i}from"jquery-events-to-dom-events";import{isEqual as n,debounce as o}from"lodash";import s from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){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}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{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}}u.values={criterionId:Number,input:Object};class c extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}c.values={criterionId:Number};class h extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}h.values={submitUrl:String};class p extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}p.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const m=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},f=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=o;let d={clause:null==(i=l[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return s.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class b extends e{connect(){this.element.refineStateController=this,this.changeDelegate=r("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(f(t.id,1,t)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},f(i.id,1,i)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,s=n||!r,l=s&&o;r||i?t.splice(l&&n?e-1:l&&!r||s&&!o?e:e-1,2):this.blueprint=[],m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));const o=this.blueprint[e],s=f(t,i.depth,r);return!n(o,s)&&(this.blueprint[e]=s,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}b.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},b.targets=["loading"];class g extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}g.targets=["blueprintField"],g.values={formId:String,stateDomId:String};class v extends a{initialize(){this.updateBlueprint=o((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}v.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class C extends e{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=s(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}C.targets=["field","hiddenField"];const I=[[d,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[h,"refine/filter-pills-controller.js"],[p,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[b,"refine/state-controller.js"],[g,"refine/stored-filter-controller.js"],[v,"refine/update-controller.js"],[C,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,C as DateController,u as DefaultsController,c as DeleteController,h as FilterPillsController,p as SearchFilterController,a as ServerRefreshController,b as StateController,g as StoredFilterController,v as UpdateController,I as controllerDefinitions};
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as r,abnegate as i}from"jquery-events-to-dom-events";import{isEqual as n,debounce as o}from"lodash";import s from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){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}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{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}}u.values={criterionId:Number,input:Object};class c extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}c.values={criterionId:Number};class h extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}h.values={submitUrl:String};class p extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}p.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const m=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},f=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=o;let d={clause:null==(i=l[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return s.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class b extends e{connect(){this.element.refineStateController=this,this.changeDelegate=r("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(f(t.id,1,t)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},f(i.id,1,i)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,s=n||!r,l=s&&o;r||i?t.splice(l&&n?e-1:l&&!r||s&&!o?e:e-1,2):this.blueprint=[],m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));const o=this.blueprint[e],s=f(t,i.depth,r);return!n(o,s)&&(this.blueprint[e]=s,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}b.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},b.targets=["loading"];class g extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}g.targets=["blueprintField"],g.values={formId:String,stateDomId:String};class v extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}v.targets=["content"];class C extends a{initialize(){this.updateBlueprint=o((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}C.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I extends e{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=s(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}I.targets=["field","hiddenField"];const w=[[d,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[h,"refine/filter-pills-controller.js"],[p,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[b,"refine/state-controller.js"],[g,"refine/stored-filter-controller.js"],[v,"refine/toggle-controller.js"],[C,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,I as DateController,u as DefaultsController,c as DeleteController,h as FilterPillsController,p as SearchFilterController,a as ServerRefreshController,b as StateController,g as StoredFilterController,v as ToggleController,C as UpdateController,w as controllerDefinitions};
//# sourceMappingURL=refine-stimulus.esm.js.map

@@ -1,2 +0,2 @@

var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("jquery-events-to-dom-events"),i=require("lodash");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(require("flatpickr"));function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class s extends e.Controller{connect(){this.state.finishUpdate()}get state(){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}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class a extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}a.values={previousCriterionId:Number};class d extends e.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}}d.values={criterionId:Number,input:Object};class u extends s{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}u.values={criterionId:Number};class c extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}c.values={submitUrl:String};class h extends e.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}h.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const p=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},m=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let d={clause:null==(i=s[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class f extends e.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=r.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){r.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(m(t.id,1,t)),p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},m(i.id,1,i)),p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){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(m));const o=this.blueprint[e],l=m(t,n.depth,r);return!i.isEqual(o,l)&&(this.blueprint[e]=l,p(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}f.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},f.targets=["loading"];class b extends e.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}b.targets=["blueprintField"],b.values={formId:String,stateDomId:String};class g extends s{initialize(){this.updateBlueprint=i.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}g.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class v extends e.Controller{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=o.default(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}v.targets=["field","hiddenField"];const C=[[a,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[u,"refine/delete-controller.js"],[c,"refine/filter-pills-controller.js"],[h,"refine/search-filter-controller.js"],[s,"refine/server-refresh-controller.js"],[f,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[g,"refine/update-controller.js"],[v,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});exports.AddController=a,exports.DateController=v,exports.DefaultsController=d,exports.DeleteController=u,exports.FilterPillsController=c,exports.SearchFilterController=h,exports.ServerRefreshController=s,exports.StateController=f,exports.StoredFilterController=b,exports.UpdateController=g,exports.controllerDefinitions=C;
var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("jquery-events-to-dom-events"),i=require("lodash");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(require("flatpickr"));function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class s extends e.Controller{connect(){this.state.finishUpdate()}get state(){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}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class a extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}a.values={previousCriterionId:Number};class d extends e.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}}d.values={criterionId:Number,input:Object};class u extends s{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}u.values={criterionId:Number};class c extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}c.values={submitUrl:String};class h extends e.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}h.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const p=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},m=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let d={clause:null==(i=s[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class f extends e.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=r.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){r.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(m(t.id,1,t)),p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},m(i.id,1,i)),p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){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(m));const o=this.blueprint[e],l=m(t,n.depth,r);return!i.isEqual(o,l)&&(this.blueprint[e]=l,p(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}f.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},f.targets=["loading"];class b extends e.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}b.targets=["blueprintField"],b.values={formId:String,stateDomId:String};class g extends e.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}g.targets=["content"];class v extends s{initialize(){this.updateBlueprint=i.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}v.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class C extends e.Controller{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=o.default(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}C.targets=["field","hiddenField"];const I=[[a,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[u,"refine/delete-controller.js"],[c,"refine/filter-pills-controller.js"],[h,"refine/search-filter-controller.js"],[s,"refine/server-refresh-controller.js"],[f,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[g,"refine/toggle-controller.js"],[v,"refine/update-controller.js"],[C,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});exports.AddController=a,exports.DateController=C,exports.DefaultsController=d,exports.DeleteController=u,exports.FilterPillsController=c,exports.SearchFilterController=h,exports.ServerRefreshController=s,exports.StateController=f,exports.StoredFilterController=b,exports.ToggleController=g,exports.UpdateController=v,exports.controllerDefinitions=I;
//# sourceMappingURL=refine-stimulus.js.map

@@ -1,2 +0,2 @@

import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as i,abnegate as r}from"jquery-events-to-dom-events";import{isEqual as n,debounce as s}from"lodash";import o from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){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}async refreshFromServer(){this.state.startUpdate();const e=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":this.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"hammerstone_refine_filters_builder[client_id]":this.state.clientIdValue}});await e.perform()}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{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}}u.values={criterionId:Number,input:Object};class c extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}function h(){return h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e},h.apply(this,arguments)}c.values={criterionId:Number};class p extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var i=parseInt(t);this.stateController.deleteCriterion(i),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams(h({},Object.fromEntries(this.existingParams),Object.fromEntries(t))).toString(),r=`${window.location.pathname}?${i}`;history.pushState({},document.title,r),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class m extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults({detail:{url:e}}){console.log("filter submit success"),window.Turbo?window.Turbo.visit(e):window.location.href=e}}m.values={submitUrl:String},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 f=(e,{blueprint:t,formId:i})=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:i}});e.dispatchEvent(r)},b=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},o=(null==i?void 0:i.refinements)||[],{clauses:l,options:a}=s;let d={clause:null==(r=l[0])?void 0:r.id,selected:"option-condition"===n?[a[0].id]:void 0};return o.forEach(e=>{var t;const{meta:i,component:r}=e,{clauses:n,options:s}=i;d[e.id]={clause:n[0].id,selected:"option-condition"===r?[null==(t=s[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class g extends e{connect(){this.element.refineStateController=this,this.changeDelegate=i("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){r("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[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(b(t.id,1,t)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:i}=this,r=i[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},b(r.id,1,r)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],r=t[e+1],n=i&&"or"===i.word,s=r&&"or"===r.word||!r,o=n||!i,l=o&&s;i||r?t.splice(l&&n?e-1:l&&!i||o&&!s?e:e-1,2):this.blueprint=[],f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,i){const r=this.blueprint[e];if("criterion"!==r.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(b)}`);const s=this.blueprint[e],o=b(t,r.depth,i);return!n(s,o)&&(this.blueprint[e]=o,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,i){const{blueprint:r}=this,n=r[e],s=(i=i||"input").split(", ");s.length>1?n[s[0]][s[1]]=h({},n[s[0]][s[1]],t):n[i]=h({},n[i],t),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},g.targets=["loading"];class v extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:i}=t;this.blueprintFieldTarget.value=JSON.stringify(i),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class w extends a{initialize(){this.updateBlueprint=s((e,t,i)=>{this.value(e,t,i)},500)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}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")}value(e,t,i){const{criterionIdValue:r,state:n}=this,s=e.target.dataset;n.updateInput(r,{[i=i||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:i}=this,r=e.target;let n=r.value;n||(n=r.querySelector("select").value);const s=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}w.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class C extends e{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=o(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,i)=>{this.fieldTarget.value=i.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=i.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}C.targets=["field","hiddenField"];const I=[[d,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[m,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[w,"refine/update-controller.js"],[C,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,C as DateController,u as DefaultsController,c as DeleteController,p as FilterPillsController,m as SearchFilterController,a as ServerRefreshController,g as StateController,v as StoredFilterController,w as UpdateController,I as controllerDefinitions};
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as i,abnegate as r}from"jquery-events-to-dom-events";import{isEqual as n,debounce as s}from"lodash";import o from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){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}async refreshFromServer(){this.state.startUpdate();const e=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":this.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"hammerstone_refine_filters_builder[client_id]":this.state.clientIdValue}});await e.perform()}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{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}}u.values={criterionId:Number,input:Object};class c extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}function h(){return h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e},h.apply(this,arguments)}c.values={criterionId:Number};class p extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var i=parseInt(t);this.stateController.deleteCriterion(i),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams(h({},Object.fromEntries(this.existingParams),Object.fromEntries(t))).toString(),r=`${window.location.pathname}?${i}`;history.pushState({},document.title,r),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class m extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults({detail:{url:e}}){console.log("filter submit success"),window.Turbo?window.Turbo.visit(e):window.location.href=e}}m.values={submitUrl:String},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 f=(e,{blueprint:t,formId:i})=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:i}});e.dispatchEvent(r)},b=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},o=(null==i?void 0:i.refinements)||[],{clauses:l,options:a}=s;let d={clause:null==(r=l[0])?void 0:r.id,selected:"option-condition"===n?[a[0].id]:void 0};return o.forEach(e=>{var t;const{meta:i,component:r}=e,{clauses:n,options:s}=i;d[e.id]={clause:n[0].id,selected:"option-condition"===r?[null==(t=s[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class g extends e{connect(){this.element.refineStateController=this,this.changeDelegate=i("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){r("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[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(b(t.id,1,t)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:i}=this,r=i[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},b(r.id,1,r)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],r=t[e+1],n=i&&"or"===i.word,s=r&&"or"===r.word||!r,o=n||!i,l=o&&s;i||r?t.splice(l&&n?e-1:l&&!i||o&&!s?e:e-1,2):this.blueprint=[],f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,i){const r=this.blueprint[e];if("criterion"!==r.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(b)}`);const s=this.blueprint[e],o=b(t,r.depth,i);return!n(s,o)&&(this.blueprint[e]=o,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,i){const{blueprint:r}=this,n=r[e],s=(i=i||"input").split(", ");s.length>1?n[s[0]][s[1]]=h({},n[s[0]][s[1]],t):n[i]=h({},n[i],t),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},g.targets=["loading"];class v extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:i}=t;this.blueprintFieldTarget.value=JSON.stringify(i),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class w extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}w.targets=["content"];class C extends a{initialize(){this.updateBlueprint=s((e,t,i)=>{this.value(e,t,i)},500)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}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")}value(e,t,i){const{criterionIdValue:r,state:n}=this,s=e.target.dataset;n.updateInput(r,{[i=i||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:i}=this,r=e.target;let n=r.value;n||(n=r.querySelector("select").value);const s=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}C.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I extends e{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=o(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,i)=>{this.fieldTarget.value=i.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=i.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}I.targets=["field","hiddenField"];const S=[[d,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[m,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[w,"refine/toggle-controller.js"],[C,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,I as DateController,u as DefaultsController,c as DeleteController,p as FilterPillsController,m as SearchFilterController,a as ServerRefreshController,g as StateController,v as StoredFilterController,w as ToggleController,C as UpdateController,S 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("@rails/request.js"),require("jquery-events-to-dom-events"),require("lodash"),require("flatpickr")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","@rails/request.js","jquery-events-to-dom-events","lodash","flatpickr"],t):t((e||self).refineStimulus={},e.Stimulus,e.request_js,e.jqueryEventsToDomEvents,e.lodash,e.flatpickr)}(this,function(e,t,r,i,n,o){function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=l(o);function a(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u extends t.Controller{connect(){this.state.finishUpdate()}get state(){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}refreshFromServer(){try{const e=this;e.state.startUpdate();const t=new r.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(t.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class d extends u{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class c 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}}c.values={criterionId:Number,input:Object};class h extends u{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}h.values={criterionId:Number};class p extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class f extends t.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}f.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const m=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},b=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let u={clause:null==(i=s[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;u[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:u}};class g 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.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(b(t.id,1,t)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},b(i.id,1,i)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(b));const o=this.blueprint[e],l=b(t,i.depth,r);return!n.isEqual(o,l)&&(this.blueprint[e]=l,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},g.targets=["loading"];class v extends t.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class C extends u{initialize(){this.updateBlueprint=n.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}C.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class w extends t.Controller{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=s.default(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}w.targets=["field","hiddenField"];const I=[[d,"refine/add-controller.js"],[c,"refine/defaults-controller.js"],[h,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[f,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[C,"refine/update-controller.js"],[w,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:a(e[1]),controllerConstructor:t}});e.AddController=d,e.DateController=w,e.DefaultsController=c,e.DeleteController=h,e.FilterPillsController=p,e.SearchFilterController=f,e.ServerRefreshController=u,e.StateController=g,e.StoredFilterController=v,e.UpdateController=C,e.controllerDefinitions=I});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("@rails/request.js"),require("jquery-events-to-dom-events"),require("lodash"),require("flatpickr")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","@rails/request.js","jquery-events-to-dom-events","lodash","flatpickr"],t):t((e||self).refineStimulus={},e.Stimulus,e.request_js,e.jqueryEventsToDomEvents,e.lodash,e.flatpickr)}(this,function(e,t,r,i,n,o){function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=l(o);function a(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class d extends t.Controller{connect(){this.state.finishUpdate()}get state(){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}refreshFromServer(){try{const e=this;e.state.startUpdate();const t=new r.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(t.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class u extends d{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}u.values={previousCriterionId:Number};class c 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}}c.values={criterionId:Number,input:Object};class h extends d{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}h.values={criterionId:Number};class p extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class f extends t.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}f.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const m=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},b=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let d={clause:null==(i=s[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class g 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.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(b(t.id,1,t)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},b(i.id,1,i)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(b));const o=this.blueprint[e],l=b(t,i.depth,r);return!n.isEqual(o,l)&&(this.blueprint[e]=l,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},g.targets=["loading"];class v extends t.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class C extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}C.targets=["content"];class w extends d{initialize(){this.updateBlueprint=n.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}w.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I extends t.Controller{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=s.default(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}I.targets=["field","hiddenField"];const y=[[u,"refine/add-controller.js"],[c,"refine/defaults-controller.js"],[h,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[f,"refine/search-filter-controller.js"],[d,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[C,"refine/toggle-controller.js"],[w,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:a(e[1]),controllerConstructor:t}});e.AddController=u,e.DateController=I,e.DefaultsController=c,e.DeleteController=h,e.FilterPillsController=p,e.SearchFilterController=f,e.ServerRefreshController=d,e.StateController=g,e.StoredFilterController=v,e.ToggleController=C,e.UpdateController=w,e.controllerDefinitions=y});
//# sourceMappingURL=refine-stimulus.umd.js.map

@@ -11,2 +11,3 @@ import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers"

import StoredFilterController from './refine/stored-filter-controller'
import ToggleController from './refine/toggle-controller'
import UpdateController from './refine/update-controller'

@@ -24,2 +25,3 @@ import DateController from './refine/date-controller'

[StoredFilterController, 'refine/stored-filter-controller.js'],
[ToggleController, 'refine/toggle-controller.js'],
[UpdateController, 'refine/update-controller.js'],

@@ -45,4 +47,5 @@ [DateController, 'refine/date-controller.js']

StoredFilterController,
ToggleController,
UpdateController,
DateController
}

@@ -0,1 +1,6 @@

### 2.4.1
* Remove loading div from filter_builder_dropdown
* Remove dependency on stimulus reveal stimulus controller
### 2.4.0

@@ -2,0 +7,0 @@ * Refactor of query and builder object. Breaking change for existing implementations. PR #86

{
"name": "@hammerstone/refine-stimulus",
"version":"2.4.0",
"version":"2.4.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": [

@@ -31,3 +31,3 @@ ## How to integrate the refine filter

Depending on how you import Stimulus Controllers and define `application` it may be `Stimulus.load(refineControllers)`
## Troubleshooting Stimulus Controllers
### Troubleshooting Stimulus Controllers
To make sure the Stimulus controllers are loaded properly, add `window.Stimulus=application` to `controllers/index.js`

@@ -52,2 +52,4 @@ Then in the console inspect the stimulus object:

Add to `index.js` or wherever you added your stimulus controllers
```

@@ -108,2 +110,9 @@ import jquery from 'jquery'

### Notes for Pagy/Jumpstart
```
apply_filter(ContactsFilter, initial_query: (Contact.sort_by_params(params[:sort], sort_direction))
@pagy, @contacts = pagy(@refine_filter.get_query)
```
This is a helper method you can inspect in `Hammerstone::FilterApplicationController`. You probably *do not* want to use this method but want to implement your own. It will return `@refine_filter` which is generated from the stable_id. The `stable_id` comes in from the params when the form is submitted or the URL is directly changed.

@@ -133,3 +142,3 @@

13. If the gems tailwind styles are being purged with JIT you can add the gem to `tmp/gems` and add this to your tailwing config.
~13. If the gems tailwind styles are being purged with JIT you can add the gem to `tmp/gems` and add this to your tailwing config.~

@@ -143,3 +152,3 @@ ``` tailwind.config.js

Run the following rake task:
~Run the following rake task:~
```

@@ -146,0 +155,0 @@ task :add_temp_gems do

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc