@hammerstone/refine-stimulus
Advanced tools
Comparing version 2.4.3-0.1 to 2.5.0
@@ -1,2 +0,2 @@ | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as r,abnegate as i}from"jquery-events-to-dom-events";import{isEqual as n,debounce as o}from"lodash";import s from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}u.values={criterionId:Number,input:Object};class c extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}c.values={criterionId:Number};class h extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}h.values={submitUrl:String};class p extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}p.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const m=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},f=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=o;let d={clause:null==(i=l[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return s.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class b extends e{connect(){this.element.refineStateController=this,this.changeDelegate=r("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(f(t.id,1,t)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},f(i.id,1,i)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,s=n||!r,l=s&&o;r||i?t.splice(l&&n?e-1:l&&!r||s&&!o?e:e-1,2):this.blueprint=[],m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));const o=this.blueprint[e],s=f(t,i.depth,r);return!n(o,s)&&(this.blueprint[e]=s,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}b.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},b.targets=["loading"];class g extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}g.targets=["blueprintField"],g.values={formId:String,stateDomId:String};class v extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}v.targets=["content"];class C extends a{initialize(){this.updateBlueprint=o((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}C.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I extends e{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=s(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}I.targets=["field","hiddenField"];const w=[[d,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[h,"refine/filter-pills-controller.js"],[p,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[b,"refine/state-controller.js"],[g,"refine/stored-filter-controller.js"],[v,"refine/toggle-controller.js"],[C,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,I as DateController,u as DefaultsController,c as DeleteController,h as FilterPillsController,p as SearchFilterController,a as ServerRefreshController,b as StateController,g as StoredFilterController,v as ToggleController,C as UpdateController,w as controllerDefinitions}; | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as r,abnegate as i}from"jquery-events-to-dom-events";import{isEqual as n,debounce as o}from"lodash";import s from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{refresh(e){const t=new FormData(this.element),r=new URL(this.urlValue);for(const[e,i]of t.entries())console.log(e,i),r.searchParams.set(e,i);window.Turbo.visit(r.toString(),{frame:this.turboFrameValue})}}u.values={url:String,turboFrame:String};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 h extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}h.values={criterionId:Number};class m extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=`${window.location.pathname}?${r}`;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}m.values={submitUrl:String};class p extends e{show(e){this.frameTarget.src=this.srcValue}hide(e){this.frameTarget.innerHTML=""}}p.targets=["frame"],p.values={src:String};class f extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}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 g=(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:{}},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 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,g(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(b(t.id,1,t)),g(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)),g(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=[],g(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(b)}`);const o=this.blueprint[e],s=b(t,i.depth,r);return!n(o,s)&&(this.blueprint[e]=s,g(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},g(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}v.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},v.targets=["loading"];class w extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}w.targets=["blueprintField"],w.values={formId:String,stateDomId:String};class C extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}C.targets=["content"];class I 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())}}I.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class S 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()}}S.targets=["field","hiddenField"];const y=[[d,"refine/add-controller.js"],[u,"refine/condition-form-controller.js"],[c,"refine/defaults-controller.js"],[h,"refine/delete-controller.js"],[m,"refine/filter-pills-controller.js"],[p,"refine/popup-controller.js"],[f,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[v,"refine/state-controller.js"],[w,"refine/stored-filter-controller.js"],[C,"refine/toggle-controller.js"],[I,"refine/update-controller.js"],[S,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,u as ConditionFormController,S as DateController,c as DefaultsController,h as DeleteController,m as FilterPillsController,p as PopupController,f as SearchFilterController,a as ServerRefreshController,v as StateController,w as StoredFilterController,C as ToggleController,I as UpdateController,y as controllerDefinitions}; | ||
//# sourceMappingURL=refine-stimulus.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("jquery-events-to-dom-events"),i=require("lodash");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(require("flatpickr"));function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class s extends e.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class a extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}a.values={previousCriterionId:Number};class d extends e.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}d.values={criterionId:Number,input:Object};class u extends s{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}u.values={criterionId:Number};class c extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}c.values={submitUrl:String};class h extends e.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}h.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const p=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},m=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let d={clause:null==(i=s[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class f extends e.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=r.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){r.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(m(t.id,1,t)),p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},m(i.id,1,i)),p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const n=this.blueprint[e];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(m));const o=this.blueprint[e],l=m(t,n.depth,r);return!i.isEqual(o,l)&&(this.blueprint[e]=l,p(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},p(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}f.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},f.targets=["loading"];class b extends e.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}b.targets=["blueprintField"],b.values={formId:String,stateDomId:String};class g extends e.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}g.targets=["content"];class v extends s{initialize(){this.updateBlueprint=i.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}v.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class C extends e.Controller{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=o.default(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}C.targets=["field","hiddenField"];const I=[[a,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[u,"refine/delete-controller.js"],[c,"refine/filter-pills-controller.js"],[h,"refine/search-filter-controller.js"],[s,"refine/server-refresh-controller.js"],[f,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[g,"refine/toggle-controller.js"],[v,"refine/update-controller.js"],[C,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});exports.AddController=a,exports.DateController=C,exports.DefaultsController=d,exports.DeleteController=u,exports.FilterPillsController=c,exports.SearchFilterController=h,exports.ServerRefreshController=s,exports.StateController=f,exports.StoredFilterController=b,exports.ToggleController=g,exports.UpdateController=v,exports.controllerDefinitions=I; | ||
var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("jquery-events-to-dom-events"),i=require("lodash");function n(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var o=n(require("flatpickr"));function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class s extends e.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}refreshFromServer(){try{const e=this;e.state.startUpdate();const r=new t.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class a extends s{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}a.values={previousCriterionId:Number};class u extends e.Controller{refresh(e){const t=new FormData(this.element),r=new URL(this.urlValue);for(const[e,i]of t.entries())console.log(e,i),r.searchParams.set(e,i);window.Turbo.visit(r.toString(),{frame:this.turboFrameValue})}}u.values={url:String,turboFrame:String};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 s{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}c.values={criterionId:Number};class h extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=`${window.location.pathname}?${r}`;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}h.values={submitUrl:String};class p extends e.Controller{show(e){this.frameTarget.src=this.srcValue}hide(e){this.frameTarget.innerHTML=""}}p.targets=["frame"],p.values={src:String};class m extends e.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}m.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const f=(e,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)},g=(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 b 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,f(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(g(t.id,1,t)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},g(i.id,1,i)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],f(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(g)}`);const o=this.blueprint[e],l=g(t,n.depth,r);return!i.isEqual(o,l)&&(this.blueprint[e]=l,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}b.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},b.targets=["loading"];class v extends e.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class C extends e.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}C.targets=["content"];class w 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())}}w.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I 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()}}I.targets=["field","hiddenField"];const S=[[a,"refine/add-controller.js"],[u,"refine/condition-form-controller.js"],[d,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[h,"refine/filter-pills-controller.js"],[p,"refine/popup-controller.js"],[m,"refine/search-filter-controller.js"],[s,"refine/server-refresh-controller.js"],[b,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[C,"refine/toggle-controller.js"],[w,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});exports.AddController=a,exports.ConditionFormController=u,exports.DateController=I,exports.DefaultsController=d,exports.DeleteController=c,exports.FilterPillsController=h,exports.PopupController=p,exports.SearchFilterController=m,exports.ServerRefreshController=s,exports.StateController=b,exports.StoredFilterController=v,exports.ToggleController=C,exports.UpdateController=w,exports.controllerDefinitions=S; | ||
//# sourceMappingURL=refine-stimulus.js.map |
@@ -1,2 +0,2 @@ | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{delegate as i,abnegate as r}from"jquery-events-to-dom-events";import{isEqual as n,debounce as s}from"lodash";import o from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}async refreshFromServer(){this.state.startUpdate();const e=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":this.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"hammerstone_refine_filters_builder[client_id]":this.state.clientIdValue}});await e.perform()}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}u.values={criterionId:Number,input:Object};class c extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}function h(){return h=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e},h.apply(this,arguments)}c.values={criterionId:Number};class p extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var i=parseInt(t);this.stateController.deleteCriterion(i),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams(h({},Object.fromEntries(this.existingParams),Object.fromEntries(t))).toString(),r=`${window.location.pathname}?${i}`;history.pushState({},document.title,r),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class m extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults({detail:{url:e}}){console.log("filter submit success"),window.Turbo?window.Turbo.visit(e):window.location.href=e}}m.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}e.prototype=window.Event.prototype,window.CustomEvent=e}();const f=(e,{blueprint:t,formId:i})=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:i}});e.dispatchEvent(r)},b=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},o=(null==i?void 0:i.refinements)||[],{clauses:l,options:a}=s;let d={clause:null==(r=l[0])?void 0:r.id,selected:"option-condition"===n?[a[0].id]:void 0};return o.forEach(e=>{var t;const{meta:i,component:r}=e,{clauses:n,options:s}=i;d[e.id]={clause:n[0].id,selected:"option-condition"===r?[null==(t=s[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class g extends e{connect(){this.element.refineStateController=this,this.changeDelegate=i("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){r("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(b(t.id,1,t)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:i}=this,r=i[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},b(r.id,1,r)),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],r=t[e+1],n=i&&"or"===i.word,s=r&&"or"===r.word||!r,o=n||!i,l=o&&s;i||r?t.splice(l&&n?e-1:l&&!i||o&&!s?e:e-1,2):this.blueprint=[],f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,i){const r=this.blueprint[e];if("criterion"!==r.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(b)}`);const s=this.blueprint[e],o=b(t,r.depth,i);return!n(s,o)&&(this.blueprint[e]=o,f(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,i){const{blueprint:r}=this,n=r[e],s=(i=i||"input").split(", ");s.length>1?n[s[0]][s[1]]=h({},n[s[0]][s[1]],t):n[i]=h({},n[i],t),f(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},g.targets=["loading"];class v extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:i}=t;this.blueprintFieldTarget.value=JSON.stringify(i),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class w extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}w.targets=["content"];class C extends a{initialize(){this.updateBlueprint=s((e,t,i)=>{this.value(e,t,i)},500)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,i=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,i,"selected")}value(e,t,i){const{criterionIdValue:r,state:n}=this,s=e.target.dataset;n.updateInput(r,{[i=i||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:i}=this,r=e.target;let n=r.value;n||(n=r.querySelector("select").value);const s=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}C.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I extends e{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=o(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,i)=>{this.fieldTarget.value=i.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=i.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}I.targets=["field","hiddenField"];const S=[[d,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[m,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[w,"refine/toggle-controller.js"],[C,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,I as DateController,u as DefaultsController,c as DeleteController,p as FilterPillsController,m as SearchFilterController,a as ServerRefreshController,g as StateController,v as StoredFilterController,w as ToggleController,C as UpdateController,S as controllerDefinitions}; | ||
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 o from"flatpickr";function l(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class a extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}async refreshFromServer(){this.state.startUpdate();const e=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":this.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"hammerstone_refine_filters_builder[client_id]":this.state.clientIdValue}});await e.perform()}}class d extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class u extends e{refresh(e){const t=new FormData(this.element),r=new URL(this.urlValue);for(const[e,i]of t.entries())console.log(e,i),r.searchParams.set(e,i);window.Turbo.visit(r.toString(),{frame:this.turboFrameValue})}}u.values={url:String,turboFrame:String};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 h extends a{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}function p(){return p=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var i in r)Object.prototype.hasOwnProperty.call(r,i)&&(e[i]=r[i])}return e},p.apply(this,arguments)}h.values={criterionId:Number};class m extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,r=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await r.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams(p({},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}}m.values={submitUrl:String};class f extends e{show(e){this.frameTarget.src=this.srcValue}hide(e){this.frameTarget.innerHTML=""}}f.targets=["frame"],f.values={src:String};class g extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,r=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await r.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults({detail:{url:e}}){console.log("filter submit success"),window.Turbo?window.Turbo.visit(e):window.location.href=e}}g.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 b=(e,{blueprint:t,formId:r})=>{const i=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:r}});e.dispatchEvent(i)},v=(e,t,r)=>{var i;const n=null==r?void 0:r.component,s=(null==r?void 0:r.meta)||{clauses:[],options:{}},o=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=s;let d={clause:null==(i=l[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return o.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 w 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,{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(v(t.id,1,t)),b(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"},v(i.id,1,i)),b(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,s=i&&"or"===i.word||!i,o=n||!r,l=o&&s;r||i?t.splice(l&&n?e-1:l&&!r||o&&!s?e:e-1,2):this.blueprint=[],b(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(v)}`);const s=this.blueprint[e],o=v(t,i.depth,r);return!n(s,o)&&(this.blueprint[e]=o,b(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!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]]=p({},n[s[0]][s[1]],t):n[r]=p({},n[r],t),b(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}w.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},w.targets=["loading"];class C extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}C.targets=["blueprintField"],C.values={formId:String,stateDomId:String};class I extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}I.targets=["content"];class S extends a{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 y 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,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()}}y.targets=["field","hiddenField"];const T=[[d,"refine/add-controller.js"],[u,"refine/condition-form-controller.js"],[c,"refine/defaults-controller.js"],[h,"refine/delete-controller.js"],[m,"refine/filter-pills-controller.js"],[f,"refine/popup-controller.js"],[g,"refine/search-filter-controller.js"],[a,"refine/server-refresh-controller.js"],[w,"refine/state-controller.js"],[C,"refine/stored-filter-controller.js"],[I,"refine/toggle-controller.js"],[S,"refine/update-controller.js"],[y,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:l(e[1]),controllerConstructor:t}});export{d as AddController,u as ConditionFormController,y as DateController,c as DefaultsController,h as DeleteController,m as FilterPillsController,f as PopupController,g as SearchFilterController,a as ServerRefreshController,w as StateController,C as StoredFilterController,I as ToggleController,S as UpdateController,T as controllerDefinitions}; | ||
//# sourceMappingURL=refine-stimulus.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("@rails/request.js"),require("jquery-events-to-dom-events"),require("lodash"),require("flatpickr")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","@rails/request.js","jquery-events-to-dom-events","lodash","flatpickr"],t):t((e||self).refineStimulus={},e.Stimulus,e.request_js,e.jqueryEventsToDomEvents,e.lodash,e.flatpickr)}(this,function(e,t,r,i,n,o){function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=l(o);function a(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class d extends t.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}refreshFromServer(){try{const e=this;e.state.startUpdate();const t=new r.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(t.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class u extends d{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}u.values={previousCriterionId:Number};class c extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}c.values={criterionId:Number,input:Object};class h extends d{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}h.values={criterionId:Number};class p extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class f extends t.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}f.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const m=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},b=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let d={clause:null==(i=s[0])?void 0:i.id,selected:"option-condition"===n?[a[0].id]:void 0};return l.forEach(e=>{var t;const{meta:r,component:i}=e,{clauses:n,options:o}=r;d[e.id]={clause:n[0].id,selected:"option-condition"===i?[null==(t=o[0])?void 0:t.id]:void 0}}),{depth:t,type:"criterion",condition_id:e,input:d}};class g extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(b(t.id,1,t)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},b(i.id,1,i)),m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(b));const o=this.blueprint[e],l=b(t,i.depth,r);return!n.isEqual(o,l)&&(this.blueprint[e]=l,m(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},m(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}g.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},g.targets=["loading"];class v extends t.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}v.targets=["blueprintField"],v.values={formId:String,stateDomId:String};class C extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}C.targets=["content"];class w extends d{initialize(){this.updateBlueprint=n.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset;n.updateInput(i,{[r=r||o.inputKey||"value"]:t=t||e.target.value},o.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}w.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class I extends t.Controller{connect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.connect.bind(this)():this.defaultConnect()}disconnect(){var e;null!=(e=window.HammerstoneRefine)&&e.datePicker?window.HammerstoneRefine.datePicker.disconnect.bind(this)():this.defaultDisconnect()}defaultConnect(){this.plugin=s.default(this.fieldTarget,{minDate:this.futureOnlyValue?new Date:null,dateFormat:"m/d/Y",onChange:(e,t,r)=>{this.fieldTarget.value=r.formatDate(e[0],this.includeTimeValue?"m/d/Y h:i K":"m/d/Y"),this.hiddenFieldTarget.value=r.formatDate(e[0],"Y-m-d"),this.hiddenFieldTarget.dispatchEvent(new Event("change",{bubbles:!0}))}})}defaultDisconnect(){this.plugin.destroy()}}I.targets=["field","hiddenField"];const y=[[u,"refine/add-controller.js"],[c,"refine/defaults-controller.js"],[h,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[f,"refine/search-filter-controller.js"],[d,"refine/server-refresh-controller.js"],[g,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[C,"refine/toggle-controller.js"],[w,"refine/update-controller.js"],[I,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:a(e[1]),controllerConstructor:t}});e.AddController=u,e.DateController=I,e.DefaultsController=c,e.DeleteController=h,e.FilterPillsController=p,e.SearchFilterController=f,e.ServerRefreshController=d,e.StateController=g,e.StoredFilterController=v,e.ToggleController=C,e.UpdateController=w,e.controllerDefinitions=y}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("@rails/request.js"),require("jquery-events-to-dom-events"),require("lodash"),require("flatpickr")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","@rails/request.js","jquery-events-to-dom-events","lodash","flatpickr"],t):t((e||self).refineStimulus={},e.Stimulus,e.request_js,e.jqueryEventsToDomEvents,e.lodash,e.flatpickr)}(this,function(e,t,r,i,n,o){function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var s=l(o);function a(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u extends t.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}refreshFromServer(){try{const e=this;e.state.startUpdate();const t=new r.FetchRequest("GET",e.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"hammerstone_refine_filters_builder[filter_class]":e.state.filterName,"hammerstone_refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"hammerstone_refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(t.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class d extends u{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer()}group(){this.state.addGroup(),this.refreshFromServer()}}d.values={previousCriterionId:Number};class c extends t.Controller{refresh(e){const t=new FormData(this.element),r=new URL(this.urlValue);for(const[e,i]of t.entries())console.log(e,i),r.searchParams.set(e,i);window.Turbo.visit(r.toString(),{frame:this.turboFrameValue})}}c.values={url:String,turboFrame:String};class h 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}}h.values={criterionId:Number,input:Object};class f extends u{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}f.values={criterionId:Number};class p extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=`${window.location.pathname}?${r}`;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}p.values={submitUrl:String};class m extends t.Controller{show(e){this.frameTarget.src=this.srcValue}hide(e){this.frameTarget.innerHTML=""}}m.targets=["frame"],m.values={src:String};class g extends t.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({hammerstone_refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}g.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 b=(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)},v=(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 C 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,{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(v(t.id,1,t)),b(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"},v(i.id,1,i)),b(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=[],b(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(v)}`);const o=this.blueprint[e],l=v(t,i.depth,r);return!n.isEqual(o,l)&&(this.blueprint[e]=l,b(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},b(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}C.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String},C.targets=["loading"];class w extends t.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}w.targets=["blueprintField"],w.values={formId:String,stateDomId:String};class I extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}I.targets=["content"];class S 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())}}S.values={criterionId:Number},require("flatpickr/dist/flatpickr.css");class y 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()}}y.targets=["field","hiddenField"];const T=[[d,"refine/add-controller.js"],[c,"refine/condition-form-controller.js"],[h,"refine/defaults-controller.js"],[f,"refine/delete-controller.js"],[p,"refine/filter-pills-controller.js"],[m,"refine/popup-controller.js"],[g,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[C,"refine/state-controller.js"],[w,"refine/stored-filter-controller.js"],[I,"refine/toggle-controller.js"],[S,"refine/update-controller.js"],[y,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:a(e[1]),controllerConstructor:t}});e.AddController=d,e.ConditionFormController=c,e.DateController=y,e.DefaultsController=h,e.DeleteController=f,e.FilterPillsController=p,e.PopupController=m,e.SearchFilterController=g,e.ServerRefreshController=u,e.StateController=C,e.StoredFilterController=w,e.ToggleController=I,e.UpdateController=S,e.controllerDefinitions=T}); | ||
//# sourceMappingURL=refine-stimulus.umd.js.map |
import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers" | ||
import AddController from './refine/add-controller' | ||
import ConditionFormController from './refine/condition-form-controller' | ||
import DefaultsController from './refine/defaults-controller' | ||
import DeleteController from './refine/delete-controller' | ||
import FilterPillsController from './refine/filter-pills-controller' | ||
import PopupController from './refine/popup-controller' | ||
import SearchFilterController from './refine/search-filter-controller' | ||
@@ -17,5 +19,7 @@ import ServerRefreshController from './refine/server-refresh-controller' | ||
[AddController, 'refine/add-controller.js'], | ||
[ConditionFormController, 'refine/condition-form-controller.js'], | ||
[DefaultsController, 'refine/defaults-controller.js'], | ||
[DeleteController, 'refine/delete-controller.js'], | ||
[FilterPillsController, 'refine/filter-pills-controller.js'], | ||
[PopupController, 'refine/popup-controller.js'], | ||
[SearchFilterController, 'refine/search-filter-controller.js'], | ||
@@ -39,5 +43,7 @@ [ServerRefreshController, 'refine/server-refresh-controller.js'], | ||
AddController, | ||
ConditionFormController, | ||
DefaultsController, | ||
DeleteController, | ||
FilterPillsController, | ||
PopupController, | ||
SearchFilterController, | ||
@@ -44,0 +50,0 @@ ServerRefreshController, |
@@ -1,3 +0,8 @@ | ||
### 2.4.3 (not yet released) | ||
### 2.5.0 | ||
* V2 "filter pill" UI and architecture. Not a breaking change, existing filters still work. This introduces an entire new concept of an inline filter. | ||
### 2.4.4 | ||
* features | ||
* Hotfix to allow end user to create custom condition with a left joins | ||
### 2.4.3 | ||
* features | ||
* added generator for creating filters | ||
@@ -4,0 +9,0 @@ * bugfix |
{ | ||
"name": "@hammerstone/refine-stimulus", | ||
"version":"2.4.3", | ||
"version": "2.5.0", | ||
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.", | ||
@@ -5,0 +5,0 @@ "browserslist": [ |
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
280610
30
2394
2
0