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 1.1.0 to 1.1.1

2

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

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

import{Controller as t}from"stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function r(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}function a(){return a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},a.apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},s(t,e)}var l=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()},i.getStateController=function(){for(var t=this.element;t!==document.body;){var e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null},i.addHiddenInput=function(t,e){var i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i},i.finishUpdate=function(){this.state.finishUpdate()},i.startUpdate=function(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()},i.submitForm=function(){this.startUpdate(),this.element.requestSubmit()},e}(t),u=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.criterion=function(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()},i.group=function(){this.state.addGroup(),this.startUpdate()},e}(l);u.values={previousCriterionId:Number};var d=function(t){function e(){return t.apply(this,arguments)||this}return o(e,t),e.prototype.connect=function(){var t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)},e}(t);d.values={criterionId:Number,input:Object};var c=function(t){function e(){return t.apply(this,arguments)||this}return o(e,t),e.prototype.criterion=function(){this.state.deleteCriterion(this.criterionIdValue),this.startUpdate()},e}(l);c.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();var p=function(t,e,i,n){var r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},h=function(t){var e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},f=function(t,e,i){var n=i.meta,r={clause:n.clauses[0].id,selected:"option-condition"===i.component?[n.options[0].id]:void 0};return i.refinements.forEach(function(t){var e=t.meta;r[t.id]={clause:e.clauses[0].id,selected:"option-condition"===t.component?[e.options[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:r}},v=function(t){function n(){return t.apply(this,arguments)||this}o(n,t);var r=n.prototype;return r.connect=function(){this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce(function(t,e){return t[e.id]=e,t},{}),this.loadingTimeout=null,p(this.element,this.stableId,this.filterName,!0),p(window,this.stableId,this.filterName,!0)},r.disconnect=function(){i("change",this.changeDelegate)},r.startUpdate=function(){var t=this;this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(function(){document.activeElement.blur(),t.loadingTarget.classList.remove("hidden")},1e3)},r.finishUpdate=function(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")},r.conditionConfigFor=function(t){return this.conditionsLookup[t]},r.updateStableId=function(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),p(this.element,this.stableId,this.filterName),p(window,this.stableId,this.filterName))},r.addGroup=function(){var t,e=this.conditions[0];this.blueprint.length>0&&this.blueprint.push({depth:t=void 0===t?0:t,type:"conjunction",word:"or"}),this.blueprint.push(f(e.id,1,e)),h(this.blueprint)},r.addCriterion=function(t){var e,i=this.conditions[0];this.blueprint.splice(t+1,0,{depth:e=void 0===e?1:e,type:"conjunction",word:"and"},f(i.id,1,i)),h(this.blueprint)},r.deleteCriterion=function(t){var e=this.blueprint,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,a=n&&"or"===n.word||!n,o=r||!i,s=o&&a;if(i||n?e.splice(s&&r?t-1:s&&!i||o&&!a?t:t-1,2):this.blueprint=[],0===this.blueprint.length){var l=this.conditions[0];this.blueprint.push(f(l.id,1,l))}h(this.blueprint)},r.replaceCriterion=function(t,e,i){var n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));this.blueprint[t]=f(e,n.depth,i),h(this.blueprint)},r.updateInput=function(t,e,i){var n=this.blueprint[t],r=(i=i||"input").split(", ");r.length>1?n[r[0]][r[1]]=a({},n[r[0]][r[1]],e):n[i]=a({},n[i],e),h(this.blueprint)},n}(t);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var b=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.connect=function(){var t;this.idValue&&(t=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}}),window.dispatchEvent(t))},i.updateStableIdField=function(t){this.hasStableIdFieldTarget&&(this.stableIdFieldTarget.value=t.detail.stableId)},i.activateSaveLink=function(t){var e=t.detail,i=e.stableId,n=e.initialLoad;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){var r=new URL(this.enabledSaveLinkTarget.href);r.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",r),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}},e}(t);b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String};var m=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.initialize=function(){var t=this;this.updateBlueprint=n(function(e,i,n){t.value(e,i,n),t.createStableId(t.state.blueprint,t.state.filterName)},500)},i.connect=function(){l.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)},i.refinedFilter=function(t){this.state.updateInput(this.criterionIdValue,{id:t.target.value},t.target.dataset.inputId),this.submitForm()},i.clause=function(t){this.state.updateInput(this.criterionIdValue,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()},i.selected=function(t){var e=Array.prototype.slice.call(t.target.options).filter(function(t){return t.selected}).map(function(t){return t.value});this.value(t,e,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)},i.value=function(t,e,i){var n,r=t.target.dataset,a=r.inputId;this.state.updateInput(this.criterionIdValue,((n={})[i=i||r.inputKey||"value"]=e=e||t.target.value,n),a)},i.date=function(t){var e=t.detail.picker.startDate.format("YYYY-MM-DD");this.value(t,e),this.submitForm()},i.createStableId=function(t,e){var i=this.state,n=JSON.stringify({blueprint:t,filter:e}),r=document.querySelector("meta[name='csrf-token']").content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r},success:function(t){i.updateStableId(t.filter_id)}})},i.condition=function(t){var e=this.criterionIdValue,i=this.state,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()},i.cancelEnter=function(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())},e}(l);m.values={criterionId:Number,stableId:String};var g=[[u,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[l,"refine/form-controller.js"],[v,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){var e=t[0];return{identifier:r(t[1]),controllerConstructor:e}});export{u as AddController,d as DefaultsController,c as DeleteController,l as FormController,v as StateController,b as StoredFilterController,m as UpdateController,g as controllerDefinitions};
import{Controller as t}from"stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function r(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}function a(){return a=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},a.apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},s(t,e)}var l=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()},i.getStateController=function(){for(var t=this.element;t!==document.body;){var e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null},i.addHiddenInput=function(t,e){var i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i},i.finishUpdate=function(){this.state.finishUpdate()},i.startUpdate=function(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()},i.submitForm=function(){this.startUpdate(),this.element.requestSubmit()},e}(t),u=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.criterion=function(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()},i.group=function(){this.state.addGroup(),this.startUpdate()},e}(l);u.values={previousCriterionId:Number};var d=function(t){function e(){return t.apply(this,arguments)||this}return o(e,t),e.prototype.connect=function(){var t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)},e}(t);d.values={criterionId:Number,input:Object};var c=function(t){function e(){return t.apply(this,arguments)||this}return o(e,t),e.prototype.criterion=function(){this.state.deleteCriterion(this.criterionIdValue),this.startUpdate()},e}(l);c.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();var p=function(t,e,i,n){var r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},h=function(t){var e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},f=function(t,e,i){var n=i.meta,r={clause:n.clauses[0].id,selected:"option-condition"===i.component?[n.options[0].id]:void 0};return i.refinements.forEach(function(t){var e=t.meta;r[t.id]={clause:e.clauses[0].id,selected:"option-condition"===t.component?[e.options[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:r}},v=function(t){function n(){return t.apply(this,arguments)||this}o(n,t);var r=n.prototype;return r.connect=function(){this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce(function(t,e){return t[e.id]=e,t},{}),this.loadingTimeout=null,p(this.element,this.stableId,this.filterName,!0),p(window,this.stableId,this.filterName,!0)},r.disconnect=function(){i("change",this.changeDelegate)},r.startUpdate=function(){var t=this;this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(function(){document.activeElement.blur(),t.loadingTarget.classList.remove("hidden")},1e3)},r.finishUpdate=function(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")},r.conditionConfigFor=function(t){return this.conditionsLookup[t]},r.updateStableId=function(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),p(this.element,this.stableId,this.filterName),p(window,this.stableId,this.filterName))},r.addGroup=function(){var t,e=this.conditions[0];this.blueprint.length>0&&this.blueprint.push({depth:t=void 0===t?0:t,type:"conjunction",word:"or"}),this.blueprint.push(f(e.id,1,e)),h(this.blueprint)},r.addCriterion=function(t){var e,i=this.conditions[0];this.blueprint.splice(t+1,0,{depth:e=void 0===e?1:e,type:"conjunction",word:"and"},f(i.id,1,i)),h(this.blueprint)},r.deleteCriterion=function(t){var e=this.blueprint,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,a=n&&"or"===n.word||!n,o=r||!i,s=o&&a;if(i||n?e.splice(s&&r?t-1:s&&!i||o&&!a?t:t-1,2):this.blueprint=[],0===this.blueprint.length){var l=this.conditions[0];this.blueprint.push(f(l.id,1,l))}h(this.blueprint)},r.replaceCriterion=function(t,e,i){var n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));this.blueprint[t]=f(e,n.depth,i),h(this.blueprint)},r.updateInput=function(t,e,i){var n=this.blueprint[t],r=(i=i||"input").split(", ");r.length>1?n[r[0]][r[1]]=a({},n[r[0]][r[1]],e):n[i]=a({},n[i],e),h(this.blueprint)},n}(t);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var b=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.connect=function(){var t;this.idValue&&(t=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}}),window.dispatchEvent(t))},i.updateStableIdField=function(t){this.hasStableIdFieldTarget&&(this.stableIdFieldTarget.value=t.detail.stableId)},i.activateSaveLink=function(t){var e=t.detail,i=e.stableId,n=e.initialLoad;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){var r=new URL(this.enabledSaveLinkTarget.href);r.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",r),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}},e}(t);b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String};var m=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.initialize=function(){var t=this;this.updateBlueprint=n(function(e,i,n){t.value(e,i,n),t.createStableId(t.state.blueprint,t.state.filterName)},500)},i.connect=function(){l.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)},i.refinedFilter=function(t){this.state.updateInput(this.criterionIdValue,{id:t.target.value},t.target.dataset.inputId),this.submitForm()},i.clause=function(t){this.state.updateInput(this.criterionIdValue,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()},i.selected=function(t){var e=Array.prototype.slice.call(t.target.options).filter(function(t){return t.selected}).map(function(t){return t.value});this.value(t,e,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)},i.value=function(t,e,i){var n,r=t.target.dataset,a=r.inputId;this.state.updateInput(this.criterionIdValue,((n={})[i=i||r.inputKey||"value"]=e=e||t.target.value,n),a)},i.date=function(t){var e=t.detail.picker.startDate.format("YYYY-MM-DD");this.value(t,e),this.submitForm()},i.createStableId=function(t,e){var i,n=this.state,r=JSON.stringify({blueprint:t,filter:e}),a=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":a},success:function(t){n.updateStableId(t.filter_id)}})},i.condition=function(t){var e=this.criterionIdValue,i=this.state,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()},i.cancelEnter=function(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())},e}(l);m.values={criterionId:Number,stableId:String};var g=[[u,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[l,"refine/form-controller.js"],[v,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){var e=t[0];return{identifier:r(t[1]),controllerConstructor:e}});export{u as AddController,d as DefaultsController,c as DeleteController,l as FormController,v as StateController,b as StoredFilterController,m as UpdateController,g as controllerDefinitions};
//# sourceMappingURL=refine-stimulus.esm.js.map

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

var t=require("stimulus"),e=require("jquery-events-to-dom-events"),i=require("lodash");function n(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}function r(){return r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},r.apply(this,arguments)}function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,o(t,e)}function o(t,e){return o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},o(t,e)}var s=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()},i.getStateController=function(){for(var t=this.element;t!==document.body;){var e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null},i.addHiddenInput=function(t,e){var i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i},i.finishUpdate=function(){this.state.finishUpdate()},i.startUpdate=function(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()},i.submitForm=function(){this.startUpdate(),this.element.requestSubmit()},e}(t.Controller),l=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.criterion=function(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()},i.group=function(){this.state.addGroup(),this.startUpdate()},e}(s);l.values={previousCriterionId:Number};var u=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e.prototype.connect=function(){var t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)},e}(t.Controller);u.values={criterionId:Number,input:Object};var d=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e.prototype.criterion=function(){this.state.deleteCriterion(this.criterionIdValue),this.startUpdate()},e}(s);d.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();var c=function(t,e,i,n){var r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},p=function(t){var e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},h=function(t,e,i){var n=i.meta,r={clause:n.clauses[0].id,selected:"option-condition"===i.component?[n.options[0].id]:void 0};return i.refinements.forEach(function(t){var e=t.meta;r[t.id]={clause:e.clauses[0].id,selected:"option-condition"===t.component?[e.options[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:r}},f=function(t){function i(){return t.apply(this,arguments)||this}a(i,t);var n=i.prototype;return n.connect=function(){this.changeDelegate=e.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce(function(t,e){return t[e.id]=e,t},{}),this.loadingTimeout=null,c(this.element,this.stableId,this.filterName,!0),c(window,this.stableId,this.filterName,!0)},n.disconnect=function(){e.abnegate("change",this.changeDelegate)},n.startUpdate=function(){var t=this;this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(function(){document.activeElement.blur(),t.loadingTarget.classList.remove("hidden")},1e3)},n.finishUpdate=function(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")},n.conditionConfigFor=function(t){return this.conditionsLookup[t]},n.updateStableId=function(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),c(this.element,this.stableId,this.filterName),c(window,this.stableId,this.filterName))},n.addGroup=function(){var t,e=this.conditions[0];this.blueprint.length>0&&this.blueprint.push({depth:t=void 0===t?0:t,type:"conjunction",word:"or"}),this.blueprint.push(h(e.id,1,e)),p(this.blueprint)},n.addCriterion=function(t){var e,i=this.conditions[0];this.blueprint.splice(t+1,0,{depth:e=void 0===e?1:e,type:"conjunction",word:"and"},h(i.id,1,i)),p(this.blueprint)},n.deleteCriterion=function(t){var e=this.blueprint,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,a=n&&"or"===n.word||!n,o=r||!i,s=o&&a;if(i||n?e.splice(s&&r?t-1:s&&!i||o&&!a?t:t-1,2):this.blueprint=[],0===this.blueprint.length){var l=this.conditions[0];this.blueprint.push(h(l.id,1,l))}p(this.blueprint)},n.replaceCriterion=function(t,e,i){var n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(h));this.blueprint[t]=h(e,n.depth,i),p(this.blueprint)},n.updateInput=function(t,e,i){var n=this.blueprint[t],a=(i=i||"input").split(", ");a.length>1?n[a[0]][a[1]]=r({},n[a[0]][a[1]],e):n[i]=r({},n[i],e),p(this.blueprint)},i}(t.Controller);f.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},f.targets=["loading"];var b=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.connect=function(){var t;this.idValue&&(t=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}}),window.dispatchEvent(t))},i.updateStableIdField=function(t){this.hasStableIdFieldTarget&&(this.stableIdFieldTarget.value=t.detail.stableId)},i.activateSaveLink=function(t){var e=t.detail,i=e.stableId,n=e.initialLoad;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){var r=new URL(this.enabledSaveLinkTarget.href);r.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",r),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}},e}(t.Controller);b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String};var v=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var n=e.prototype;return n.initialize=function(){var t=this;this.updateBlueprint=i.debounce(function(e,i,n){t.value(e,i,n),t.createStableId(t.state.blueprint,t.state.filterName)},500)},n.connect=function(){s.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)},n.refinedFilter=function(t){this.state.updateInput(this.criterionIdValue,{id:t.target.value},t.target.dataset.inputId),this.submitForm()},n.clause=function(t){this.state.updateInput(this.criterionIdValue,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()},n.selected=function(t){var e=Array.prototype.slice.call(t.target.options).filter(function(t){return t.selected}).map(function(t){return t.value});this.value(t,e,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)},n.value=function(t,e,i){var n,r=t.target.dataset,a=r.inputId;this.state.updateInput(this.criterionIdValue,((n={})[i=i||r.inputKey||"value"]=e=e||t.target.value,n),a)},n.date=function(t){var e=t.detail.picker.startDate.format("YYYY-MM-DD");this.value(t,e),this.submitForm()},n.createStableId=function(t,e){var i=this.state,n=JSON.stringify({blueprint:t,filter:e}),r=document.querySelector("meta[name='csrf-token']").content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r},success:function(t){i.updateStableId(t.filter_id)}})},n.condition=function(t){var e=this.criterionIdValue,i=this.state,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()},n.cancelEnter=function(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())},e}(s);v.values={criterionId:Number,stableId:String};var m=[[l,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[d,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[f,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[v,"refine/update-controller.js"]].map(function(t){var e=t[0];return{identifier:n(t[1]),controllerConstructor:e}});exports.AddController=l,exports.DefaultsController=u,exports.DeleteController=d,exports.FormController=s,exports.StateController=f,exports.StoredFilterController=b,exports.UpdateController=v,exports.controllerDefinitions=m;
var t=require("stimulus"),e=require("jquery-events-to-dom-events"),i=require("lodash");function n(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}function r(){return r=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},r.apply(this,arguments)}function o(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,a(t,e)}function a(t,e){return a=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},a(t,e)}var s=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()},i.getStateController=function(){for(var t=this.element;t!==document.body;){var e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null},i.addHiddenInput=function(t,e){var i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i},i.finishUpdate=function(){this.state.finishUpdate()},i.startUpdate=function(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()},i.submitForm=function(){this.startUpdate(),this.element.requestSubmit()},e}(t.Controller),l=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.criterion=function(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()},i.group=function(){this.state.addGroup(),this.startUpdate()},e}(s);l.values={previousCriterionId:Number};var u=function(t){function e(){return t.apply(this,arguments)||this}return o(e,t),e.prototype.connect=function(){var t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)},e}(t.Controller);u.values={criterionId:Number,input:Object};var d=function(t){function e(){return t.apply(this,arguments)||this}return o(e,t),e.prototype.criterion=function(){this.state.deleteCriterion(this.criterionIdValue),this.startUpdate()},e}(s);d.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();var c=function(t,e,i,n){var r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},p=function(t){var e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},h=function(t,e,i){var n=i.meta,r={clause:n.clauses[0].id,selected:"option-condition"===i.component?[n.options[0].id]:void 0};return i.refinements.forEach(function(t){var e=t.meta;r[t.id]={clause:e.clauses[0].id,selected:"option-condition"===t.component?[e.options[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:r}},f=function(t){function i(){return t.apply(this,arguments)||this}o(i,t);var n=i.prototype;return n.connect=function(){this.changeDelegate=e.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce(function(t,e){return t[e.id]=e,t},{}),this.loadingTimeout=null,c(this.element,this.stableId,this.filterName,!0),c(window,this.stableId,this.filterName,!0)},n.disconnect=function(){e.abnegate("change",this.changeDelegate)},n.startUpdate=function(){var t=this;this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(function(){document.activeElement.blur(),t.loadingTarget.classList.remove("hidden")},1e3)},n.finishUpdate=function(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")},n.conditionConfigFor=function(t){return this.conditionsLookup[t]},n.updateStableId=function(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),c(this.element,this.stableId,this.filterName),c(window,this.stableId,this.filterName))},n.addGroup=function(){var t,e=this.conditions[0];this.blueprint.length>0&&this.blueprint.push({depth:t=void 0===t?0:t,type:"conjunction",word:"or"}),this.blueprint.push(h(e.id,1,e)),p(this.blueprint)},n.addCriterion=function(t){var e,i=this.conditions[0];this.blueprint.splice(t+1,0,{depth:e=void 0===e?1:e,type:"conjunction",word:"and"},h(i.id,1,i)),p(this.blueprint)},n.deleteCriterion=function(t){var e=this.blueprint,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,o=n&&"or"===n.word||!n,a=r||!i,s=a&&o;if(i||n?e.splice(s&&r?t-1:s&&!i||a&&!o?t:t-1,2):this.blueprint=[],0===this.blueprint.length){var l=this.conditions[0];this.blueprint.push(h(l.id,1,l))}p(this.blueprint)},n.replaceCriterion=function(t,e,i){var n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(h));this.blueprint[t]=h(e,n.depth,i),p(this.blueprint)},n.updateInput=function(t,e,i){var n=this.blueprint[t],o=(i=i||"input").split(", ");o.length>1?n[o[0]][o[1]]=r({},n[o[0]][o[1]],e):n[i]=r({},n[i],e),p(this.blueprint)},i}(t.Controller);f.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},f.targets=["loading"];var v=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var i=e.prototype;return i.connect=function(){var t;this.idValue&&(t=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}}),window.dispatchEvent(t))},i.updateStableIdField=function(t){this.hasStableIdFieldTarget&&(this.stableIdFieldTarget.value=t.detail.stableId)},i.activateSaveLink=function(t){var e=t.detail,i=e.stableId,n=e.initialLoad;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){var r=new URL(this.enabledSaveLinkTarget.href);r.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",r),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}},e}(t.Controller);v.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],v.values={id:Number,stableId:String};var b=function(t){function e(){return t.apply(this,arguments)||this}o(e,t);var n=e.prototype;return n.initialize=function(){var t=this;this.updateBlueprint=i.debounce(function(e,i,n){t.value(e,i,n),t.createStableId(t.state.blueprint,t.state.filterName)},500)},n.connect=function(){s.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)},n.refinedFilter=function(t){this.state.updateInput(this.criterionIdValue,{id:t.target.value},t.target.dataset.inputId),this.submitForm()},n.clause=function(t){this.state.updateInput(this.criterionIdValue,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()},n.selected=function(t){var e=Array.prototype.slice.call(t.target.options).filter(function(t){return t.selected}).map(function(t){return t.value});this.value(t,e,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)},n.value=function(t,e,i){var n,r=t.target.dataset,o=r.inputId;this.state.updateInput(this.criterionIdValue,((n={})[i=i||r.inputKey||"value"]=e=e||t.target.value,n),o)},n.date=function(t){var e=t.detail.picker.startDate.format("YYYY-MM-DD");this.value(t,e),this.submitForm()},n.createStableId=function(t,e){var i,n=this.state,r=JSON.stringify({blueprint:t,filter:e}),o=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":o},success:function(t){n.updateStableId(t.filter_id)}})},n.condition=function(t){var e=this.criterionIdValue,i=this.state,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()},n.cancelEnter=function(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())},e}(s);b.values={criterionId:Number,stableId:String};var m=[[l,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[d,"refine/delete-controller.js"],[s,"refine/form-controller.js"],[f,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[b,"refine/update-controller.js"]].map(function(t){var e=t[0];return{identifier:n(t[1]),controllerConstructor:e}});exports.AddController=l,exports.DefaultsController=u,exports.DeleteController=d,exports.FormController=s,exports.StateController=f,exports.StoredFilterController=v,exports.UpdateController=b,exports.controllerDefinitions=m;
//# sourceMappingURL=refine-stimulus.js.map

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

import{Controller as t}from"stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function s(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class a extends t{connect(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class r extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}r.values={previousCriterionId:Number};class o extends t{connect(){const t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)}}o.values={criterionId:Number,input:Object};class l extends a{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}function d(){return d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},d.apply(this,arguments)}l.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const u=(t,e,i,n)=>{const s=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(s)},c=t=>{const e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},h=(t,e,i)=>{const{meta:n,refinements:s,component:a}=i,{clauses:r,options:o}=n;let l={clause:r[0].id,selected:"option-condition"===a?[o[0].id]:void 0};return s.forEach(t=>{const{meta:e,component:i}=t,{clauses:n,options:s}=e;l[t.id]={clause:n[0].id,selected:"option-condition"===i?[s[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:l}};class p extends t{connect(){this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,u(this.element,this.stableId,this.filterName,!0),u(window,this.stableId,this.filterName,!0)}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),u(this.element,this.stableId,this.filterName),u(window,this.stableId,this.filterName))}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(h(e.id,1,e)),c(this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var s;e.splice(t+1,0,{depth:s=void 0===s?1:s,type:"conjunction",word:"and"},h(n.id,1,n)),c(this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],s=i&&"or"===i.word,a=n&&"or"===n.word||!n,r=s||!i,o=r&&a;if(i||n?e.splice(o&&s?t-1:o&&!i||r&&!a?t:t-1,2):this.blueprint=[],0===this.blueprint.length){const t=this.conditions[0];this.blueprint.push(h(t.id,1,t))}c(this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(h)}`);this.blueprint[t]=h(e,n.depth,i),c(this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,s=n[t],a=(i=i||"input").split(", ");a.length>1?s[a[0]][a[1]]=d({},s[a[0]][a[1]],e):s[i]=d({},s[i],e),c(this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends t{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String};class m extends a{initialize(){this.updateBlueprint=n((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){a.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:s}=this,a=t.target.dataset;s.updateInput(n,{[i=i||a.inputKey||"value"]:e=e||t.target.value},a.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){const{state:i}=this;let n=JSON.stringify({blueprint:t,filter:e}),s=document.querySelector("meta[name='csrf-token']").content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":s},success:function(t){i.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,s=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,s),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}m.values={criterionId:Number,stableId:String};const f=[[r,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:s(t[1]),controllerConstructor:e}});export{r as AddController,o as DefaultsController,l as DeleteController,a as FormController,p as StateController,b as StoredFilterController,m as UpdateController,f as controllerDefinitions};
import{Controller as t}from"stimulus";import{delegate as e,abnegate as i}from"jquery-events-to-dom-events";import{debounce as n}from"lodash";function s(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}class a extends t{connect(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()}getStateController(){let t=this.element;for(;t!==document.body;){const e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null}addHiddenInput(t,e){const i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i}finishUpdate(){this.state.finishUpdate()}startUpdate(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()}submitForm(){this.startUpdate(),this.element.requestSubmit()}}class r extends a{criterion(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()}group(){this.state.addGroup(),this.startUpdate()}}r.values={previousCriterionId:Number};class o extends t{connect(){const t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)}}o.values={criterionId:Number,input:Object};class l extends a{criterion(){const{state:t,criterionIdValue:e}=this;t.deleteCriterion(e),this.startUpdate()}}function d(){return d=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},d.apply(this,arguments)}l.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();const u=(t,e,i,n)=>{const s=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(s)},c=t=>{const e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},h=(t,e,i)=>{const{meta:n,refinements:s,component:a}=i,{clauses:r,options:o}=n;let l={clause:r[0].id,selected:"option-condition"===a?[o[0].id]:void 0};return s.forEach(t=>{const{meta:e,component:i}=t,{clauses:n,options:s}=e;l[t.id]={clause:n[0].id,selected:"option-condition"===i?[s[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:l}};class p extends t{connect(){this.changeDelegate=e("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce((t,e)=>(t[e.id]=e,t),{}),this.loadingTimeout=null,u(this.element,this.stableId,this.filterName,!0),u(window,this.stableId,this.filterName,!0)}disconnect(){i("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{document.activeElement.blur(),this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(t){return this.conditionsLookup[t]}updateStableId(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),u(this.element,this.stableId,this.filterName),u(window,this.stableId,this.filterName))}addGroup(){const{conditions:t}=this,e=t[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(h(e.id,1,e)),c(this.blueprint)}addCriterion(t){const{blueprint:e,conditions:i}=this,n=i[0];var s;e.splice(t+1,0,{depth:s=void 0===s?1:s,type:"conjunction",word:"and"},h(n.id,1,n)),c(this.blueprint)}deleteCriterion(t){const{blueprint:e}=this,i=e[t-1],n=e[t+1],s=i&&"or"===i.word,a=n&&"or"===n.word||!n,r=s||!i,o=r&&a;if(i||n?e.splice(o&&s?t-1:o&&!i||r&&!a?t:t-1,2):this.blueprint=[],0===this.blueprint.length){const t=this.conditions[0];this.blueprint.push(h(t.id,1,t))}c(this.blueprint)}replaceCriterion(t,e,i){const n=this.blueprint[t];if("criterion"!==n.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(h)}`);this.blueprint[t]=h(e,n.depth,i),c(this.blueprint)}updateInput(t,e,i){const{blueprint:n}=this,s=n[t],a=(i=i||"input").split(", ");a.length>1?s[a[0]][a[1]]=d({},s[a[0]][a[1]],e):s[i]=d({},s[i],e),c(this.blueprint)}}p.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},p.targets=["loading"];class b extends t{connect(){this.idValue&&(t=>{const e=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}});window.dispatchEvent(e)})()}updateStableIdField(t){if(this.hasStableIdFieldTarget){const{detail:e}=t,{stableId:i}=e;this.stableIdFieldTarget.value=i}}activateSaveLink(t){const{detail:e}=t,{stableId:i,initialLoad:n}=e;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){const t=new URL(this.enabledSaveLinkTarget.href);t.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",t),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}}}b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String};class m extends a{initialize(){this.updateBlueprint=n((t,e,i)=>{this.value(t,e,i),this.createStableId(this.state.blueprint,this.state.filterName)},500)}connect(){a.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)}refinedFilter(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{id:t.target.value},t.target.dataset.inputId),this.submitForm()}clause(t){const{criterionIdValue:e,state:i}=this;i.updateInput(e,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()}selected(t){const{target:e}=t,i=Array.prototype.slice.call(e.options).filter(t=>t.selected).map(t=>t.value);this.value(t,i,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)}value(t,e,i){const{criterionIdValue:n,state:s}=this,a=t.target.dataset;s.updateInput(n,{[i=i||a.inputKey||"value"]:e=e||t.target.value},a.inputId)}date(t){const{picker:e}=t.detail,i=e.startDate.format("YYYY-MM-DD");this.value(t,i),this.submitForm()}createStableId(t,e){var i;const{state:n}=this;let s=JSON.stringify({blueprint:t,filter:e}),a=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:s,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":a},success:function(t){n.updateStableId(t.filter_id)}})}condition(t){const{criterionIdValue:e,state:i}=this,n=t.target.value,s=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,s),this.submitForm()}cancelEnter(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())}}m.values={criterionId:Number,stableId:String};const f=[[r,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[p,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){const e=t[0];return{identifier:s(t[1]),controllerConstructor:e}});export{r as AddController,o as DefaultsController,l as DeleteController,a as FormController,p as StateController,b as StoredFilterController,m as UpdateController,f as controllerDefinitions};
//# sourceMappingURL=refine-stimulus.modern.js.map

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

!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("stimulus"),require("jquery-events-to-dom-events"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","stimulus","jquery-events-to-dom-events","lodash"],e):e((t||self).refineStimulus={},t.stimulus,t.jqueryEventsToDomEvents,t.lodash)}(this,function(t,e,i,n){function r(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}function o(){return o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o.apply(this,arguments)}function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},s(t,e)}var l=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()},i.getStateController=function(){for(var t=this.element;t!==document.body;){var e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null},i.addHiddenInput=function(t,e){var i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i},i.finishUpdate=function(){this.state.finishUpdate()},i.startUpdate=function(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()},i.submitForm=function(){this.startUpdate(),this.element.requestSubmit()},e}(e.Controller),u=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.criterion=function(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()},i.group=function(){this.state.addGroup(),this.startUpdate()},e}(l);u.values={previousCriterionId:Number};var d=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e.prototype.connect=function(){var t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)},e}(e.Controller);d.values={criterionId:Number,input:Object};var c=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e.prototype.criterion=function(){this.state.deleteCriterion(this.criterionIdValue),this.startUpdate()},e}(l);c.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();var p=function(t,e,i,n){var r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},h=function(t){var e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},f=function(t,e,i){var n=i.meta,r={clause:n.clauses[0].id,selected:"option-condition"===i.component?[n.options[0].id]:void 0};return i.refinements.forEach(function(t){var e=t.meta;r[t.id]={clause:e.clauses[0].id,selected:"option-condition"===t.component?[e.options[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:r}},b=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var n=e.prototype;return n.connect=function(){this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce(function(t,e){return t[e.id]=e,t},{}),this.loadingTimeout=null,p(this.element,this.stableId,this.filterName,!0),p(window,this.stableId,this.filterName,!0)},n.disconnect=function(){i.abnegate("change",this.changeDelegate)},n.startUpdate=function(){var t=this;this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(function(){document.activeElement.blur(),t.loadingTarget.classList.remove("hidden")},1e3)},n.finishUpdate=function(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")},n.conditionConfigFor=function(t){return this.conditionsLookup[t]},n.updateStableId=function(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),p(this.element,this.stableId,this.filterName),p(window,this.stableId,this.filterName))},n.addGroup=function(){var t,e=this.conditions[0];this.blueprint.length>0&&this.blueprint.push({depth:t=void 0===t?0:t,type:"conjunction",word:"or"}),this.blueprint.push(f(e.id,1,e)),h(this.blueprint)},n.addCriterion=function(t){var e,i=this.conditions[0];this.blueprint.splice(t+1,0,{depth:e=void 0===e?1:e,type:"conjunction",word:"and"},f(i.id,1,i)),h(this.blueprint)},n.deleteCriterion=function(t){var e=this.blueprint,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,o=n&&"or"===n.word||!n,a=r||!i,s=a&&o;if(i||n?e.splice(s&&r?t-1:s&&!i||a&&!o?t:t-1,2):this.blueprint=[],0===this.blueprint.length){var l=this.conditions[0];this.blueprint.push(f(l.id,1,l))}h(this.blueprint)},n.replaceCriterion=function(t,e,i){var n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));this.blueprint[t]=f(e,n.depth,i),h(this.blueprint)},n.updateInput=function(t,e,i){var n=this.blueprint[t],r=(i=i||"input").split(", ");r.length>1?n[r[0]][r[1]]=o({},n[r[0]][r[1]],e):n[i]=o({},n[i],e),h(this.blueprint)},e}(e.Controller);b.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},b.targets=["loading"];var v=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.connect=function(){var t;this.idValue&&(t=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}}),window.dispatchEvent(t))},i.updateStableIdField=function(t){this.hasStableIdFieldTarget&&(this.stableIdFieldTarget.value=t.detail.stableId)},i.activateSaveLink=function(t){var e=t.detail,i=e.stableId,n=e.initialLoad;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){var r=new URL(this.enabledSaveLinkTarget.href);r.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",r),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}},e}(e.Controller);v.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],v.values={id:Number,stableId:String};var m=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.initialize=function(){var t=this;this.updateBlueprint=n.debounce(function(e,i,n){t.value(e,i,n),t.createStableId(t.state.blueprint,t.state.filterName)},500)},i.connect=function(){l.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)},i.refinedFilter=function(t){this.state.updateInput(this.criterionIdValue,{id:t.target.value},t.target.dataset.inputId),this.submitForm()},i.clause=function(t){this.state.updateInput(this.criterionIdValue,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()},i.selected=function(t){var e=Array.prototype.slice.call(t.target.options).filter(function(t){return t.selected}).map(function(t){return t.value});this.value(t,e,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)},i.value=function(t,e,i){var n,r=t.target.dataset,o=r.inputId;this.state.updateInput(this.criterionIdValue,((n={})[i=i||r.inputKey||"value"]=e=e||t.target.value,n),o)},i.date=function(t){var e=t.detail.picker.startDate.format("YYYY-MM-DD");this.value(t,e),this.submitForm()},i.createStableId=function(t,e){var i=this.state,n=JSON.stringify({blueprint:t,filter:e}),r=document.querySelector("meta[name='csrf-token']").content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:n,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":r},success:function(t){i.updateStableId(t.filter_id)}})},i.condition=function(t){var e=this.criterionIdValue,i=this.state,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()},i.cancelEnter=function(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())},e}(l);m.values={criterionId:Number,stableId:String};var g=[[u,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[l,"refine/form-controller.js"],[b,"refine/state-controller.js"],[v,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){var e=t[0];return{identifier:r(t[1]),controllerConstructor:e}});t.AddController=u,t.DefaultsController=d,t.DeleteController=c,t.FormController=l,t.StateController=b,t.StoredFilterController=v,t.UpdateController=m,t.controllerDefinitions=g});
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("stimulus"),require("jquery-events-to-dom-events"),require("lodash")):"function"==typeof define&&define.amd?define(["exports","stimulus","jquery-events-to-dom-events","lodash"],e):e((t||self).refineStimulus={},t.stimulus,t.jqueryEventsToDomEvents,t.lodash)}(this,function(t,e,i,n){function r(t){var e=(t.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(e)return e.replace(/_/g,"-").replace(/\//g,"--")}function o(){return o=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var i=arguments[e];for(var n in i)Object.prototype.hasOwnProperty.call(i,n)&&(t[n]=i[n])}return t},o.apply(this,arguments)}function a(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,s(t,e)}function s(t,e){return s=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t},s(t,e)}var l=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.blueprintInput=this.addHiddenInput("blueprint"),this.addHiddenInput("filter",this.state.filterName),this.addHiddenInput("id_suffix",this.state.idSuffix),this.finishUpdate()},i.getStateController=function(){for(var t=this.element;t!==document.body;){var e=this.application.getControllerForElementAndIdentifier(t,"refine--state");if(e)return e;t=t.parentNode}return null},i.addHiddenInput=function(t,e){var i=document.createElement("input");return i.type="hidden",i.name=t,i.value=e||"",this.element.appendChild(i),i},i.finishUpdate=function(){this.state.finishUpdate()},i.startUpdate=function(){this.blueprintInput.value=JSON.stringify(this.state.blueprint),this.state.startUpdate()},i.submitForm=function(){this.startUpdate(),this.element.requestSubmit()},e}(e.Controller),u=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.criterion=function(){this.state.addCriterion(this.previousCriterionIdValue),this.startUpdate()},i.group=function(){this.state.addGroup(),this.startUpdate()},e}(l);u.values={previousCriterionId:Number};var d=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e.prototype.connect=function(){var t=document.getElementById("refine");this.state=this.application.getControllerForElementAndIdentifier(t,"refine--state"),this.state.updateInput(this.criterionIdValue,this.inputValue)},e}(e.Controller);d.values={criterionId:Number,input:Object};var c=function(t){function e(){return t.apply(this,arguments)||this}return a(e,t),e.prototype.criterion=function(){this.state.deleteCriterion(this.criterionIdValue),this.startUpdate()},e}(l);c.values={criterionId:Number},function(){if("function"==typeof window.CustomEvent)return!1;function t(t,e){e=e||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(t,e.bubbles,e.cancelable,e.detail),i}t.prototype=window.Event.prototype,window.CustomEvent=t}();var p=function(t,e,i,n){var r=new CustomEvent("filter-stabilized",{bubbles:!0,cancelable:!0,detail:{stableId:e,filterName:i,initialLoad:n}});t.dispatchEvent(r)},h=function(t){var e=new CustomEvent("filter-unstable",{detail:{blueprint:t}});window.dispatchEvent(e)},f=function(t,e,i){var n=i.meta,r={clause:n.clauses[0].id,selected:"option-condition"===i.component?[n.options[0].id]:void 0};return i.refinements.forEach(function(t){var e=t.meta;r[t.id]={clause:e.clauses[0].id,selected:"option-condition"===t.component?[e.options[0].id]:void 0}}),{depth:e,type:"criterion",condition_id:t,input:r}},v=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var n=e.prototype;return n.connect=function(){this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.idSuffix=this.idSuffixValue,this.stableId=this.stableIdValue,this.conditionsLookup=this.conditions.reduce(function(t,e){return t[e.id]=e,t},{}),this.loadingTimeout=null,p(this.element,this.stableId,this.filterName,!0),p(window,this.stableId,this.filterName,!0)},n.disconnect=function(){i.abnegate("change",this.changeDelegate)},n.startUpdate=function(){var t=this;this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(function(){document.activeElement.blur(),t.loadingTarget.classList.remove("hidden")},1e3)},n.finishUpdate=function(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")},n.conditionConfigFor=function(t){return this.conditionsLookup[t]},n.updateStableId=function(t){t!==this.stableId&&(this.stableId=t,console.log(this.blueprint),p(this.element,this.stableId,this.filterName),p(window,this.stableId,this.filterName))},n.addGroup=function(){var t,e=this.conditions[0];this.blueprint.length>0&&this.blueprint.push({depth:t=void 0===t?0:t,type:"conjunction",word:"or"}),this.blueprint.push(f(e.id,1,e)),h(this.blueprint)},n.addCriterion=function(t){var e,i=this.conditions[0];this.blueprint.splice(t+1,0,{depth:e=void 0===e?1:e,type:"conjunction",word:"and"},f(i.id,1,i)),h(this.blueprint)},n.deleteCriterion=function(t){var e=this.blueprint,i=e[t-1],n=e[t+1],r=i&&"or"===i.word,o=n&&"or"===n.word||!n,a=r||!i,s=a&&o;if(i||n?e.splice(s&&r?t-1:s&&!i||a&&!o?t:t-1,2):this.blueprint=[],0===this.blueprint.length){var l=this.conditions[0];this.blueprint.push(f(l.id,1,l))}h(this.blueprint)},n.replaceCriterion=function(t,e,i){var n=this.blueprint[t];if("criterion"!==n.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(f));this.blueprint[t]=f(e,n.depth,i),h(this.blueprint)},n.updateInput=function(t,e,i){var n=this.blueprint[t],r=(i=i||"input").split(", ");r.length>1?n[r[0]][r[1]]=o({},n[r[0]][r[1]],e):n[i]=o({},n[i],e),h(this.blueprint)},e}(e.Controller);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var b=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.connect=function(){var t;this.idValue&&(t=new CustomEvent("filter-stored",{detail:{storedFilterId:this.idValue}}),window.dispatchEvent(t))},i.updateStableIdField=function(t){this.hasStableIdFieldTarget&&(this.stableIdFieldTarget.value=t.detail.stableId)},i.activateSaveLink=function(t){var e=t.detail,i=e.stableId,n=e.initialLoad;if(i==this.stableIdValue&&(t.preventDefault(),t.stopPropagation()),this.hasEnabledSaveLinkTarget&&this.hasDisabledSaveLinkTarget&&!n){var r=new URL(this.enabledSaveLinkTarget.href);r.searchParams.set("stable_id",i),this.enabledSaveLinkTarget.setAttribute("href",r),this.disabledSaveLinkTarget.classList.add("hidden"),this.enabledSaveLinkTarget.classList.remove("hidden")}},e}(e.Controller);b.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],b.values={id:Number,stableId:String};var m=function(t){function e(){return t.apply(this,arguments)||this}a(e,t);var i=e.prototype;return i.initialize=function(){var t=this;this.updateBlueprint=n.debounce(function(e,i,n){t.value(e,i,n),t.createStableId(t.state.blueprint,t.state.filterName)},500)},i.connect=function(){l.prototype.connect.apply(this),this.state.updateStableId(this.stableIdValue)},i.refinedFilter=function(t){this.state.updateInput(this.criterionIdValue,{id:t.target.value},t.target.dataset.inputId),this.submitForm()},i.clause=function(t){this.state.updateInput(this.criterionIdValue,{clause:t.target.value},t.target.dataset.inputId),this.submitForm()},i.selected=function(t){var e=Array.prototype.slice.call(t.target.options).filter(function(t){return t.selected}).map(function(t){return t.value});this.value(t,e,"selected"),this.createStableId(this.state.blueprint,this.state.filterName)},i.value=function(t,e,i){var n,r=t.target.dataset,o=r.inputId;this.state.updateInput(this.criterionIdValue,((n={})[i=i||r.inputKey||"value"]=e=e||t.target.value,n),o)},i.date=function(t){var e=t.detail.picker.startDate.format("YYYY-MM-DD");this.value(t,e),this.submitForm()},i.createStableId=function(t,e){var i,n=this.state,r=JSON.stringify({blueprint:t,filter:e}),o=null==(i=document.querySelector("meta[name='csrf-token']"))?void 0:i.content;$.ajax({type:"PUT",url:"/hammerstone/update_stable_id",data:r,headers:{accept:"application/json","content-type":"application/json","X-CSRF-Token":o},success:function(t){n.updateStableId(t.filter_id)}})},i.condition=function(t){var e=this.criterionIdValue,i=this.state,n=t.target.value,r=this.state.conditionConfigFor(n);i.replaceCriterion(e,n,r),this.submitForm()},i.cancelEnter=function(t){"Enter"===t.code&&(t.preventDefault(),t.stopPropagation())},e}(l);m.values={criterionId:Number,stableId:String};var g=[[u,"refine/add-controller.js"],[d,"refine/defaults-controller.js"],[c,"refine/delete-controller.js"],[l,"refine/form-controller.js"],[v,"refine/state-controller.js"],[b,"refine/stored-filter-controller.js"],[m,"refine/update-controller.js"]].map(function(t){var e=t[0];return{identifier:r(t[1]),controllerConstructor:e}});t.AddController=u,t.DefaultsController=d,t.DeleteController=c,t.FormController=l,t.StateController=v,t.StoredFilterController=b,t.UpdateController=m,t.controllerDefinitions=g});
//# sourceMappingURL=refine-stimulus.umd.js.map

@@ -86,3 +86,3 @@ import FormController from './form-controller'

let post_data = JSON.stringify({ blueprint, filter })
let token = document.querySelector("meta[name='csrf-token']").content
let token = document.querySelector("meta[name='csrf-token']")?.content
$.ajax({

@@ -89,0 +89,0 @@ type: 'PUT',

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

@@ -5,0 +5,0 @@ "main": "app/assets/javascripts/refine-stimulus.js",

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