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.3.11 to 2.3.12

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:{filter:e.state.filterName,blueprint:JSON.stringify(e.state.blueprint),form_id:e.state.formIdValue}});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}}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,formId:String,refreshUrl:String},b.targets=["loading"];class g extends e{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintValue=r,this.setBlueprintFieldFromValue(null)}setBlueprintFieldFromValue(e){this.hasBlueprintFieldTarget&&(this.blueprintFieldTarget.value=JSON.stringify(this.blueprintValue))}}g.targets=["blueprintField"],g.values={id:Number,stableId:String,filterName:String,formId:String,blueprint:Array};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:{filter:e.state.filterName,blueprint:JSON.stringify(e.state.blueprint),form_id:e.state.formIdValue}});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});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,formId:String,refreshUrl:String},b.targets=["loading"];class g extends e{connect(){const e=document.getElementById("query_hammerstone_refine_filter_forms_form_"+this.formIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprintValue),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};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 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/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,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:{filter:e.state.filterName,blueprint:JSON.stringify(e.state.blueprint),form_id:e.state.formIdValue}});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}}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,formId:String,refreshUrl:String},f.targets=["loading"];class b extends e.Controller{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintValue=r,this.setBlueprintFieldFromValue(null)}setBlueprintFieldFromValue(e){this.hasBlueprintFieldTarget&&(this.blueprintFieldTarget.value=JSON.stringify(this.blueprintValue))}}b.targets=["blueprintField"],b.values={id:Number,stableId:String,filterName:String,formId:String,blueprint:Array};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:{filter:e.state.filterName,blueprint:JSON.stringify(e.state.blueprint),form_id:e.state.formIdValue}});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 u 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}}u.values={criterionId:Number,input:Object};class d extends s{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}d.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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});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({filter:e.stateController.filterName,blueprint:JSON.stringify(r),form_id:e.stateController.formIdValue})});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 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 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,formId:String,refreshUrl:String},f.targets=["loading"];class b extends e.Controller{connect(){const e=document.getElementById("query_hammerstone_refine_filter_forms_form_"+this.formIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprintValue),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};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"],[u,"refine/defaults-controller.js"],[d,"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=u,exports.DeleteController=d,exports.FilterPillsController=c,exports.SearchFilterController=h,exports.ServerRefreshController=s,exports.StateController=f,exports.StoredFilterController=b,exports.UpdateController=g,exports.controllerDefinitions=C;
//# 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:{filter:this.state.filterName,blueprint:JSON.stringify(this.state.blueprint),form_id:this.state.formIdValue}});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({filter:this.stateController.filterName,blueprint:JSON.stringify(e),form_id:this.stateController.formIdValue})});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({filter:this.stateController.filterName,blueprint:JSON.stringify(e),form_id:this.stateController.formIdValue})});await i.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}}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,formId:String,refreshUrl:String},g.targets=["loading"];class v extends e{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:i}=t;this.blueprintValue=i,this.setBlueprintFieldFromValue(null)}setBlueprintFieldFromValue(e){this.hasBlueprintFieldTarget&&(this.blueprintFieldTarget.value=JSON.stringify(this.blueprintValue))}}v.targets=["blueprintField"],v.values={id:Number,stableId:String,filterName:String,formId:String,blueprint:Array};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 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}async refreshFromServer(){this.state.startUpdate();const e=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{filter:this.state.filterName,blueprint:JSON.stringify(this.state.blueprint),form_id:this.state.formIdValue}});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 r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}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 r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,r=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({filter:this.stateController.filterName,blueprint:JSON.stringify(e),form_id:this.stateController.formIdValue})});await r.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams(h({},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 m extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,r=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({filter:this.stateController.filterName,blueprint:JSON.stringify(e),form_id:this.stateController.formIdValue})});await r.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 r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const f=(e,{blueprint:t,formId:r})=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:r}});e.dispatchEvent(i)},b=(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 g 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,f(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(b(t.id,1,t)),f(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)),f(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=[],f(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],s=b(t,i.depth,r);return!n(o,s)&&(this.blueprint[e]=s,f(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]]=h({},n[o[0]][o[1]],t):n[r]=h({},n[r],t),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,formId:String,refreshUrl:String},g.targets=["loading"];class v extends e{connect(){const e=document.getElementById(`query_hammerstone_refine_filter_forms_form_${this.formIdValue}`).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprintValue),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};class w 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())}}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=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"],[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};
//# 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:{filter:e.state.filterName,blueprint:JSON.stringify(e.state.blueprint),form_id:e.state.formIdValue}});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({filter:e.stateController.filterName,blueprint:JSON.stringify(t),form_id:e.stateController.formIdValue})});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({filter:e.stateController.filterName,blueprint:JSON.stringify(t),form_id:e.stateController.formIdValue})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}}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,formId:String,refreshUrl:String},g.targets=["loading"];class v extends t.Controller{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintValue=r,this.setBlueprintFieldFromValue(null)}setBlueprintFieldFromValue(e){this.hasBlueprintFieldTarget&&(this.blueprintFieldTarget.value=JSON.stringify(this.blueprintValue))}}v.targets=["blueprintField"],v.values={id:Number,stableId:String,filterName:String,formId:String,blueprint:Array};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 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 w=[[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"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:a(e[1]),controllerConstructor:t}});e.AddController=d,e.DateController=I,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=w});
!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:{filter:e.state.filterName,blueprint:JSON.stringify(e.state.blueprint),form_id:e.state.formIdValue}});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({filter:e.stateController.filterName,blueprint:JSON.stringify(t),form_id:e.stateController.formIdValue})});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({filter:e.stateController.filterName,blueprint:JSON.stringify(t),form_id:e.stateController.formIdValue})});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,formId:String,refreshUrl:String},g.targets=["loading"];class v extends t.Controller{connect(){const e=document.getElementById("query_hammerstone_refine_filter_forms_form_"+this.formIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprintValue),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};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});
//# sourceMappingURL=refine-stimulus.umd.js.map

@@ -39,2 +39,11 @@ import { Controller } from "@hotwired/stimulus"

}
loadResults({detail: {url}}) {
console.log("filter submit success")
if (window.Turbo) {
window.Turbo.visit(url)
} else {
window.location.href = url
}
}
}

@@ -6,8 +6,10 @@ import { Controller } from "@hotwired/stimulus"

static targets = ['blueprintField']
static values = { id: Number, stableId: String, filterName: String, formId: String, blueprint: Array }
static values = { formId: String }
connect() {
if (this.idValue) {
filterStoredEvent(this.idValue)
}
const stateController = document
.getElementById(`query_hammerstone_refine_filter_forms_form_${this.formIdValue}`)
.refineStateController
this.blueprintFieldTarget.value = JSON.stringify(stateController.blueprintValue)
console.log("connect", this.blueprintFieldTarget.value)
}

@@ -19,11 +21,5 @@

const { blueprint } = detail
this.blueprintValue = blueprint
this.setBlueprintFieldFromValue(null)
this.blueprintFieldTarget.value = JSON.stringify(blueprint)
console.log("update blueprint", this.blueprintFieldTarget.value)
}
setBlueprintFieldFromValue(_event) {
if (this.hasBlueprintFieldTarget) {
this.blueprintFieldTarget.value = JSON.stringify(this.blueprintValue)
}
}
}

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

### 2.3.12 2023-01-13
* Cleanup
* Separate stored filter back end (PR #83)
* Dispatch events on filter update (PR #82)
### 2.3.11 2022-12-6

@@ -2,0 +7,0 @@ * Possible breaking change

{
"name": "@hammerstone/refine-stimulus",
"version":"2.3.11",
"version":"2.3.12",
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.",

@@ -5,0 +5,0 @@ "browserslist": [

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

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