@hammerstone/refine-stimulus
Advanced tools
Comparing version 1.2.1 to 2.0.0
@@ -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}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)},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},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){var e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},b=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.element.refineStateController=this,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,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(b(e.id,1,e)),f(this.blueprint),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"},b(i.id,1,i)),f(this.blueprint),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(b(l.id,1,l))}f(this.blueprint),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(b));this.blueprint[t]=b(e,n.depth,i),f(this.blueprint),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),f(this.blueprint),h(this.blueprint)},n}(t);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var m=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);m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String};var g=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);g.values={criterionId:Number,stableId:String};var I=[[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"],[m,"refine/stored-filter-controller.js"],[g,"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,m as StoredFilterController,g as UpdateController,I 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(){console.log("Form Controller Connected"),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}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)},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},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){var e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},b=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.element.refineStateController=this,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,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(b(e.id,1,e)),f(this.blueprint),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"},b(i.id,1,i)),f(this.blueprint),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(b(l.id,1,l))}f(this.blueprint),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(b));this.blueprint[t]=b(e,n.depth,i),f(this.blueprint),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),f(this.blueprint),h(this.blueprint)},n}(t);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var m=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);m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String};var g=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);g.values={criterionId:Number,stableId:String};var I=[[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"],[m,"refine/stored-filter-controller.js"],[g,"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,m as StoredFilterController,g as UpdateController,I 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 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}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)},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},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){var e=new CustomEvent("blueprint-updated",{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 i(){return t.apply(this,arguments)||this}o(i,t);var n=i.prototype;return n.connect=function(){this.element.refineStateController=this,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,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(f(e.id,1,e)),h(this.blueprint),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"},f(i.id,1,i)),h(this.blueprint),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(f(l.id,1,l))}h(this.blueprint),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(f));this.blueprint[t]=f(e,n.depth,i),h(this.blueprint),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),h(this.blueprint),p(this.blueprint)},i}(t.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}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 m=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);m.values={criterionId:Number,stableId:String};var g=[[l,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[d,"refine/delete-controller.js"],[s,"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:n(t[1]),controllerConstructor:e}});exports.AddController=l,exports.DefaultsController=u,exports.DeleteController=d,exports.FormController=s,exports.StateController=b,exports.StoredFilterController=v,exports.UpdateController=m,exports.controllerDefinitions=g; | ||
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(){console.log("Form Controller Connected"),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}o(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)},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},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){var e=new CustomEvent("blueprint-updated",{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 i(){return t.apply(this,arguments)||this}o(i,t);var n=i.prototype;return n.connect=function(){this.element.refineStateController=this,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,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(f(e.id,1,e)),h(this.blueprint),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"},f(i.id,1,i)),h(this.blueprint),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(f(l.id,1,l))}h(this.blueprint),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(f));this.blueprint[t]=f(e,n.depth,i),h(this.blueprint),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),h(this.blueprint),p(this.blueprint)},i}(t.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}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 m=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);m.values={criterionId:Number,stableId:String};var g=[[l,"refine/add-controller.js"],[u,"refine/defaults-controller.js"],[d,"refine/delete-controller.js"],[s,"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:n(t[1]),controllerConstructor:e}});exports.AddController=l,exports.DefaultsController=u,exports.DeleteController=d,exports.FormController=s,exports.StateController=b,exports.StoredFilterController=v,exports.UpdateController=m,exports.controllerDefinitions=g; | ||
//# 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(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}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}}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=>{const e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},p=(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 b extends t{connect(){this.element.refineStateController=this,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,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(p(e.id,1,e)),h(this.blueprint),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"},p(n.id,1,n)),h(this.blueprint),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(p(t.id,1,t))}h(this.blueprint),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(p)}`);this.blueprint[t]=p(e,n.depth,i),h(this.blueprint),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),h(this.blueprint),c(this.blueprint)}}b.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},b.targets=["loading"];class m 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")}}}m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String};class f 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())}}f.values={criterionId:Number,stableId:String};const v=[[r,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[b,"refine/state-controller.js"],[m,"refine/stored-filter-controller.js"],[f,"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,b as StateController,m as StoredFilterController,f as UpdateController,v 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(){console.log("Form Controller Connected"),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(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}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}}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=>{const e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},p=(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 b extends t{connect(){this.element.refineStateController=this,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,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(p(e.id,1,e)),h(this.blueprint),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"},p(n.id,1,n)),h(this.blueprint),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(p(t.id,1,t))}h(this.blueprint),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(p)}`);this.blueprint[t]=p(e,n.depth,i),h(this.blueprint),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),h(this.blueprint),c(this.blueprint)}}b.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},b.targets=["loading"];class m 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")}}}m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String};class f 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())}}f.values={criterionId:Number,stableId:String};const v=[[r,"refine/add-controller.js"],[o,"refine/defaults-controller.js"],[l,"refine/delete-controller.js"],[a,"refine/form-controller.js"],[b,"refine/state-controller.js"],[m,"refine/stored-filter-controller.js"],[f,"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,b as StateController,m as StoredFilterController,f as UpdateController,v 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}a(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)},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},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){var e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},b=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.element.refineStateController=this,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,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(b(e.id,1,e)),f(this.blueprint),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"},b(i.id,1,i)),f(this.blueprint),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(b(l.id,1,l))}f(this.blueprint),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(b));this.blueprint[t]=b(e,n.depth,i),f(this.blueprint),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),f(this.blueprint),h(this.blueprint)},e}(e.Controller);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var m=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);m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String};var g=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);g.values={criterionId:Number,stableId:String};var I=[[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"],[m,"refine/stored-filter-controller.js"],[g,"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=m,t.UpdateController=g,t.controllerDefinitions=I}); | ||
!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(){console.log("Form Controller Connected"),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}a(e,t);var i=e.prototype;return i.connect=function(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)},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},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){var e=new CustomEvent("blueprint-updated",{detail:{blueprint:t}});window.dispatchEvent(e)},b=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.element.refineStateController=this,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,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(b(e.id,1,e)),f(this.blueprint),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"},b(i.id,1,i)),f(this.blueprint),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(b(l.id,1,l))}f(this.blueprint),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(b));this.blueprint[t]=b(e,n.depth,i),f(this.blueprint),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),f(this.blueprint),h(this.blueprint)},e}(e.Controller);v.values={blueprint:Array,conditions:Array,className:String,stableId:String,idSuffix:String},v.targets=["loading"];var m=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);m.targets=["enabledSaveLink","disabledSaveLink","stableIdField"],m.values={id:Number,stableId:String};var g=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);g.values={criterionId:Number,stableId:String};var I=[[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"],[m,"refine/stored-filter-controller.js"],[g,"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=m,t.UpdateController=g,t.controllerDefinitions=I}); | ||
//# sourceMappingURL=refine-stimulus.umd.js.map |
@@ -5,2 +5,3 @@ import { Controller } from "stimulus" | ||
connect() { | ||
console.log('Form Controller Connected') | ||
this.state = this.getStateController() | ||
@@ -7,0 +8,0 @@ this.blueprintInput = this.addHiddenInput('blueprint') |
{ | ||
"name": "@hammerstone/refine-stimulus", | ||
"version": "1.2.1", | ||
"version": "2.0.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 @@ "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
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
Network access
Supply chain riskThis module accesses the network.
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
183449
22
720
1