@clickfunnels/refine-stimulus
Advanced tools
Comparing version 2.11.5 to 2.11.6
@@ -1,2 +0,2 @@ | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{useClickOutside as r}from"stimulus-use";import{delegate as i,abnegate as n}from"jquery-events-to-dom-events";import{isEqual as s,debounce as l}from"lodash";import o from"moment";import a from"jquery";import"daterangepicker";function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}refreshFromServer(e){void 0===e&&(e={});try{const r=this,{includeErrors:i}=e;r.state.startUpdate();const n=new t("GET",r.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":r.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(r.state.blueprint),"refine_filters_builder[client_id]":r.state.clientIdValue,include_errors:!!i}});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class c extends u{criterion(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addCriterion(e.previousCriterionIdValue),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}group(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addGroup(),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{const e=this,r=new t("GET",e.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":e.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(e){return e.ok})}catch(e){return Promise.reject(e)}}}c.values={previousCriterionId:Number};class h extends e{refresh(e){try{const e=this,r=document.getElementById(e.formIdValue),i=new FormData(r),n=new t("GET",e.urlValue,{query:i,responseKind:"turbo-stream"});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}h.values={url:String,formId:String};class p extends e{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}p.values={criterionId:Number,input:Object};class m extends u{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}m.values={criterionId:Number};class f extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}f.values={submitUrl:String};class g extends e{connect(){r(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}g.targets=["frame"],g.values={src:String,isOpen:{type:Boolean,default:!1}};class b extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}b.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const v=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},y=(e,t,r)=>{var i;const n=null==r?void 0:r.component,s=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:o,options:a}=s;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let u={clause:null==(i=o[0])?void 0:i.id,selected:d};return l.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let s;s="option-condition"===r?n[0]?[n[0].id]:[]:void 0,u[e.id]={clause:i[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:u}};class w extends e{connect(){this.element.refineStateController=this,this.changeDelegate=i("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,v(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){n("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(y(t.id,1,t)),v(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r.find(e=>e.id==this.defaultConditionIdValue)||r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},y(i.id,1,i)),v(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,s=i&&"or"===i.word||!i,l=n||!r,o=l&&s;r||i?t.splice(o&&n?e-1:o&&!r||l&&!s?e:e-1,2):this.blueprint=[],v(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(y));const n=this.blueprint[e],l=y(t,i.depth,r);return!s(n,l)&&(this.blueprint[e]=l,v(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],s=(r=r||"input").split(", ");s.length>1?n[s[0]][s[1]]={...n[s[0]][s[1]],...t}:n[r]={...n[r],...t},v(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}w.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},w.targets=["loading"];class I extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}I.targets=["blueprintField"],I.values={formId:String,stateDomId:String};class C extends e{submit(e){e.preventDefault(),this.element.requestSubmit()}}class S extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}S.targets=["content"];class T extends e{submit(e){try{const r=this;e.preventDefault();const i=new t(r.element.method||"POST",r.element.action,{responseKind:"turbo-stream",body:new FormData(r.element)});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class V extends e{visit(e){try{const r=this;e.preventDefault();const i=new t(r.element.dataset.turboMethod||"GET",r.element.href,{responseKind:"turbo-stream"});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class E extends e{filter(e){const t=e.currentTarget.value.toLowerCase(),r=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,r.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===r.size}),this.categoryTargets.forEach(e=>{e.hidden=!r.has(e.innerHTML)})}}E.targets=["listItem","category","recommended"];class P extends u{initialize(){this.updateBlueprint=l((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,s=e.target.dataset;n.updateInput(i,{[r=r||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const s=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}P.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class F extends e{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const r=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,i=t?o(t.startDate.toISOString()):o(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),s=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=s,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:a(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=a(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(a(this.pluginMainEl).off("apply.daterangepicker"),a(this.pluginMainEl).off("cancel.daterangepicker"),a(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}F.targets=["field","hiddenField","clearButton"],F.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const j=[[c,"refine/add-controller.js"],[h,"refine/criterion-form-controller.js"],[p,"refine/defaults-controller.js"],[m,"refine/delete-controller.js"],[f,"refine/filter-pills-controller.js"],[g,"refine/popup-controller.js"],[b,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[w,"refine/state-controller.js"],[I,"refine/stored-filter-controller.js"],[C,"refine/submit-form-controller.js"],[S,"refine/toggle-controller.js"],[T,"refine/turbo-stream-form-controller.js"],[V,"refine/turbo-stream-link-controller.js"],[E,"./refine/typeahead-list-controller.js"],[P,"refine/update-controller.js"],[F,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{c as AddController,h as CriterionFormController,F as DateController,p as DefaultsController,m as DeleteController,f as FilterPillsController,g as PopupController,b as SearchFilterController,u as ServerRefreshController,w as StateController,I as StoredFilterController,C as SubmitForm,S as ToggleController,T as TurboStreamFormController,V as TurboStreamLinkController,E as TypeaheadListController,P as UpdateController,j as controllerDefinitions}; | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{useClickOutside as r}from"stimulus-use";import{delegate as i,abnegate as n}from"jquery-events-to-dom-events";import{isEqual as s,debounce as l}from"lodash";import o from"moment";import a from"jquery";import"daterangepicker";function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}refreshFromServer(e){void 0===e&&(e={});try{const r=this,{includeErrors:i}=e;r.state.startUpdate();const n=new t("GET",r.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":r.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(r.state.blueprint),"refine_filters_builder[client_id]":r.state.clientIdValue,include_errors:!!i}});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class c extends u{criterion(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addCriterion(e.previousCriterionIdValue),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}group(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addGroup(),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{const e=this,r=new t("GET",e.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":e.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(e){return e.ok})}catch(e){return Promise.reject(e)}}}c.values={previousCriterionId:Number};class h extends e{refresh(e){try{const e=this,r=document.getElementById(e.formIdValue),i=new FormData(r),n=new t("GET",e.urlValue,{query:i,responseKind:"turbo-stream"});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}h.values={url:String,formId:String};class p extends e{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}p.values={criterionId:Number,input:Object};class m extends u{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}m.values={criterionId:Number};class f extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}f.values={submitUrl:String};class g extends e{connect(){r(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}g.targets=["frame"],g.values={src:String,isOpen:{type:Boolean,default:!1}};class b extends e{connect(){console.log("Connecting modal controller"),r(this)}disconnect(){}open(e){console.log("Opening modal!!!",this.srcValue),e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}close(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.close(e)}}b.targets=["frame"],b.values={src:String,isOpen:{type:Boolean,default:!1}};class v extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}v.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const y=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},w=(e,t,r)=>{var i;const n=null==r?void 0:r.component,s=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:o,options:a}=s;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let u={clause:null==(i=o[0])?void 0:i.id,selected:d};return l.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let s;s="option-condition"===r?n[0]?[n[0].id]:[]:void 0,u[e.id]={clause:i[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:u}};class I extends e{connect(){this.element.refineStateController=this,this.changeDelegate=i("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){n("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(w(t.id,1,t)),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r.find(e=>e.id==this.defaultConditionIdValue)||r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},w(i.id,1,i)),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,s=i&&"or"===i.word||!i,l=n||!r,o=l&&s;r||i?t.splice(o&&n?e-1:o&&!r||l&&!s?e:e-1,2):this.blueprint=[],y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(w));const n=this.blueprint[e],l=w(t,i.depth,r);return!s(n,l)&&(this.blueprint[e]=l,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],s=(r=r||"input").split(", ");s.length>1?n[s[0]][s[1]]={...n[s[0]][s[1]],...t}:n[r]={...n[r],...t},y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}I.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},I.targets=["loading"];class C extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}C.targets=["blueprintField"],C.values={formId:String,stateDomId:String};class T extends e{submit(e){e.preventDefault(),this.element.requestSubmit()}}class S extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}S.targets=["content"];class V extends e{submit(e){try{const r=this;e.preventDefault();const i=new t(r.element.method||"POST",r.element.action,{responseKind:"turbo-stream",body:new FormData(r.element)});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class E extends e{visit(e){try{const r=this;e.preventDefault();const i=new t(r.element.dataset.turboMethod||"GET",r.element.href,{responseKind:"turbo-stream"});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class P extends e{filter(e){const t=e.currentTarget.value.toLowerCase(),r=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,r.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===r.size}),this.categoryTargets.forEach(e=>{e.hidden=!r.has(e.innerHTML)})}}P.targets=["listItem","category","recommended"];class j extends u{initialize(){this.updateBlueprint=l((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,s=e.target.dataset;n.updateInput(i,{[r=r||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const s=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}j.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class F extends e{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const r=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,i=t?o(t.startDate.toISOString()):o(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),s=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=s,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:a(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=a(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(a(this.pluginMainEl).off("apply.daterangepicker"),a(this.pluginMainEl).off("cancel.daterangepicker"),a(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}F.targets=["field","hiddenField","clearButton"],F.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const D=[[c,"refine/add-controller.js"],[h,"refine/criterion-form-controller.js"],[p,"refine/defaults-controller.js"],[m,"refine/delete-controller.js"],[f,"refine/filter-pills-controller.js"],[g,"refine/popup-controller.js"],[b,"refine/modal-controller.js"],[v,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[I,"refine/state-controller.js"],[C,"refine/stored-filter-controller.js"],[T,"refine/submit-form-controller.js"],[S,"refine/toggle-controller.js"],[V,"refine/turbo-stream-form-controller.js"],[E,"refine/turbo-stream-link-controller.js"],[P,"./refine/typeahead-list-controller.js"],[j,"refine/update-controller.js"],[F,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{c as AddController,h as CriterionFormController,F as DateController,p as DefaultsController,m as DeleteController,f as FilterPillsController,b as ModalController,g as PopupController,v as SearchFilterController,u as ServerRefreshController,I as StateController,C as StoredFilterController,T as SubmitForm,S as ToggleController,V as TurboStreamFormController,E as TurboStreamLinkController,P as TypeaheadListController,j as UpdateController,D as controllerDefinitions}; | ||
//# sourceMappingURL=refine-stimulus.esm.js.map |
@@ -1,2 +0,2 @@ | ||
var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("stimulus-use"),i=require("jquery-events-to-dom-events"),n=require("lodash"),l=require("moment"),o=require("jquery");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("daterangepicker");var a=s(l),u=s(o);function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class c extends e.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}refreshFromServer(e){void 0===e&&(e={});try{const r=this,{includeErrors:i}=e;r.state.startUpdate();const n=new t.FetchRequest("GET",r.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":r.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(r.state.blueprint),"refine_filters_builder[client_id]":r.state.clientIdValue,include_errors:!!i}});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class h extends c{criterion(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addCriterion(e.previousCriterionIdValue),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}group(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addGroup(),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{const e=this,r=new t.FetchRequest("GET",e.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":e.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(e){return e.ok})}catch(e){return Promise.reject(e)}}}h.values={previousCriterionId:Number};class p extends e.Controller{refresh(e){try{const e=this,r=document.getElementById(e.formIdValue),i=new FormData(r),n=new t.FetchRequest("GET",e.urlValue,{query:i,responseKind:"turbo-stream"});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}p.values={url:String,formId:String};class m extends e.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}m.values={criterionId:Number,input:Object};class f extends c{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}f.values={criterionId:Number};class g extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}g.values={submitUrl:String};class b extends e.Controller{connect(){r.useClickOutside(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}b.targets=["frame"],b.values={src:String,isOpen:{type:Boolean,default:!1}};class v extends e.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}v.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const C=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},y=(e,t,r)=>{var i;const n=null==r?void 0:r.component,l=(null==r?void 0:r.meta)||{clauses:[],options:{}},o=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=l;let u;u="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let d={clause:null==(i=s[0])?void 0:i.id,selected:u};return o.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let l;l="option-condition"===r?n[0]?[n[0].id]:[]:void 0,d[e.id]={clause:i[0].id,selected:l}}),{depth:t,type:"criterion",condition_id:e,input:d}};class w extends e.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(y(t.id,1,t)),C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r.find(e=>e.id==this.defaultConditionIdValue)||r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},y(i.id,1,i)),C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,l=i&&"or"===i.word||!i,o=n||!r,s=o&&l;r||i?t.splice(s&&n?e-1:s&&!r||o&&!l?e:e-1,2):this.blueprint=[],C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(y));const l=this.blueprint[e],o=y(t,i.depth,r);return!n.isEqual(l,o)&&(this.blueprint[e]=o,C(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],l=(r=r||"input").split(", ");l.length>1?n[l[0]][l[1]]={...n[l[0]][l[1]],...t}:n[r]={...n[r],...t},C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}w.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},w.targets=["loading"];class I extends e.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}I.targets=["blueprintField"],I.values={formId:String,stateDomId:String};class S extends e.Controller{submit(e){e.preventDefault(),this.element.requestSubmit()}}class T extends e.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}T.targets=["content"];class V extends e.Controller{submit(e){try{const r=this;e.preventDefault();const i=new t.FetchRequest(r.element.method||"POST",r.element.action,{responseKind:"turbo-stream",body:new FormData(r.element)});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class F extends e.Controller{visit(e){try{const r=this;e.preventDefault();const i=new t.FetchRequest(r.element.dataset.turboMethod||"GET",r.element.href,{responseKind:"turbo-stream"});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class E extends e.Controller{filter(e){const t=e.currentTarget.value.toLowerCase(),r=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,r.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===r.size}),this.categoryTargets.forEach(e=>{e.hidden=!r.has(e.innerHTML)})}}E.targets=["listItem","category","recommended"];class P extends c{initialize(){this.updateBlueprint=n.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,l=e.target.dataset;n.updateInput(i,{[r=r||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const l=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,l)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}P.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class j extends e.Controller{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const r=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,i=t?a.default(t.startDate.toISOString()):a.default(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),l=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=l,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:u.default(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=u.default(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(u.default(this.pluginMainEl).off("apply.daterangepicker"),u.default(this.pluginMainEl).off("cancel.daterangepicker"),u.default(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}j.targets=["field","hiddenField","clearButton"],j.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const x=[[h,"refine/add-controller.js"],[p,"refine/criterion-form-controller.js"],[m,"refine/defaults-controller.js"],[f,"refine/delete-controller.js"],[g,"refine/filter-pills-controller.js"],[b,"refine/popup-controller.js"],[v,"refine/search-filter-controller.js"],[c,"refine/server-refresh-controller.js"],[w,"refine/state-controller.js"],[I,"refine/stored-filter-controller.js"],[S,"refine/submit-form-controller.js"],[T,"refine/toggle-controller.js"],[V,"refine/turbo-stream-form-controller.js"],[F,"refine/turbo-stream-link-controller.js"],[E,"./refine/typeahead-list-controller.js"],[P,"refine/update-controller.js"],[j,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});exports.AddController=h,exports.CriterionFormController=p,exports.DateController=j,exports.DefaultsController=m,exports.DeleteController=f,exports.FilterPillsController=g,exports.PopupController=b,exports.SearchFilterController=v,exports.ServerRefreshController=c,exports.StateController=w,exports.StoredFilterController=I,exports.SubmitForm=S,exports.ToggleController=T,exports.TurboStreamFormController=V,exports.TurboStreamLinkController=F,exports.TypeaheadListController=E,exports.UpdateController=P,exports.controllerDefinitions=x; | ||
var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("stimulus-use"),i=require("jquery-events-to-dom-events"),n=require("lodash"),l=require("moment"),o=require("jquery");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("daterangepicker");var a=s(l),u=s(o);function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class c extends e.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}refreshFromServer(e){void 0===e&&(e={});try{const r=this,{includeErrors:i}=e;r.state.startUpdate();const n=new t.FetchRequest("GET",r.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":r.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(r.state.blueprint),"refine_filters_builder[client_id]":r.state.clientIdValue,include_errors:!!i}});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class h extends c{criterion(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addCriterion(e.previousCriterionIdValue),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}group(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addGroup(),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{const e=this,r=new t.FetchRequest("GET",e.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":e.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(r.perform()).then(function(e){return e.ok})}catch(e){return Promise.reject(e)}}}h.values={previousCriterionId:Number};class p extends e.Controller{refresh(e){try{const e=this,r=document.getElementById(e.formIdValue),i=new FormData(r),n=new t.FetchRequest("GET",e.urlValue,{query:i,responseKind:"turbo-stream"});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}p.values={url:String,formId:String};class m extends e.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}m.values={criterionId:Number,input:Object};class f extends c{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}f.values={criterionId:Number};class g extends e.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}g.values={submitUrl:String};class b extends e.Controller{connect(){r.useClickOutside(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}b.targets=["frame"],b.values={src:String,isOpen:{type:Boolean,default:!1}};class v extends e.Controller{connect(){console.log("Connecting modal controller"),r.useClickOutside(this)}disconnect(){}open(e){console.log("Opening modal!!!",this.srcValue),e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}close(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.close(e)}}v.targets=["frame"],v.values={src:String,isOpen:{type:Boolean,default:!1}};class C extends e.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:r}=e.stateController,i=new t.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(r),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}C.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const y=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},w=(e,t,r)=>{var i;const n=null==r?void 0:r.component,l=(null==r?void 0:r.meta)||{clauses:[],options:{}},o=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=l;let u;u="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let d={clause:null==(i=s[0])?void 0:i.id,selected:u};return o.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let l;l="option-condition"===r?n[0]?[n[0].id]:[]:void 0,d[e.id]={clause:i[0].id,selected:l}}),{depth:t,type:"criterion",condition_id:e,input:d}};class I extends e.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=i.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){i.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(w(t.id,1,t)),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r.find(e=>e.id==this.defaultConditionIdValue)||r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},w(i.id,1,i)),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,l=i&&"or"===i.word||!i,o=n||!r,s=o&&l;r||i?t.splice(s&&n?e-1:s&&!r||o&&!l?e:e-1,2):this.blueprint=[],y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(w));const l=this.blueprint[e],o=w(t,i.depth,r);return!n.isEqual(l,o)&&(this.blueprint[e]=o,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],l=(r=r||"input").split(", ");l.length>1?n[l[0]][l[1]]={...n[l[0]][l[1]],...t}:n[r]={...n[r],...t},y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}I.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},I.targets=["loading"];class S extends e.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}S.targets=["blueprintField"],S.values={formId:String,stateDomId:String};class T extends e.Controller{submit(e){e.preventDefault(),this.element.requestSubmit()}}class V extends e.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}V.targets=["content"];class F extends e.Controller{submit(e){try{const r=this;e.preventDefault();const i=new t.FetchRequest(r.element.method||"POST",r.element.action,{responseKind:"turbo-stream",body:new FormData(r.element)});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class E extends e.Controller{visit(e){try{const r=this;e.preventDefault();const i=new t.FetchRequest(r.element.dataset.turboMethod||"GET",r.element.href,{responseKind:"turbo-stream"});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class P extends e.Controller{filter(e){const t=e.currentTarget.value.toLowerCase(),r=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,r.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===r.size}),this.categoryTargets.forEach(e=>{e.hidden=!r.has(e.innerHTML)})}}P.targets=["listItem","category","recommended"];class j extends c{initialize(){this.updateBlueprint=n.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,l=e.target.dataset;n.updateInput(i,{[r=r||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const l=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,l)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}j.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class x extends e.Controller{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const r=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,i=t?a.default(t.startDate.toISOString()):a.default(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),l=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=l,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:u.default(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=u.default(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(u.default(this.pluginMainEl).off("apply.daterangepicker"),u.default(this.pluginMainEl).off("cancel.daterangepicker"),u.default(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}x.targets=["field","hiddenField","clearButton"],x.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const D=[[h,"refine/add-controller.js"],[p,"refine/criterion-form-controller.js"],[m,"refine/defaults-controller.js"],[f,"refine/delete-controller.js"],[g,"refine/filter-pills-controller.js"],[b,"refine/popup-controller.js"],[v,"refine/modal-controller.js"],[C,"refine/search-filter-controller.js"],[c,"refine/server-refresh-controller.js"],[I,"refine/state-controller.js"],[S,"refine/stored-filter-controller.js"],[T,"refine/submit-form-controller.js"],[V,"refine/toggle-controller.js"],[F,"refine/turbo-stream-form-controller.js"],[E,"refine/turbo-stream-link-controller.js"],[P,"./refine/typeahead-list-controller.js"],[j,"refine/update-controller.js"],[x,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});exports.AddController=h,exports.CriterionFormController=p,exports.DateController=x,exports.DefaultsController=m,exports.DeleteController=f,exports.FilterPillsController=g,exports.ModalController=v,exports.PopupController=b,exports.SearchFilterController=C,exports.ServerRefreshController=c,exports.StateController=I,exports.StoredFilterController=S,exports.SubmitForm=T,exports.ToggleController=V,exports.TurboStreamFormController=F,exports.TurboStreamLinkController=E,exports.TypeaheadListController=P,exports.UpdateController=j,exports.controllerDefinitions=D; | ||
//# sourceMappingURL=refine-stimulus.js.map |
@@ -1,2 +0,2 @@ | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{useClickOutside as i}from"stimulus-use";import{delegate as r,abnegate as n}from"jquery-events-to-dom-events";import{isEqual as s,debounce as l}from"lodash";import a from"moment";import o from"jquery";import"daterangepicker";function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}async refreshFromServer(e={}){const{includeErrors:i}=e;this.state.startUpdate();const r=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":this.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"refine_filters_builder[client_id]":this.state.clientIdValue,include_errors:!!i}});await r.perform()}}class c extends u{async criterion(){const e=await this.validateBlueprint();e&&this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer({includeErrors:!e})}async group(){const e=await this.validateBlueprint();e&&this.state.addGroup(),this.refreshFromServer({includeErrors:!e})}async validateBlueprint(e){const i=new t("GET",this.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":this.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"refine_filters_builder[client_id]":this.state.clientIdValue}});return(await i.perform()).ok}}c.values={previousCriterionId:Number};class h extends e{async refresh(e){const i=document.getElementById(this.formIdValue),r=new FormData(i),n=new t("GET",this.urlValue,{query:r,responseKind:"turbo-stream"});await n.perform()}}h.values={url:String,formId:String};class p extends e{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}p.values={criterionId:Number,input:Object};class m extends u{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}function f(){return f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e},f.apply(this,arguments)}m.values={criterionId:Number};class g extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var i=parseInt(t);this.stateController.deleteCriterion(i),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams(f({},Object.fromEntries(this.existingParams),Object.fromEntries(t))).toString(),r=`${window.location.pathname}?${i}`;history.pushState({},document.title,r),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}g.values={submitUrl:String};class b extends e{connect(){i(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}b.targets=["frame"],b.values={src:String,isOpen:{type:Boolean,default:!1}};class v extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults({detail:{url:e}}){console.log("filter submit success"),window.Turbo?window.Turbo.visit(e):window.location.href=e}}v.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}e.prototype=window.Event.prototype,window.CustomEvent=e}();const w=(e,{blueprint:t,formId:i})=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:i}});e.dispatchEvent(r)},y=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},l=(null==i?void 0:i.refinements)||[],{clauses:a,options:o}=s;let d;d="option-condition"===n?o[0]?[o[0].id]:[]:void 0;let u={clause:null==(r=a[0])?void 0:r.id,selected:d};return l.forEach(e=>{const{meta:t,component:i}=e,{clauses:r,options:n}=t;let s;s="option-condition"===i?n[0]?[n[0].id]:[]:void 0,u[e.id]={clause:r[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:u}};class I extends e{connect(){this.element.refineStateController=this,this.changeDelegate=r("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){n("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(y(t.id,1,t)),w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:i}=this,r=i.find(e=>e.id==this.defaultConditionIdValue)||i[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},y(r.id,1,r)),w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],r=t[e+1],n=i&&"or"===i.word,s=r&&"or"===r.word||!r,l=n||!i,a=l&&s;i||r?t.splice(a&&n?e-1:a&&!i||l&&!s?e:e-1,2):this.blueprint=[],w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,i){const r=this.blueprint[e];if("criterion"!==r.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(y)}`);const n=this.blueprint[e],l=y(t,r.depth,i);return!s(n,l)&&(this.blueprint[e]=l,w(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,i){const{blueprint:r}=this,n=r[e],s=(i=i||"input").split(", ");s.length>1?n[s[0]][s[1]]=f({},n[s[0]][s[1]],t):n[i]=f({},n[i],t),w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}I.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},I.targets=["loading"];class C extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:i}=t;this.blueprintFieldTarget.value=JSON.stringify(i),console.log("update blueprint",this.blueprintFieldTarget.value)}}C.targets=["blueprintField"],C.values={formId:String,stateDomId:String};class S extends e{submit(e){e.preventDefault(),this.element.requestSubmit()}}class T extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}T.targets=["content"];class V extends e{async submit(e){e.preventDefault();const i=new t(this.element.method||"POST",this.element.action,{responseKind:"turbo-stream",body:new FormData(this.element)});await i.perform()}}class E extends e{async visit(e){e.preventDefault();const i=new t(this.element.dataset.turboMethod||"GET",this.element.href,{responseKind:"turbo-stream"});await i.perform()}}class F extends e{filter(e){const t=e.currentTarget.value.toLowerCase(),i=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,i.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===i.size}),this.categoryTargets.forEach(e=>{e.hidden=!i.has(e.innerHTML)})}}F.targets=["listItem","category","recommended"];class _ extends u{initialize(){this.updateBlueprint=l((e,t,i)=>{this.value(e,t,i)},500)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,i=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,i,"selected")}value(e,t,i){const{criterionIdValue:r,state:n}=this,s=e.target.dataset;n.updateInput(r,{[i=i||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:i}=this,r=e.target;let n=r.value;n||(n=r.querySelector("select").value);const s=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}_.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class D extends e{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const i=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,r=t?a(t.startDate.toISOString()):a(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=r.format(i),s=this.includeTimeValue?r.toISOString(!0):r.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=s,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:o(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=o(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(o(this.pluginMainEl).off("apply.daterangepicker"),o(this.pluginMainEl).off("cancel.daterangepicker"),o(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}D.targets=["field","hiddenField","clearButton"],D.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const j=[[c,"refine/add-controller.js"],[h,"refine/criterion-form-controller.js"],[p,"refine/defaults-controller.js"],[m,"refine/delete-controller.js"],[g,"refine/filter-pills-controller.js"],[b,"refine/popup-controller.js"],[v,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[I,"refine/state-controller.js"],[C,"refine/stored-filter-controller.js"],[S,"refine/submit-form-controller.js"],[T,"refine/toggle-controller.js"],[V,"refine/turbo-stream-form-controller.js"],[E,"refine/turbo-stream-link-controller.js"],[F,"./refine/typeahead-list-controller.js"],[_,"refine/update-controller.js"],[D,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{c as AddController,h as CriterionFormController,D as DateController,p as DefaultsController,m as DeleteController,g as FilterPillsController,b as PopupController,v as SearchFilterController,u as ServerRefreshController,I as StateController,C as StoredFilterController,S as SubmitForm,T as ToggleController,V as TurboStreamFormController,E as TurboStreamLinkController,F as TypeaheadListController,_ as UpdateController,j as controllerDefinitions}; | ||
import{Controller as e}from"@hotwired/stimulus";import{FetchRequest as t}from"@rails/request.js";import{useClickOutside as i}from"stimulus-use";import{delegate as r,abnegate as n}from"jquery-events-to-dom-events";import{isEqual as s,debounce as l}from"lodash";import a from"moment";import o from"jquery";import"daterangepicker";function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u extends e{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}async refreshFromServer(e={}){const{includeErrors:i}=e;this.state.startUpdate();const r=new t("GET",this.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":this.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"refine_filters_builder[client_id]":this.state.clientIdValue,include_errors:!!i}});await r.perform()}}class c extends u{async criterion(){const e=await this.validateBlueprint();e&&this.state.addCriterion(this.previousCriterionIdValue),this.refreshFromServer({includeErrors:!e})}async group(){const e=await this.validateBlueprint();e&&this.state.addGroup(),this.refreshFromServer({includeErrors:!e})}async validateBlueprint(e){const i=new t("GET",this.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":this.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(this.state.blueprint),"refine_filters_builder[client_id]":this.state.clientIdValue}});return(await i.perform()).ok}}c.values={previousCriterionId:Number};class h extends e{async refresh(e){const i=document.getElementById(this.formIdValue),r=new FormData(i),n=new t("GET",this.urlValue,{query:r,responseKind:"turbo-stream"});await n.perform()}}h.values={url:String,formId:String};class p extends e{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}p.values={criterionId:Number,input:Object};class m extends u{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}function f(){return f=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var i=arguments[t];for(var r in i)Object.prototype.hasOwnProperty.call(i,r)&&(e[r]=i[r])}return e},f.apply(this,arguments)}m.values={criterionId:Number};class g extends e{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var i=parseInt(t);this.stateController.deleteCriterion(i),this.reloadPage()}async reloadPage(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const i=new URLSearchParams(f({},Object.fromEntries(this.existingParams),Object.fromEntries(t))).toString(),r=`${window.location.pathname}?${i}`;history.pushState({},document.title,r),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}g.values={submitUrl:String};class b extends e{connect(){i(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}b.targets=["frame"],b.values={src:String,isOpen:{type:Boolean,default:!1}};class v extends e{connect(){console.log("Connecting modal controller"),i(this)}disconnect(){}open(e){console.log("Opening modal!!!",this.srcValue),e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}close(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.close(e)}}v.targets=["frame"],v.values={src:String,isOpen:{type:Boolean,default:!1}};class w extends e{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}async submitFilter(){const{blueprint:e}=this.stateController,i=new t("POST",this.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:this.stateController.filterName,blueprint_json:JSON.stringify(e),client_id:this.stateController.clientIdValue}})});await i.perform()}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults({detail:{url:e}}){console.log("filter submit success"),window.Turbo?window.Turbo.visit(e):window.location.href=e}}w.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var i=document.createEvent("CustomEvent");return i.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),i}e.prototype=window.Event.prototype,window.CustomEvent=e}();const y=(e,{blueprint:t,formId:i})=>{const r=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:t,formId:i}});e.dispatchEvent(r)},I=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},l=(null==i?void 0:i.refinements)||[],{clauses:a,options:o}=s;let d;d="option-condition"===n?o[0]?[o[0].id]:[]:void 0;let u={clause:null==(r=a[0])?void 0:r.id,selected:d};return l.forEach(e=>{const{meta:t,component:i}=e,{clauses:r,options:n}=t;let s;s="option-condition"===i?n[0]?[n[0].id]:[]:void 0,u[e.id]={clause:r[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:u}};class C extends e{connect(){this.element.refineStateController=this,this.changeDelegate=r("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){n("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var i;this.blueprint.length>0&&this.blueprint.push({depth:i=void 0===i?0:i,type:"conjunction",word:"or"}),this.blueprint.push(I(t.id,1,t)),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:i}=this,r=i.find(e=>e.id==this.defaultConditionIdValue)||i[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},I(r.id,1,r)),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,i=t[e-1],r=t[e+1],n=i&&"or"===i.word,s=r&&"or"===r.word||!r,l=n||!i,a=l&&s;i||r?t.splice(a&&n?e-1:a&&!i||l&&!s?e:e-1,2):this.blueprint=[],y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,i){const r=this.blueprint[e];if("criterion"!==r.type)throw new Error(`You can't call updateConditionId on a non-criterion type. Trying to update ${JSON.stringify(I)}`);const n=this.blueprint[e],l=I(t,r.depth,i);return!s(n,l)&&(this.blueprint[e]=l,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,i){const{blueprint:r}=this,n=r[e],s=(i=i||"input").split(", ");s.length>1?n[s[0]][s[1]]=f({},n[s[0]][s[1]],t):n[i]=f({},n[i],t),y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}C.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},C.targets=["loading"];class T extends e{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:i}=t;this.blueprintFieldTarget.value=JSON.stringify(i),console.log("update blueprint",this.blueprintFieldTarget.value)}}T.targets=["blueprintField"],T.values={formId:String,stateDomId:String};class S extends e{submit(e){e.preventDefault(),this.element.requestSubmit()}}class V extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}V.targets=["content"];class E extends e{async submit(e){e.preventDefault();const i=new t(this.element.method||"POST",this.element.action,{responseKind:"turbo-stream",body:new FormData(this.element)});await i.perform()}}class F extends e{async visit(e){e.preventDefault();const i=new t(this.element.dataset.turboMethod||"GET",this.element.href,{responseKind:"turbo-stream"});await i.perform()}}class D extends e{filter(e){const t=e.currentTarget.value.toLowerCase(),i=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,i.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===i.size}),this.categoryTargets.forEach(e=>{e.hidden=!i.has(e.innerHTML)})}}D.targets=["listItem","category","recommended"];class O extends u{initialize(){this.updateBlueprint=l((e,t,i)=>{this.value(e,t,i)},500)}refinedFilter(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:i}=this;i.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,i=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,i,"selected")}value(e,t,i){const{criterionIdValue:r,state:n}=this,s=e.target.dataset;n.updateInput(r,{[i=i||s.inputKey||"value"]:t=t||e.target.value},s.inputId)}condition(e){const{criterionIdValue:t,state:i}=this,r=e.target;let n=r.value;n||(n=r.querySelector("select").value);const s=this.state.conditionConfigFor(n);i.replaceCriterion(t,n,s)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}O.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class _ extends e{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const i=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,r=t?a(t.startDate.toISOString()):a(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=r.format(i),s=this.includeTimeValue?r.toISOString(!0):r.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=s,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:o(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=o(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(o(this.pluginMainEl).off("apply.daterangepicker"),o(this.pluginMainEl).off("cancel.daterangepicker"),o(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}_.targets=["field","hiddenField","clearButton"],_.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const j=[[c,"refine/add-controller.js"],[h,"refine/criterion-form-controller.js"],[p,"refine/defaults-controller.js"],[m,"refine/delete-controller.js"],[g,"refine/filter-pills-controller.js"],[b,"refine/popup-controller.js"],[v,"refine/modal-controller.js"],[w,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[C,"refine/state-controller.js"],[T,"refine/stored-filter-controller.js"],[S,"refine/submit-form-controller.js"],[V,"refine/toggle-controller.js"],[E,"refine/turbo-stream-form-controller.js"],[F,"refine/turbo-stream-link-controller.js"],[D,"./refine/typeahead-list-controller.js"],[O,"refine/update-controller.js"],[_,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{c as AddController,h as CriterionFormController,_ as DateController,p as DefaultsController,m as DeleteController,g as FilterPillsController,v as ModalController,b as PopupController,w as SearchFilterController,u as ServerRefreshController,C as StateController,T as StoredFilterController,S as SubmitForm,V as ToggleController,E as TurboStreamFormController,F as TurboStreamLinkController,D as TypeaheadListController,O as UpdateController,j as controllerDefinitions}; | ||
//# sourceMappingURL=refine-stimulus.modern.js.map |
@@ -1,2 +0,2 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("@rails/request.js"),require("stimulus-use"),require("jquery-events-to-dom-events"),require("lodash"),require("moment"),require("jquery"),require("daterangepicker")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","@rails/request.js","stimulus-use","jquery-events-to-dom-events","lodash","moment","jquery","daterangepicker"],t):t((e||self).refineStimulus={},e.Stimulus,e.request_js,e.stimulusUse,e.jqueryEventsToDomEvents,e.lodash,e.moment,e.jquery)}(this,function(e,t,r,i,n,l,o,s){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(o),d=a(s);function c(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class h extends t.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}refreshFromServer(e){void 0===e&&(e={});try{const t=this,{includeErrors:i}=e;t.state.startUpdate();const n=new r.FetchRequest("GET",t.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":t.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(t.state.blueprint),"refine_filters_builder[client_id]":t.state.clientIdValue,include_errors:!!i}});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class p extends h{criterion(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addCriterion(e.previousCriterionIdValue),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}group(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addGroup(),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{const e=this,t=new r.FetchRequest("GET",e.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":e.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(t.perform()).then(function(e){return e.ok})}catch(e){return Promise.reject(e)}}}p.values={previousCriterionId:Number};class m extends t.Controller{refresh(e){try{const e=this,t=document.getElementById(e.formIdValue),i=new FormData(t),n=new r.FetchRequest("GET",e.urlValue,{query:i,responseKind:"turbo-stream"});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}m.values={url:String,formId:String};class f extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}f.values={criterionId:Number,input:Object};class g extends h{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}g.values={criterionId:Number};class b extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}b.values={submitUrl:String};class v extends t.Controller{connect(){i.useClickOutside(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}v.targets=["frame"],v.values={src:String,isOpen:{type:Boolean,default:!1}};class y extends t.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}y.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const C=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},w=(e,t,r)=>{var i;const n=null==r?void 0:r.component,l=(null==r?void 0:r.meta)||{clauses:[],options:{}},o=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=l;let u;u="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let d={clause:null==(i=s[0])?void 0:i.id,selected:u};return o.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let l;l="option-condition"===r?n[0]?[n[0].id]:[]:void 0,d[e.id]={clause:i[0].id,selected:l}}),{depth:t,type:"criterion",condition_id:e,input:d}};class I extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=n.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){n.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(w(t.id,1,t)),C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r.find(e=>e.id==this.defaultConditionIdValue)||r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},w(i.id,1,i)),C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,l=i&&"or"===i.word||!i,o=n||!r,s=o&&l;r||i?t.splice(s&&n?e-1:s&&!r||o&&!l?e:e-1,2):this.blueprint=[],C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(w));const n=this.blueprint[e],o=w(t,i.depth,r);return!l.isEqual(n,o)&&(this.blueprint[e]=o,C(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],l=(r=r||"input").split(", ");l.length>1?n[l[0]][l[1]]={...n[l[0]][l[1]],...t}:n[r]={...n[r],...t},C(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}I.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},I.targets=["loading"];class S extends t.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}S.targets=["blueprintField"],S.values={formId:String,stateDomId:String};class T extends t.Controller{submit(e){e.preventDefault(),this.element.requestSubmit()}}class V extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}V.targets=["content"];class F extends t.Controller{submit(e){try{const t=this;e.preventDefault();const i=new r.FetchRequest(t.element.method||"POST",t.element.action,{responseKind:"turbo-stream",body:new FormData(t.element)});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class j extends t.Controller{visit(e){try{const t=this;e.preventDefault();const i=new r.FetchRequest(t.element.dataset.turboMethod||"GET",t.element.href,{responseKind:"turbo-stream"});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class E extends t.Controller{filter(e){const t=e.currentTarget.value.toLowerCase(),r=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,r.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===r.size}),this.categoryTargets.forEach(e=>{e.hidden=!r.has(e.innerHTML)})}}E.targets=["listItem","category","recommended"];class P extends h{initialize(){this.updateBlueprint=l.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,l=e.target.dataset;n.updateInput(i,{[r=r||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const l=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,l)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}P.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class D extends t.Controller{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const r=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,i=t?u.default(t.startDate.toISOString()):u.default(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),l=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=l,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:d.default(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=d.default(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(d.default(this.pluginMainEl).off("apply.daterangepicker"),d.default(this.pluginMainEl).off("cancel.daterangepicker"),d.default(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}D.targets=["field","hiddenField","clearButton"],D.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const _=[[p,"refine/add-controller.js"],[m,"refine/criterion-form-controller.js"],[f,"refine/defaults-controller.js"],[g,"refine/delete-controller.js"],[b,"refine/filter-pills-controller.js"],[v,"refine/popup-controller.js"],[y,"refine/search-filter-controller.js"],[h,"refine/server-refresh-controller.js"],[I,"refine/state-controller.js"],[S,"refine/stored-filter-controller.js"],[T,"refine/submit-form-controller.js"],[V,"refine/toggle-controller.js"],[F,"refine/turbo-stream-form-controller.js"],[j,"refine/turbo-stream-link-controller.js"],[E,"./refine/typeahead-list-controller.js"],[P,"refine/update-controller.js"],[D,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:c(e[1]),controllerConstructor:t}});e.AddController=p,e.CriterionFormController=m,e.DateController=D,e.DefaultsController=f,e.DeleteController=g,e.FilterPillsController=b,e.PopupController=v,e.SearchFilterController=y,e.ServerRefreshController=h,e.StateController=I,e.StoredFilterController=S,e.SubmitForm=T,e.ToggleController=V,e.TurboStreamFormController=F,e.TurboStreamLinkController=j,e.TypeaheadListController=E,e.UpdateController=P,e.controllerDefinitions=_}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("@hotwired/stimulus"),require("@rails/request.js"),require("stimulus-use"),require("jquery-events-to-dom-events"),require("lodash"),require("moment"),require("jquery"),require("daterangepicker")):"function"==typeof define&&define.amd?define(["exports","@hotwired/stimulus","@rails/request.js","stimulus-use","jquery-events-to-dom-events","lodash","moment","jquery","daterangepicker"],t):t((e||self).refineStimulus={},e.Stimulus,e.request_js,e.stimulusUse,e.jqueryEventsToDomEvents,e.lodash,e.moment,e.jquery)}(this,function(e,t,r,i,n,l,s,o){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var u=a(s),d=a(o);function c(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class h extends t.Controller{connect(){this.state.finishUpdate()}get state(){let e=this.element;for(;e!==document.body;){if(e.matches('[data-controller~="refine--state"]'))return this.application.getControllerForElementAndIdentifier(e,"refine--state");e=e.parentNode}return null}refreshFromServer(e){void 0===e&&(e={});try{const t=this,{includeErrors:i}=e;t.state.startUpdate();const n=new r.FetchRequest("GET",t.state.refreshUrlValue,{responseKind:"turbo-stream",query:{"refine_filters_builder[filter_class]":t.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(t.state.blueprint),"refine_filters_builder[client_id]":t.state.clientIdValue,include_errors:!!i}});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class p extends h{criterion(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addCriterion(e.previousCriterionIdValue),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}group(){try{const e=this;return Promise.resolve(e.validateBlueprint()).then(function(t){t&&e.state.addGroup(),e.refreshFromServer({includeErrors:!t})})}catch(e){return Promise.reject(e)}}validateBlueprint(e){try{const e=this,t=new r.FetchRequest("GET",e.state.validateBlueprintUrlValue,{query:{"refine_filters_builder[filter_class]":e.state.filterName,"refine_filters_builder[blueprint_json]":JSON.stringify(e.state.blueprint),"refine_filters_builder[client_id]":e.state.clientIdValue}});return Promise.resolve(t.perform()).then(function(e){return e.ok})}catch(e){return Promise.reject(e)}}}p.values={previousCriterionId:Number};class m extends t.Controller{refresh(e){try{const e=this,t=document.getElementById(e.formIdValue),i=new FormData(t),n=new r.FetchRequest("GET",e.urlValue,{query:i,responseKind:"turbo-stream"});return Promise.resolve(n.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}m.values={url:String,formId:String};class f extends t.Controller{connect(){this.state=this.getStateController(),this.state.updateInput(this.criterionIdValue,this.inputValue)}getStateController(){let e=this.element;for(;e!==document.body;){const t=this.application.getControllerForElementAndIdentifier(e,"refine--state");if(t)return t;e=e.parentNode}return null}}f.values={criterionId:Number,input:Object};class g extends h{criterion(){const{state:e,criterionIdValue:t}=this;e.deleteCriterion(t),this.refreshFromServer()}}g.values={criterionId:Number};class b extends t.Controller{connect(){const e=new URLSearchParams(window.location.search);this.existingParams=e,this.existingParams.delete("stable_id")}delete(e){const{criterionId:t}=e.currentTarget.dataset;var r=parseInt(t);this.stateController.deleteCriterion(r),this.reloadPage()}reloadPage(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}redirectToStableId(e){const t=new URLSearchParams;e&&t.append("stable_id",e);const r=new URLSearchParams({...Object.fromEntries(this.existingParams),...Object.fromEntries(t)}).toString(),i=window.location.pathname+"?"+r;history.pushState({},document.title,i),window.location.reload()}get stateController(){return this.element.refineStateController}get stabilizeFilterController(){return this.element.stabilizeFilterController}}b.values={submitUrl:String};class v extends t.Controller{connect(){i.useClickOutside(this),this.boundHandleKeyUp=this.handleKeyUp.bind(this),document.addEventListener("keyup",this.boundHandleKeyUp)}disconnect(){document.removeEventListener("keyup",this.boundHandleKeyUp)}show(e){e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}hide(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.hide(e)}handleKeyUp(e){"Escape"!==e.key&&"Esc"!==e.key||this.hide(e)}}v.targets=["frame"],v.values={src:String,isOpen:{type:Boolean,default:!1}};class y extends t.Controller{connect(){console.log("Connecting modal controller"),i.useClickOutside(this)}disconnect(){}open(e){console.log("Opening modal!!!",this.srcValue),e.preventDefault(),this.frameTarget.src=this.srcValue,this.isOpenValue=!0}close(e){this.isOpenValue&&(null==e||e.preventDefault(),this.frameTarget.innerHTML="",this.isOpenValue=!1)}clickOutside(e){this.close(e)}}y.targets=["frame"],y.values={src:String,isOpen:{type:Boolean,default:!1}};class C extends t.Controller{search(e){e.preventDefault(),this.submitFilter(),document.activeElement.blur()}submitFilter(){try{const e=this,{blueprint:t}=e.stateController,i=new r.FetchRequest("POST",e.submitUrlValue,{responseKind:"turbo-stream",body:JSON.stringify({refine_filters_builder:{filter_class:e.stateController.filterName,blueprint_json:JSON.stringify(t),client_id:e.stateController.clientIdValue}})});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}get stateController(){return this.element.querySelector('[data-controller~="refine--state"]').refineStateController}loadResults(e){let{detail:{url:t}}=e;console.log("filter submit success"),window.Turbo?window.Turbo.visit(t):window.location.href=t}}C.values={submitUrl:String},function(){if("function"==typeof window.CustomEvent)return!1;function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var r=document.createEvent("CustomEvent");return r.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),r}e.prototype=window.Event.prototype,window.CustomEvent=e}();const w=(e,t)=>{let{blueprint:r,formId:i}=t;const n=new CustomEvent("blueprint-updated",{bubbles:!0,cancelable:!0,detail:{blueprint:r,formId:i}});e.dispatchEvent(n)},I=(e,t,r)=>{var i;const n=null==r?void 0:r.component,l=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:o,options:a}=l;let u;u="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let d={clause:null==(i=o[0])?void 0:i.id,selected:u};return s.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let l;l="option-condition"===r?n[0]?[n[0].id]:[]:void 0,d[e.id]={clause:i[0].id,selected:l}}),{depth:t,type:"criterion",condition_id:e,input:d}};class S extends t.Controller{connect(){this.element.refineStateController=this,this.changeDelegate=n.delegate("change",["event","picker"]),this.blueprint=this.blueprintValue,this.conditions=this.conditionsValue,this.filterName=this.classNameValue,this.conditionsLookup=this.conditions.reduce((e,t)=>(e[t.id]=t,e),{}),this.loadingTimeout=null,w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}disconnect(){n.abnegate("change",this.changeDelegate)}startUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTimeout=window.setTimeout(()=>{this.loadingTarget.classList.remove("hidden")},1e3)}finishUpdate(){this.loadingTimeout&&window.clearTimeout(this.loadingTimeout),this.loadingTarget.classList.add("hidden")}conditionConfigFor(e){return this.conditionsLookup[e]}addGroup(){const{conditions:e}=this,t=e.find(e=>e.id==this.defaultConditionIdValue)||e[0];var r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(I(t.id,1,t)),w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}addCriterion(e){const{blueprint:t,conditions:r}=this,i=r.find(e=>e.id==this.defaultConditionIdValue)||r[0];var n;t.splice(e+1,0,{depth:n=void 0===n?1:n,type:"conjunction",word:"and"},I(i.id,1,i)),w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}deleteCriterion(e){const{blueprint:t}=this,r=t[e-1],i=t[e+1],n=r&&"or"===r.word,l=i&&"or"===i.word||!i,s=n||!r,o=s&&l;r||i?t.splice(o&&n?e-1:o&&!r||s&&!l?e:e-1,2):this.blueprint=[],w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}replaceCriterion(e,t,r){const i=this.blueprint[e];if("criterion"!==i.type)throw new Error("You can't call updateConditionId on a non-criterion type. Trying to update "+JSON.stringify(I));const n=this.blueprint[e],s=I(t,i.depth,r);return!l.isEqual(n,s)&&(this.blueprint[e]=s,w(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],l=(r=r||"input").split(", ");l.length>1?n[l[0]][l[1]]={...n[l[0]][l[1]],...t}:n[r]={...n[r],...t},w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}S.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},S.targets=["loading"];class T extends t.Controller{connect(){const e=document.getElementById(this.stateDomIdValue).refineStateController;this.blueprintFieldTarget.value=JSON.stringify(e.blueprint),console.log("connect",this.blueprintFieldTarget.value)}updateBlueprintField(e){if(e.detail.formId!=this.formIdValue)return null;const{detail:t}=e,{blueprint:r}=t;this.blueprintFieldTarget.value=JSON.stringify(r),console.log("update blueprint",this.blueprintFieldTarget.value)}}T.targets=["blueprintField"],T.values={formId:String,stateDomId:String};class V extends t.Controller{submit(e){e.preventDefault(),this.element.requestSubmit()}}class F extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}F.targets=["content"];class j extends t.Controller{submit(e){try{const t=this;e.preventDefault();const i=new r.FetchRequest(t.element.method||"POST",t.element.action,{responseKind:"turbo-stream",body:new FormData(t.element)});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class E extends t.Controller{visit(e){try{const t=this;e.preventDefault();const i=new r.FetchRequest(t.element.dataset.turboMethod||"GET",t.element.href,{responseKind:"turbo-stream"});return Promise.resolve(i.perform()).then(function(){})}catch(e){return Promise.reject(e)}}}class P extends t.Controller{filter(e){const t=e.currentTarget.value.toLowerCase(),r=new Set;this.listItemTargets.forEach(e=>{e.dataset.listItemValue.toLowerCase().includes(t)?(e.hidden=!1,r.add(e.dataset.category)):e.hidden=!0}),this.recommendedTargets.forEach(e=>{e.hidden=""!==t&&0===r.size}),this.categoryTargets.forEach(e=>{e.hidden=!r.has(e.innerHTML)})}}P.targets=["listItem","category","recommended"];class D extends h{initialize(){this.updateBlueprint=l.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,l=e.target.dataset;n.updateInput(i,{[r=r||l.inputKey||"value"]:t=t||e.target.value},l.inputId)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const l=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,l)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}D.values={criterionId:Number},require("daterangepicker/daterangepicker.css");class _ extends t.Controller{connect(){this.initPluginInstance()}disconnect(){this.teardownPluginInstance()}clearDate(e){e.preventDefault(),window.$(this.fieldTarget).val(""),this.dispatch("value-cleared")}applyDateToField(e,t){const r=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,i=t?u.default(t.startDate.toISOString()):u.default(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),l=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=l,window.$(this.fieldTarget).trigger("change",t),this.hiddenFieldTarget.dispatchEvent(new Event("change",{detail:t,bubbles:!0}))}initPluginInstance(){const e=this.pickerLocaleValue,t=this.isAmPmValue;e.format=this.includeTimeValue?this.timeFormatValue:this.dateFormatValue,window.$(this.fieldTarget).daterangepicker({singleDatePicker:!0,timePicker:this.includeTimeValue,timePickerIncrement:5,autoUpdateInput:!1,autoApply:!0,minDate:!!this.futureOnlyValue&&new Date,locale:e,parentEl:d.default(this.element),drops:this.dropsValue?this.dropsValue:"down",timePicker24Hour:!t}),window.$(this.fieldTarget).on("apply.daterangepicker",this.applyDateToField.bind(this)),window.$(this.fieldTarget).on("cancel.daterangepicker",this.clearDate.bind(this)),window.$(this.fieldTarget).on("showCalendar.daterangepicker",this.showCalendar.bind(this)),this.pluginMainEl=this.fieldTarget,this.plugin=d.default(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(d.default(this.pluginMainEl).off("apply.daterangepicker"),d.default(this.pluginMainEl).off("cancel.daterangepicker"),d.default(this.pluginMainEl).off("showCalendar.daterangepicker"),this.plugin.remove())}showCalendar(){this.dispatch("show-calendar")}}_.targets=["field","hiddenField","clearButton"],_.values={includeTime:Boolean,futureOnly:Boolean,drops:String,inline:Boolean,dateFormat:String,timeFormat:String,isAmPm:Boolean,locale:{type:String,default:"en"},datetimeFormat:{type:String,default:"MM/DD/YYYY h:mm A"},pickerLocale:{type:Object,default:{}}};const O=[[p,"refine/add-controller.js"],[m,"refine/criterion-form-controller.js"],[f,"refine/defaults-controller.js"],[g,"refine/delete-controller.js"],[b,"refine/filter-pills-controller.js"],[v,"refine/popup-controller.js"],[y,"refine/modal-controller.js"],[C,"refine/search-filter-controller.js"],[h,"refine/server-refresh-controller.js"],[S,"refine/state-controller.js"],[T,"refine/stored-filter-controller.js"],[V,"refine/submit-form-controller.js"],[F,"refine/toggle-controller.js"],[j,"refine/turbo-stream-form-controller.js"],[E,"refine/turbo-stream-link-controller.js"],[P,"./refine/typeahead-list-controller.js"],[D,"refine/update-controller.js"],[_,"refine/date-controller.js"]].map(function(e){const t=e[0];return{identifier:c(e[1]),controllerConstructor:t}});e.AddController=p,e.CriterionFormController=m,e.DateController=_,e.DefaultsController=f,e.DeleteController=g,e.FilterPillsController=b,e.ModalController=y,e.PopupController=v,e.SearchFilterController=C,e.ServerRefreshController=h,e.StateController=S,e.StoredFilterController=T,e.SubmitForm=V,e.ToggleController=F,e.TurboStreamFormController=j,e.TurboStreamLinkController=E,e.TypeaheadListController=P,e.UpdateController=D,e.controllerDefinitions=O}); | ||
//# sourceMappingURL=refine-stimulus.umd.js.map |
@@ -9,2 +9,3 @@ import { identifierForContextKey } from "@hotwired/stimulus-webpack-helpers" | ||
import PopupController from './refine/popup-controller' | ||
import ModalController from './refine/modal-controller' | ||
import SearchFilterController from './refine/search-filter-controller' | ||
@@ -29,2 +30,3 @@ import ServerRefreshController from './refine/server-refresh-controller' | ||
[PopupController, 'refine/popup-controller.js'], | ||
[ModalController, 'refine/modal-controller.js'], | ||
[SearchFilterController, 'refine/search-filter-controller.js'], | ||
@@ -57,2 +59,3 @@ [ServerRefreshController, 'refine/server-refresh-controller.js'], | ||
PopupController, | ||
ModalController, | ||
SearchFilterController, | ||
@@ -59,0 +62,0 @@ ServerRefreshController, |
@@ -0,1 +1,3 @@ | ||
### 2.11.6 | ||
* WIP Feature - Adds initial framework to support a Shoelace modal component for condition selection. | ||
### 2.11.5 | ||
@@ -2,0 +4,0 @@ * New Feature - Adds the ability to delete OR groupings which merge them as AND conjunctions |
{ | ||
"name": "@clickfunnels/refine-stimulus", | ||
"version": "2.11.5", | ||
"version": "2.11.6", | ||
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.", | ||
@@ -5,0 +5,0 @@ "browserslist": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
391550
36
3882