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.10 to 2.3.11

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 s}from"lodash";import l from"flatpickr";function a(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class o 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 o{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class c 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}}c.values={criterionId:Number,input:Object};class u extends o{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}u.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:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(t){t.stableId&&e.redirectToStableId(t.stableId)})}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}}class m extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(r){r.stableId?e.redirectToStableId(r.stableId):e.fetchAndRenderInvalidFilter(t)})}catch(e){return Promise.reject(e)}}addHiddenInput(e){let{name:t,value:r}=e;const i=document.createElement("input");i.type="hidden",i.name=t,i.value=r,this.submissionFormTarget.appendChild(i)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}fetchAndRenderInvalidFilter(e){try{const r=this,i=new t("POST",r.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({filter:r.stateController.filterName,blueprint:JSON.stringify(e),form_id:r.stateController.formIdValue})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}m.values={submitUrl:String},m.targets=[],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,r)=>{const i=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:t,filterName:r}});e.dispatchEvent(i)},b=(e,t)=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});e.dispatchEvent(r)},f=(e,t,r)=>{var i;const n=null==r?void 0:r.component,s=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:a,options:o}=s;let d={clause:null==(i=a[0])?void 0:i.id,selected:"option-condition"===n?[o[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:s}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=s[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class v 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,b(this.element,this.blueprint)}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)),b(this.element,this.blueprint)}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)),b(this.element,this.blueprint)}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,s=i&&"or"===i.word||!i,l=n||!r,a=l&&s;r||i?t.splice(a&&n?e-1:a&&!r||l&&!s?e:e-1,2):this.blueprint=[],b(this.element,this.blueprint)}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 s=this.blueprint[e],l=f(t,i.depth,r);return!n(s,l)&&(this.blueprint[e]=l,b(this.element,this.blueprint),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],s=(r=r||"input").split(", ");s.length>1?n[s[0]][s[1]]={...n[s[0]][s[1]],...t}:n[r]={...n[r],...t},b(this.element,this.blueprint)}}v.values={blueprint:Array,conditions:Array,className:String,formId:String,refreshUrl:String},v.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)})()}updateStableIdField(e){if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:t}=e,{stableId:r}=t;this.stableIdFieldTarget.value=r}}activateSaveLink(e){const{detail:t}=e,{stableId:r}=t;if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget){const e=new URL(this.enabledSaveLinkTarget.href);e.searchParams.set("stable_id",r),this.enabledSaveLinkTarget.setAttribute("href",e),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}g.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],g.values={id:Number,stableId:String,filterName:String};class w extends e{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(e){try{const t=this;(e=>{const t=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});window.dispatchEvent(t)})(t.blueprint);const r=e.detail.blueprint;return Promise.resolve(t.validateBlueprint(r)).then(function(e){if(e.stableId)t.stableIdValue=e.stableId,p(t.element,t.stableIdValue,t.filterNameValue),p(window,t.stableIdValue,t.filterNameValue);else{const{errors:t}=e;(e=>{let{blueprint:t,errors:r}=e;const i=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:r}});window.dispatchEvent(i)})({blueprint:r,errors:t})}})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{var t;const r=this,{stateController:i}=r;let n=JSON.stringify({blueprint:e,filter:r.filterNameValue,form_id:i.formIdValue}),s=null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content;return Promise.resolve(fetch(r.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s}})).then(function(e){return Promise.resolve(e.json()).then(function(t){return e.ok?{stableId:t.filter_id}:{errors:t.errors}})})}catch(e){return Promise.reject(e)}}get stateController(){return this.stateControllerDomIdValue?document.getElementById(this.stateControllerDomIdValue):this.element.querySelector("[data-controller~=refine--state]")}}w.values={stableId:String,updateStableIdUrl:String,filterName:String,stateControllerDomId:String},w.targets=[];class S extends o{initialize(){this.updateBlueprint=s((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,s=e.target.dataset;n.updateInput(i,{[r=r||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const s=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}S.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=l(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 C=[[d,"refine/add-controller.js"],[c,"refine/defaults-controller.js"],[u,"refine/delete-controller.js"],[h,"refine/filter-pills-controller.js"],[m,"refine/search-filter-controller.js"],[o,"refine/server-refresh-controller.js"],[v,"refine/state-controller.js"],[g,"refine/stored-filter-controller.js"],[w,"refine/stabilize-filter-controller.js"],[S,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:a(e[1]),controllerConstructor:t}});export{d as AddController,I as DateController,c as DefaultsController,u as DeleteController,h as FilterPillsController,m as SearchFilterController,o as ServerRefreshController,w as StabilizeFilterController,v as StateController,g as StoredFilterController,S as UpdateController,C 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}}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};
//# 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 l=n(require("flatpickr"));function s(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class o 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 o{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 c extends o{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}c.values={criterionId:Number};class u 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:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(t){t.stableId&&e.redirectToStableId(t.stableId)})}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}}class h extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(r){r.stableId?e.redirectToStableId(r.stableId):e.fetchAndRenderInvalidFilter(t)})}catch(e){return Promise.reject(e)}}addHiddenInput(e){let{name:t,value:r}=e;const i=document.createElement("input");i.type="hidden",i.name=t,i.value=r,this.submissionFormTarget.appendChild(i)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}fetchAndRenderInvalidFilter(e){try{const r=this,i=new t.FetchRequest("POST",r.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({filter:r.stateController.filterName,blueprint:JSON.stringify(e),form_id:r.stateController.formIdValue})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}h.values={submitUrl:String},h.targets=[],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,r)=>{const i=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:t,filterName:r}});e.dispatchEvent(i)},m=(e,t)=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});e.dispatchEvent(r)},b=(e,t,r)=>{var i;const n=null==r?void 0:r.component,l=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:o,options:a}=l;let d={clause:null==(i=o[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:l}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=l[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,m(this.element,this.blueprint)}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(b(t.id,1,t)),m(this.element,this.blueprint)}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,this.blueprint)}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,l=i&&"or"===i.word||!i,s=n||!r,o=s&&l;r||i?t.splice(o&&n?e-1:o&&!r||s&&!l?e:e-1,2):this.blueprint=[],m(this.element,this.blueprint)}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(b));const l=this.blueprint[e],s=b(t,n.depth,r);return!i.isEqual(l,s)&&(this.blueprint[e]=s,m(this.element,this.blueprint),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],l=(r=r||"input").split(", ");l.length>1?n[l[0]][l[1]]={...n[l[0]][l[1]],...t}:n[r]={...n[r],...t},m(this.element,this.blueprint)}}f.values={blueprint:Array,conditions:Array,className:String,formId:String,refreshUrl:String},f.targets=["loading"];class v extends e.Controller{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateStableIdField(e){if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:t}=e,{stableId:r}=t;this.stableIdFieldTarget.value=r}}activateSaveLink(e){const{detail:t}=e,{stableId:r}=t;if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget){const e=new URL(this.enabledSaveLinkTarget.href);e.searchParams.set("stable_id",r),this.enabledSaveLinkTarget.setAttribute("href",e),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}v.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],v.values={id:Number,stableId:String,filterName:String};class g extends e.Controller{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(e){try{const t=this;(e=>{const t=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});window.dispatchEvent(t)})(t.blueprint);const r=e.detail.blueprint;return Promise.resolve(t.validateBlueprint(r)).then(function(e){if(e.stableId)t.stableIdValue=e.stableId,p(t.element,t.stableIdValue,t.filterNameValue),p(window,t.stableIdValue,t.filterNameValue);else{const{errors:t}=e;(e=>{let{blueprint:t,errors:r}=e;const i=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:r}});window.dispatchEvent(i)})({blueprint:r,errors:t})}})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{var t;const r=this,{stateController:i}=r;let n=JSON.stringify({blueprint:e,filter:r.filterNameValue,form_id:i.formIdValue}),l=null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content;return Promise.resolve(fetch(r.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":l}})).then(function(e){return Promise.resolve(e.json()).then(function(t){return e.ok?{stableId:t.filter_id}:{errors:t.errors}})})}catch(e){return Promise.reject(e)}}get stateController(){return this.stateControllerDomIdValue?document.getElementById(this.stateControllerDomIdValue):this.element.querySelector("[data-controller~=refine--state]")}}g.values={stableId:String,updateStableIdUrl:String,filterName:String,stateControllerDomId:String},g.targets=[];class C extends o{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,l=e.target.dataset;n.updateInput(i,{[r=r||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const l=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,l)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}C.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class S 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=l.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()}}S.targets=["field","hiddenField"];const w=[[a,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[u,"refine/filter-pills-controller.js"],[h,"refine/search-filter-controller.js"],[o,"refine/server-refresh-controller.js"],[f,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[g,"refine/stabilize-filter-controller.js"],[C,"refine/update-controller.js"],[S,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:s(e[1]),controllerConstructor:t}});exports.AddController=a,exports.DateController=S,exports.DefaultsController=d,exports.DeleteController=c,exports.FilterPillsController=u,exports.SearchFilterController=h,exports.ServerRefreshController=o,exports.StabilizeFilterController=g,exports.StateController=f,exports.StoredFilterController=v,exports.UpdateController=C,exports.controllerDefinitions=w;
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;
//# 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 a from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class o 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 o{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class c 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}}c.values={criterionId:Number,input:Object};class u extends o{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)}u.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,t=await this.stabilizeFilterController.validateBlueprint(e);t.stableId&&this.redirectToStableId(t.stableId)}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}}class m extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,t=await this.stabilizeFilterController.validateBlueprint(e);t.stableId?this.redirectToStableId(t.stableId):this.fetchAndRenderInvalidFilter(e)}addHiddenInput({name:e,value:t}){const i=document.createElement("input");i.type="hidden",i.name=e,i.value=t,this.submissionFormTarget.appendChild(i)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams(h({},Object.fromEntries(this.existingParams),Object.fromEntries(t))).toString(),r=`${window.location.pathname}?${i}`;history.pushState({},document.title,r),window.location.reload()}async fetchAndRenderInvalidFilter(e){const 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()}}m.values={submitUrl:String},m.targets=[],function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}e.prototype=window.Event.prototype,window.CustomEvent=e}();const b=(e,t,i)=>{const r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:t,filterName:i}});e.dispatchEvent(r)},f=(e,t)=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});e.dispatchEvent(i)},v=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},a=(null==i?void 0:i.refinements)||[],{clauses:l,options:o}=s;let d={clause:null==(r=l[0])?void 0:r.id,selected:"option-condition"===n?[o[0].id]:void 0};return a.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,this.blueprint)}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(v(t.id,1,t)),f(this.element,this.blueprint)}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"},v(r.id,1,r)),f(this.element,this.blueprint)}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,a=n||!i,l=a&&s;i||r?t.splice(l&&n?e-1:l&&!i||a&&!s?e:e-1,2):this.blueprint=[],f(this.element,this.blueprint)}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(v)}`);const s=this.blueprint[e],a=v(t,r.depth,i);return!n(s,a)&&(this.blueprint[e]=a,f(this.element,this.blueprint),!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,this.blueprint)}}g.values={blueprint:Array,conditions:Array,className:String,formId:String,refreshUrl:String},g.targets=["loading"];class w extends e{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateStableIdField(e){if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:t}=e,{stableId:i}=t;this.stableIdFieldTarget.value=i}}activateSaveLink(e){const{detail:t}=e,{stableId:i}=t;if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget){const e=new URL(this.enabledSaveLinkTarget.href);e.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",e),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}w.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],w.values={id:Number,stableId:String,filterName:String};class S extends e{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}async updateStableId(e){(e=>{const t=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:this.blueprint}});window.dispatchEvent(t)})();const t=e.detail.blueprint,i=await this.validateBlueprint(t);if(i.stableId)this.stableIdValue=i.stableId,b(this.element,this.stableIdValue,this.filterNameValue),b(window,this.stableIdValue,this.filterNameValue);else{const{errors:e}=i;(({blueprint:e,errors:t})=>{const i=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:e,errors:t}});window.dispatchEvent(i)})({blueprint:t,errors:e})}}async validateBlueprint(e){var t;const{stateController:i}=this;let r=JSON.stringify({blueprint:e,filter:this.filterNameValue,form_id:i.formIdValue}),n=null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content;const s=await fetch(this.updateStableIdUrlValue,{method:"PUT",body:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":n}}),a=await s.json();return s.ok?{stableId:a.filter_id}:{errors:a.errors}}get stateController(){return this.stateControllerDomIdValue?document.getElementById(this.stateControllerDomIdValue):this.element.querySelector("[data-controller~=refine--state]")}}S.values={stableId:String,updateStableIdUrl:String,filterName:String,stateControllerDomId:String},S.targets=[];class I extends o{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())}}I.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=a(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 y=[[d,"refine/add-controller.js"],[c,"refine/defaults-controller.js"],[u,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[m,"refine/search-filter-controller.js"],[o,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[w,"refine/stored-filter-controller.js"],[S,"refine/stabilize-filter-controller.js"],[I,"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,c as DefaultsController,u as DeleteController,p as FilterPillsController,m as SearchFilterController,o as ServerRefreshController,S as StabilizeFilterController,g as StateController,w as StoredFilterController,I as UpdateController,y 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:{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};
//# 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,l){function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=s(l);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:{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 c extends d{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}c.values={previousCriterionId:Number};class u 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}}u.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 m 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;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(t){t.stableId&&e.redirectToStableId(t.stableId)})}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}}class p extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController;return Promise.resolve(e.stabilizeFilterController.validateBlueprint(t)).then(function(r){r.stableId?e.redirectToStableId(r.stableId):e.fetchAndRenderInvalidFilter(t)})}catch(e){return Promise.reject(e)}}addHiddenInput(e){let{name:t,value:r}=e;const i=document.createElement("input");i.type="hidden",i.name=t,i.value=r,this.submissionFormTarget.appendChild(i)}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}fetchAndRenderInvalidFilter(e){try{const t=this,i=new r.FetchRequest("POST",t.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({filter:t.stateController.filterName,blueprint:JSON.stringify(e),form_id:t.stateController.formIdValue})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}p.values={submitUrl:String},p.targets=[],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,t,r)=>{const i=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:t,filterName:r}});e.dispatchEvent(i)},b=(e,t)=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t}});e.dispatchEvent(r)},v=(e,t,r)=>{var i;const n=null==r?void 0:r.component,l=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:o,options:a}=l;let d={clause:null==(i=o[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:l}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=l[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,b(this.element,this.blueprint)}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(v(t.id,1,t)),b(this.element,this.blueprint)}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"},v(i.id,1,i)),b(this.element,this.blueprint)}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,l=i&&"or"===i.word||!i,s=n||!r,o=s&&l;r||i?t.splice(o&&n?e-1:o&&!r||s&&!l?e:e-1,2):this.blueprint=[],b(this.element,this.blueprint)}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(v));const l=this.blueprint[e],s=v(t,i.depth,r);return!n.isEqual(l,s)&&(this.blueprint[e]=s,b(this.element,this.blueprint),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],l=(r=r||"input").split(", ");l.length>1?n[l[0]][l[1]]={...n[l[0]][l[1]],...t}:n[r]={...n[r],...t},b(this.element,this.blueprint)}}g.values={blueprint:Array,conditions:Array,className:String,formId:String,refreshUrl:String},g.targets=["loading"];class C extends t.Controller{connect(){this.idValue&&(e=>{const t=new CustomEvent("filter-stored",{bubbles:!0,cancelable:!0,detail:{storedFilterId:this.idValue}});window.dispatchEvent(t)})()}updateStableIdField(e){if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasStableIdFieldTarget){const{detail:t}=e,{stableId:r}=t;this.stableIdFieldTarget.value=r}}activateSaveLink(e){const{detail:t}=e,{stableId:r}=t;if(e.detail.filterName!=this.filterNameValue)return null;if(this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget){const e=new URL(this.enabledSaveLinkTarget.href);e.searchParams.set("stable_id",r),this.enabledSaveLinkTarget.setAttribute("href",e),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}C.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],C.values={id:Number,stableId:String,filterName:String};class S extends t.Controller{connect(){this.element.stabilizeFilterController=this,this.stableIdValue=new URLSearchParams(window.location.search).get("stable_id")}updateStableId(e){try{const t=this;(e=>{const t=new CustomEvent("filter-unstable",{bubbles:!0,cancelable:!0,detail:{blueprint:e}});window.dispatchEvent(t)})(t.blueprint);const r=e.detail.blueprint;return Promise.resolve(t.validateBlueprint(r)).then(function(e){if(e.stableId)t.stableIdValue=e.stableId,f(t.element,t.stableIdValue,t.filterNameValue),f(window,t.stableIdValue,t.filterNameValue);else{const{errors:t}=e;(e=>{let{blueprint:t,errors:r}=e;const i=new CustomEvent("filter-invalid",{bubbles:!0,cancelable:!0,detail:{blueprint:t,errors:r}});window.dispatchEvent(i)})({blueprint:r,errors:t})}})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{var t;const r=this,{stateController:i}=r;let n=JSON.stringify({blueprint:e,filter:r.filterNameValue,form_id:i.formIdValue}),l=null==(t=document.querySelector("meta[name='csrf-token']"))?void 0:t.content;return Promise.resolve(fetch(r.updateStableIdUrlValue,{method:"PUT",body:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":l}})).then(function(e){return Promise.resolve(e.json()).then(function(t){return e.ok?{stableId:t.filter_id}:{errors:t.errors}})})}catch(e){return Promise.reject(e)}}get stateController(){return this.stateControllerDomIdValue?document.getElementById(this.stateControllerDomIdValue):this.element.querySelector("[data-controller~=refine--state]")}}S.values={stableId:String,updateStableIdUrl:String,filterName:String,stateControllerDomId:String},S.targets=[];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,l=e.target.dataset;n.updateInput(i,{[r=r||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const l=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,l)&&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=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()}}I.targets=["field","hiddenField"];const y=[[c,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[h,"refine/delete-controller.js"],[m,"refine/filter-pills-controller.js"],[p,"refine/search-filter-controller.js"],[d,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[C,"refine/stored-filter-controller.js"],[S,"refine/stabilize-filter-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=c,e.DateController=I,e.DefaultsController=u,e.DeleteController=h,e.FilterPillsController=m,e.SearchFilterController=p,e.ServerRefreshController=d,e.StabilizeFilterController=S,e.StateController=g,e.StoredFilterController=C,e.UpdateController=w,e.controllerDefinitions=y});
!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});
//# sourceMappingURL=refine-stimulus.umd.js.map

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

import StoredFilterController from './refine/stored-filter-controller'
import StabilizeFilterController from './refine/stabilize-filter-controller'
import UpdateController from './refine/update-controller'

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

[StoredFilterController, 'refine/stored-filter-controller.js'],
[StabilizeFilterController, 'refine/stabilize-filter-controller.js'],
[UpdateController, 'refine/update-controller.js'],

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

StoredFilterController,
StabilizeFilterController,
UpdateController,
DateController
}
import { Controller } from "@hotwired/stimulus"
import { FetchRequest } from '@rails/request.js'
export default class extends Controller {
static values = {
submitUrl: String
}

@@ -20,6 +24,15 @@ connect() {

const {blueprint} = this.stateController
const validationResult = await this.stabilizeFilterController.validateBlueprint(blueprint)
if (validationResult.stableId) {
this.redirectToStableId(validationResult.stableId)
}
const request = new FetchRequest(
"POST",
this.submitUrlValue,
{
responseKind: "turbo-stream",
body: JSON.stringify({
filter: this.stateController.filterName,
blueprint: JSON.stringify(blueprint),
form_id: this.stateController.formIdValue
})
}
)
await request.perform()
}

@@ -26,0 +39,0 @@

@@ -9,10 +9,3 @@ import { Controller } from "@hotwired/stimulus"

static targets = []
connect() {
const urlParams = new URLSearchParams(window.location.search)
this.existingParams = urlParams
this.existingParams.delete('stable_id')
}
search(event) {

@@ -26,47 +19,2 @@ event.preventDefault()

const {blueprint} = this.stateController
const validationResult = await this.stabilizeFilterController.validateBlueprint(blueprint)
if (validationResult.stableId) {
this.redirectToStableId(validationResult.stableId)
} else {
this.fetchAndRenderInvalidFilter(blueprint)
}
}
addHiddenInput({name, value}) {
const input = document.createElement("input")
input.type = "hidden"
input.name = name
input.value = value
this.submissionFormTarget.appendChild(input)
}
get stateController() {
return this
.element
.querySelector('[data-controller~="refine--state"]')
.refineStateController
}
get stabilizeFilterController() {
return this
.element
.stabilizeFilterController
}
redirectToStableId(stableId) {
const params = new URLSearchParams()
if (stableId) {
params.append('stable_id', stableId)
}
const allParams = new URLSearchParams({
...Object.fromEntries(this.existingParams),
...Object.fromEntries(params),
}).toString()
const url = `${window.location.pathname}?${allParams}`
history.pushState({}, document.title, url)
window.location.reload()
}
async fetchAndRenderInvalidFilter(blueprint) {
const request = new FetchRequest(

@@ -86,2 +34,9 @@ "POST",

}
get stateController() {
return this
.element
.querySelector('[data-controller~="refine--state"]')
.refineStateController
}
}

@@ -78,3 +78,3 @@ import { Controller } from "@hotwired/stimulus"

this.loadingTimeout = null
blueprintUpdatedEvent(this.element, this.blueprint)
blueprintUpdatedEvent(this.element, {blueprint: this.blueprint, formId: this.formIdValue})
}

@@ -117,3 +117,3 @@

this.blueprint.push(criterion(condition.id, 1, condition))
blueprintUpdatedEvent(this.element, this.blueprint)
blueprintUpdatedEvent(this.element, {blueprint: this.blueprint, formId: this.formIdValue})
}

@@ -126,3 +126,3 @@

blueprint.splice(previousCriterionId + 1, 0, and(), criterion(condition.id, 1, condition))
blueprintUpdatedEvent(this.element, this.blueprint)
blueprintUpdatedEvent(this.element, {blueprint: this.blueprint, formId: this.formIdValue})
}

@@ -172,3 +172,3 @@

blueprintUpdatedEvent(this.element, this.blueprint)
blueprintUpdatedEvent(this.element, {blueprint: this.blueprint, formId: this.formIdValue})
}

@@ -193,3 +193,3 @@

this.blueprint[criterionId] = newCriterion
blueprintUpdatedEvent(this.element, this.blueprint)
blueprintUpdatedEvent(this.element, {blueprint: this.blueprint, formId: this.formIdValue})
return true

@@ -211,4 +211,4 @@ }

}
blueprintUpdatedEvent(this.element, this.blueprint)
blueprintUpdatedEvent(this.element, {blueprint: this.blueprint, formId: this.formIdValue})
}
}

@@ -5,4 +5,4 @@ import { Controller } from "@hotwired/stimulus"

export default class extends Controller {
static targets = ['enabledSaveLink', 'disabledSaveLink', 'stableIdField']
static values = { id: Number, stableId: String, filterName: String }
static targets = ['blueprintField']
static values = { id: Number, stableId: String, filterName: String, formId: String, blueprint: Array }

@@ -15,24 +15,15 @@ connect() {

updateStableIdField(event) {
if (event.detail.filterName != this.filterNameValue) { return null }
if (this.hasStableIdFieldTarget) {
const { detail } = event
const { stableId } = detail
this.stableIdFieldTarget.value = stableId
}
updateBlueprintField(event) {
if (event.detail.formId != this.formIdValue) { return null }
const { detail } = event
const { blueprint } = detail
this.blueprintValue = blueprint
this.setBlueprintFieldFromValue(null)
}
activateSaveLink(event) {
const { detail } = event
const { stableId } = detail
if (event.detail.filterName != this.filterNameValue) { return null }
if (this.hasEnabledSaveLinkTarget && this.hasDisabledSaveLinkTarget) {
const saveUrl = new URL(this.enabledSaveLinkTarget.href)
saveUrl.searchParams.set('stable_id', stableId)
this.enabledSaveLinkTarget.setAttribute('href', saveUrl)
this.disabledSaveLinkTarget.classList.add('hidden')
this.enabledSaveLinkTarget.classList.remove('hidden')
setBlueprintFieldFromValue(_event) {
if (this.hasBlueprintFieldTarget) {
this.blueprintFieldTarget.value = JSON.stringify(this.blueprintValue)
}
}
}

@@ -67,3 +67,3 @@ // Polyfill for custom events in IE9-11

export const blueprintUpdatedEvent = (element, blueprint) => {
export const blueprintUpdatedEvent = (element, {blueprint, formId}) => {
const event = new CustomEvent('blueprint-updated', {

@@ -73,3 +73,4 @@ bubbles: true,

detail: {
blueprint
blueprint,
formId
},

@@ -76,0 +77,0 @@ })

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

### 2.3.11 2022-12-6
* Possible breaking change
* Remove the constant server refresh PR: #81
### 2.3.10 2022-11-22
* bugfix
* bugfix
* Properly export tailwind and non tailwind css files

@@ -4,0 +7,0 @@

{
"name": "@hammerstone/refine-stimulus",
"version": "2.3.9",
"version":"2.3.11",
"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