@clickfunnels/refine-stimulus
Advanced tools
Comparing version 2.11.12 to 2.12.0
@@ -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 o}from"lodash";import l 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 c 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 u 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("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)}}}u.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 c{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(),null==e||e.stopPropagation(),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(){r(this)}disconnect(){}open(e){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 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)},T=(e,t,r)=>{var i;const n=null==r?void 0:r.component,s=(null==r?void 0:r.meta)||{clauses:[],options:{}},o=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=s;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let c={clause:null==(i=l[0])?void 0:i.id,selected:d};return o.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,c[e.id]={clause:i[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:c}};class y 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,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 r;this.blueprint.length>0&&this.blueprint.push({depth:r=void 0===r?0:r,type:"conjunction",word:"or"}),this.blueprint.push(T(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"},T(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,s=i&&"or"===i.word||!i,o=n||!r,l=o&&s;r||i?t.splice(l&&n?e-1:l&&!r||o&&!s?e:e-1,2):this.blueprint=[],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(T));const n=this.blueprint[e],o=T(t,i.depth,r);return!s(n,o)&&(this.blueprint[e]=o,w(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},w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}y.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},y.targets=["loading"];class S 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)}}S.targets=["blueprintField"],S.values={formId:String,stateDomId:String};class I extends e{submit(e){e.preventDefault(),this.element.requestSubmit()}}class C extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}C.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 P 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 j extends c{initialize(){this.updateBlueprint=o((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,s=e.target.dataset,o=s.inputId;r=r||s.inputKey||"value",t=(t=t||e.target.value).trim(),n.updateInput(i,{[r]:t},o)}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?l(t.startDate.toISOString()):l(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:{}}};class _ extends e{showSearchBar(e){this.searchBarInputTarget.hidden=!1}hideSearchBar(e){this.searchBarInputTarget.hidden=!0}}_.targets=["searchBarInput"];class D extends e{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let r=e.toString();window.history.replaceState(null,"",[window.location.pathname,r?"?"+r:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}D.values={keepScrollPosition:{type:Boolean,default:!1}};const k=[[u,"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"],[c,"refine/server-refresh-controller.js"],[y,"refine/state-controller.js"],[S,"refine/stored-filter-controller.js"],[I,"refine/submit-form-controller.js"],[C,"refine/toggle-controller.js"],[V,"refine/turbo-stream-form-controller.js"],[P,"refine/turbo-stream-link-controller.js"],[E,"./refine/typeahead-list-controller.js"],[j,"refine/update-controller.js"],[F,"refine/date-controller.js"],[_,"refine/inline-advanced-modal-controller.js"],[D,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{u as AddController,h as CriterionFormController,F as DateController,p as DefaultsController,m as DeleteController,f as FilterPillsController,_ as InlineAdvancedModalController,b as ModalController,g as PopupController,v as SearchFilterController,c as ServerRefreshController,y as StateController,S as StoredFilterController,I as SubmitForm,D as TabGroupController,C as ToggleController,V as TurboStreamFormController,P as TurboStreamLinkController,E as TypeaheadListController,j as UpdateController,k 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 o}from"lodash";import l 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 c 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 u 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("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)}}}u.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 c{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(),null==e||e.stopPropagation(),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(){r(this)}disconnect(){}open(e){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 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)},y=(e,t,r)=>{var i;const n=null==r?void 0:r.component,s=(null==r?void 0:r.meta)||{clauses:[],options:{}},o=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=s;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let c={clause:null==(i=l[0])?void 0:i.id,selected:d};return o.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,c[e.id]={clause:i[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:c}};class T 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,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 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)),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"},y(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,s=i&&"or"===i.word||!i,o=n||!r,l=o&&s;r||i?t.splice(l&&n?e-1:l&&!r||o&&!s?e:e-1,2):this.blueprint=[],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(y));const n=this.blueprint[e],o=y(t,i.depth,r);return!s(n,o)&&(this.blueprint[e]=o,w(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},w(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}T.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},T.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 S extends e{submit(e){e.preventDefault(),this.element.requestSubmit()}}class C extends e{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}C.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 c{initialize(){this.updateBlueprint=o((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,s=e.target.dataset,o=s.inputId;r=r||s.inputKey||"value","string"==typeof(t=t||e.target.value)&&(t=t.trim()),n.updateInput(i,{[r]:t},o)}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?l(t.startDate.toISOString()):l(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:{}}};class _ extends e{connect(){this.observer=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:1}),this.categoryBlockItemTargets.forEach(e=>this.observer.observe(e))}disconnect(){this.observer.disconnect()}handleIntersection(e){e.forEach(e=>{e.isIntersecting&&this.highlightCategory(e.target.dataset.categoryListBlockValue)})}highlightCategory(e){this.categoryShortcutItemTargets.forEach(t=>{t.dataset.inlineAdvancedModalValue===e?t.classList.add("active"):t.classList.remove("active")})}showSearchBar(){this.searchBarInputTarget.hidden=!1}hideSearchBar(){this.searchBarInputTarget.hidden=!0}findCategoryElementByName(e){return this.categoryListItemTargets.find(t=>t.dataset.categoryListItemValue===e)}scrollToCategory(e){const t=this.findCategoryElementByName(e.target.dataset.inlineAdvancedModalValue);t&&t.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})}}_.targets=["searchBarInput","categoryListItem","categoryBlockItem","categoryShortcutItem"];class D extends e{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let r=e.toString();window.history.replaceState(null,"",[window.location.pathname,r?"?"+r:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}D.values={keepScrollPosition:{type:Boolean,default:!1}};const k=[[u,"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"],[c,"refine/server-refresh-controller.js"],[T,"refine/state-controller.js"],[I,"refine/stored-filter-controller.js"],[S,"refine/submit-form-controller.js"],[C,"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"],[_,"refine/inline-advanced-modal-controller.js"],[D,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{u as AddController,h as CriterionFormController,F as DateController,p as DefaultsController,m as DeleteController,f as FilterPillsController,_ as InlineAdvancedModalController,b as ModalController,g as PopupController,v as SearchFilterController,c as ServerRefreshController,T as StateController,I as StoredFilterController,S as SubmitForm,D as TabGroupController,C as ToggleController,V as TurboStreamFormController,E as TurboStreamLinkController,P as TypeaheadListController,j as UpdateController,k 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"),o=require("moment"),l=require("jquery");function s(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("daterangepicker");var a=s(o),d=s(l);function u(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(),null==e||e.stopPropagation(),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(){r.useClickOutside(this)}disconnect(){}open(e){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.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}}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 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)},T=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},l=(null==r?void 0:r.refinements)||[],{clauses:s,options:a}=o;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let u={clause:null==(i=s[0])?void 0:i.id,selected:d};return l.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let o;o="option-condition"===r?n[0]?[n[0].id]:[]:void 0,u[e.id]={clause:i[0].id,selected:o}}),{depth:t,type:"criterion",condition_id:e,input:u}};class S 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(T(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"},T(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,o=i&&"or"===i.word||!i,l=n||!r,s=l&&o;r||i?t.splice(s&&n?e-1:s&&!r||l&&!o?e:e-1,2):this.blueprint=[],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(T));const o=this.blueprint[e],l=T(t,i.depth,r);return!n.isEqual(o,l)&&(this.blueprint[e]=l,C(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},C(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 y 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)}}y.targets=["blueprintField"],y.values={formId:String,stateDomId:String};class I 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 P 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 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,o=e.target.dataset,l=o.inputId;r=r||o.inputKey||"value",t=(t=t||e.target.value).trim(),n.updateInput(i,{[r]:t},l)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}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),o=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=o,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")}}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:{}}};class D extends e.Controller{showSearchBar(e){this.searchBarInputTarget.hidden=!1}hideSearchBar(e){this.searchBarInputTarget.hidden=!0}}D.targets=["searchBarInput"];class _ extends e.Controller{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let r=e.toString();window.history.replaceState(null,"",[window.location.pathname,r?"?"+r:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}_.values={keepScrollPosition:{type:Boolean,default:!1}};const k=[[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"],[w,"refine/search-filter-controller.js"],[c,"refine/server-refresh-controller.js"],[S,"refine/state-controller.js"],[y,"refine/stored-filter-controller.js"],[I,"refine/submit-form-controller.js"],[V,"refine/toggle-controller.js"],[F,"refine/turbo-stream-form-controller.js"],[P,"refine/turbo-stream-link-controller.js"],[E,"./refine/typeahead-list-controller.js"],[j,"refine/update-controller.js"],[x,"refine/date-controller.js"],[D,"refine/inline-advanced-modal-controller.js"],[_,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:u(e[1]),controllerConstructor:t}});exports.AddController=h,exports.CriterionFormController=p,exports.DateController=x,exports.DefaultsController=m,exports.DeleteController=f,exports.FilterPillsController=g,exports.InlineAdvancedModalController=D,exports.ModalController=v,exports.PopupController=b,exports.SearchFilterController=w,exports.ServerRefreshController=c,exports.StateController=S,exports.StoredFilterController=y,exports.SubmitForm=I,exports.TabGroupController=_,exports.ToggleController=V,exports.TurboStreamFormController=F,exports.TurboStreamLinkController=P,exports.TypeaheadListController=E,exports.UpdateController=j,exports.controllerDefinitions=k; | ||
var e=require("@hotwired/stimulus"),t=require("@rails/request.js"),r=require("stimulus-use"),i=require("jquery-events-to-dom-events"),n=require("lodash"),o=require("moment"),s=require("jquery");function l(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("daterangepicker");var a=l(o),d=l(s);function c(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class u 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 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.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 u{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(),null==e||e.stopPropagation(),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(){r.useClickOutside(this)}disconnect(){}open(e){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.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}}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 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)},C=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=o;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let c={clause:null==(i=l[0])?void 0:i.id,selected:d};return s.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let o;o="option-condition"===r?n[0]?[n[0].id]:[]:void 0,c[e.id]={clause:i[0].id,selected:o}}),{depth:t,type:"criterion",condition_id:e,input:c}};class T 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(C(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"},C(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,o=i&&"or"===i.word||!i,s=n||!r,l=s&&o;r||i?t.splice(l&&n?e-1:l&&!r||s&&!o?e:e-1,2):this.blueprint=[],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(C));const o=this.blueprint[e],s=C(t,i.depth,r);return!n.isEqual(o,s)&&(this.blueprint[e]=s,y(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},y(this.element,{blueprint:this.blueprint,formId:this.formIdValue})}}T.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},T.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 V extends e.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}V.targets=["content"];class E 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 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 u{initialize(){this.updateBlueprint=n.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset,s=o.inputId;r=r||o.inputKey||"value","string"==typeof(t=t||e.target.value)&&(t=t.trim()),n.updateInput(i,{[r]:t},s)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}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),o=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=o,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")}}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:{}}};class k extends e.Controller{connect(){this.observer=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:1}),this.categoryBlockItemTargets.forEach(e=>this.observer.observe(e))}disconnect(){this.observer.disconnect()}handleIntersection(e){e.forEach(e=>{e.isIntersecting&&this.highlightCategory(e.target.dataset.categoryListBlockValue)})}highlightCategory(e){this.categoryShortcutItemTargets.forEach(t=>{t.dataset.inlineAdvancedModalValue===e?t.classList.add("active"):t.classList.remove("active")})}showSearchBar(){this.searchBarInputTarget.hidden=!1}hideSearchBar(){this.searchBarInputTarget.hidden=!0}findCategoryElementByName(e){return this.categoryListItemTargets.find(t=>t.dataset.categoryListItemValue===e)}scrollToCategory(e){const t=this.findCategoryElementByName(e.target.dataset.inlineAdvancedModalValue);t&&t.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})}}k.targets=["searchBarInput","categoryListItem","categoryBlockItem","categoryShortcutItem"];class D extends e.Controller{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let r=e.toString();window.history.replaceState(null,"",[window.location.pathname,r?"?"+r:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}D.values={keepScrollPosition:{type:Boolean,default:!1}};const _=[[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"],[w,"refine/search-filter-controller.js"],[u,"refine/server-refresh-controller.js"],[T,"refine/state-controller.js"],[I,"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"],[P,"./refine/typeahead-list-controller.js"],[j,"refine/update-controller.js"],[x,"refine/date-controller.js"],[k,"refine/inline-advanced-modal-controller.js"],[D,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:c(e[1]),controllerConstructor:t}});exports.AddController=h,exports.CriterionFormController=p,exports.DateController=x,exports.DefaultsController=m,exports.DeleteController=f,exports.FilterPillsController=g,exports.InlineAdvancedModalController=k,exports.ModalController=v,exports.PopupController=b,exports.SearchFilterController=w,exports.ServerRefreshController=u,exports.StateController=T,exports.StoredFilterController=I,exports.SubmitForm=S,exports.TabGroupController=D,exports.ToggleController=V,exports.TurboStreamFormController=E,exports.TurboStreamLinkController=F,exports.TypeaheadListController=P,exports.UpdateController=j,exports.controllerDefinitions=_; | ||
//# 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 a}from"lodash";import l 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 c 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 u extends c{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}}u.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 c{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(),null==e||e.stopPropagation(),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(){i(this)}disconnect(){}open(e){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 T=(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:{}},a=(null==i?void 0:i.refinements)||[],{clauses:l,options:o}=s;let d;d="option-condition"===n?o[0]?[o[0].id]:[]:void 0;let c={clause:null==(r=l[0])?void 0:r.id,selected:d};return a.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,c[e.id]={clause:r[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:c}};class S 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,T(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)),T(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)),T(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,a=n||!i,l=a&&s;i||r?t.splice(l&&n?e-1:l&&!i||a&&!s?e:e-1,2):this.blueprint=[],T(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],a=y(t,r.depth,i);return!s(n,a)&&(this.blueprint[e]=a,T(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),T(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 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:i}=t;this.blueprintFieldTarget.value=JSON.stringify(i),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 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 j 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)})}}j.targets=["listItem","category","recommended"];class _ extends c{initialize(){this.updateBlueprint=a((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,a=s.inputId;i=i||s.inputKey||"value",t=(t=t||e.target.value).trim(),n.updateInput(r,{[i]:t},a)}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?l(t.startDate.toISOString()):l(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:{}}};class O extends e{showSearchBar(e){this.searchBarInputTarget.hidden=!1}hideSearchBar(e){this.searchBarInputTarget.hidden=!0}}O.targets=["searchBarInput"];class P extends e{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let i=e.toString();window.history.replaceState(null,"",[window.location.pathname,i?`?${i}`:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}P.values={keepScrollPosition:{type:Boolean,default:!1}};const k=[[u,"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"],[c,"refine/server-refresh-controller.js"],[S,"refine/state-controller.js"],[I,"refine/stored-filter-controller.js"],[C,"refine/submit-form-controller.js"],[V,"refine/toggle-controller.js"],[E,"refine/turbo-stream-form-controller.js"],[F,"refine/turbo-stream-link-controller.js"],[j,"./refine/typeahead-list-controller.js"],[_,"refine/update-controller.js"],[D,"refine/date-controller.js"],[O,"refine/inline-advanced-modal-controller.js"],[P,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{u as AddController,h as CriterionFormController,D as DateController,p as DefaultsController,m as DeleteController,g as FilterPillsController,O as InlineAdvancedModalController,v as ModalController,b as PopupController,w as SearchFilterController,c as ServerRefreshController,S as StateController,I as StoredFilterController,C as SubmitForm,P as TabGroupController,V as ToggleController,E as TurboStreamFormController,F as TurboStreamLinkController,j as TypeaheadListController,_ as UpdateController,k 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 a}from"lodash";import o from"moment";import l from"jquery";import"daterangepicker";function d(e){const t=(e.match(/^(?:\.\/)?(.+)(?:[_-]controller\..+?)$/)||[])[1];if(t)return t.replace(/_/g,"-").replace(/\//g,"--")}class c 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 u extends c{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}}u.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 c{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(),null==e||e.stopPropagation(),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(){i(this)}disconnect(){}open(e){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)},T=(e,t,i)=>{var r;const n=null==i?void 0:i.component,s=(null==i?void 0:i.meta)||{clauses:[],options:{}},a=(null==i?void 0:i.refinements)||[],{clauses:o,options:l}=s;let d;d="option-condition"===n?l[0]?[l[0].id]:[]:void 0;let c={clause:null==(r=o[0])?void 0:r.id,selected:d};return a.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,c[e.id]={clause:r[0].id,selected:s}}),{depth:t,type:"criterion",condition_id:e,input:c}};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,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(T(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"},T(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,a=n||!i,o=a&&s;i||r?t.splice(o&&n?e-1:o&&!i||a&&!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(T)}`);const n=this.blueprint[e],a=T(t,r.depth,i);return!s(n,a)&&(this.blueprint[e]=a,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})}}I.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},I.targets=["loading"];class S 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)}}S.targets=["blueprintField"],S.values={formId:String,stateDomId:String};class C 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 j 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)})}}j.targets=["listItem","category","recommended"];class _ extends c{initialize(){this.updateBlueprint=a((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,a=s.inputId;i=i||s.inputKey||"value","string"==typeof(t=t||e.target.value)&&(t=t.trim()),n.updateInput(r,{[i]:t},a)}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?o(t.startDate.toISOString()):o(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:l(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=l(this.pluginMainEl).data("daterangepicker"),this.inlineValue&&this.element.classList.add("date-input--inline")}teardownPluginInstance(){void 0!==this.plugin&&(l(this.pluginMainEl).off("apply.daterangepicker"),l(this.pluginMainEl).off("cancel.daterangepicker"),l(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:{}}};class k extends e{connect(){this.observer=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:1}),this.categoryBlockItemTargets.forEach(e=>this.observer.observe(e))}disconnect(){this.observer.disconnect()}handleIntersection(e){e.forEach(e=>{e.isIntersecting&&this.highlightCategory(e.target.dataset.categoryListBlockValue)})}highlightCategory(e){this.categoryShortcutItemTargets.forEach(t=>{t.dataset.inlineAdvancedModalValue===e?t.classList.add("active"):t.classList.remove("active")})}showSearchBar(){this.searchBarInputTarget.hidden=!1}hideSearchBar(){this.searchBarInputTarget.hidden=!0}findCategoryElementByName(e){return this.categoryListItemTargets.find(t=>t.dataset.categoryListItemValue===e)}scrollToCategory(e){const t=this.findCategoryElementByName(e.target.dataset.inlineAdvancedModalValue);t&&t.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})}}k.targets=["searchBarInput","categoryListItem","categoryBlockItem","categoryShortcutItem"];class O extends e{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let i=e.toString();window.history.replaceState(null,"",[window.location.pathname,i?`?${i}`:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}O.values={keepScrollPosition:{type:Boolean,default:!1}};const P=[[u,"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"],[c,"refine/server-refresh-controller.js"],[I,"refine/state-controller.js"],[S,"refine/stored-filter-controller.js"],[C,"refine/submit-form-controller.js"],[V,"refine/toggle-controller.js"],[E,"refine/turbo-stream-form-controller.js"],[F,"refine/turbo-stream-link-controller.js"],[j,"./refine/typeahead-list-controller.js"],[_,"refine/update-controller.js"],[D,"refine/date-controller.js"],[k,"refine/inline-advanced-modal-controller.js"],[O,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:d(e[1]),controllerConstructor:t}});export{u as AddController,h as CriterionFormController,D as DateController,p as DefaultsController,m as DeleteController,g as FilterPillsController,k as InlineAdvancedModalController,v as ModalController,b as PopupController,w as SearchFilterController,c as ServerRefreshController,I as StateController,S as StoredFilterController,C as SubmitForm,O as TabGroupController,V as ToggleController,E as TurboStreamFormController,F as TurboStreamLinkController,j as TypeaheadListController,_ as UpdateController,P 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 d=a(o),u=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(),null==e||e.stopPropagation(),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 w extends t.Controller{connect(){i.useClickOutside(this)}disconnect(){}open(e){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)}}w.targets=["frame"],w.values={src:String,isOpen:{type:Boolean,default:!1}};class T 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}}T.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 d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let u={clause:null==(i=s[0])?void 0:i.id,selected:d};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,u[e.id]={clause:i[0].id,selected:l}}),{depth:t,type:"criterion",condition_id:e,input:u}};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,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(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 n=this.blueprint[e],o=y(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})}}S.values={blueprint:Array,conditions:Array,className:String,refreshUrl:String,clientId:String,validateBlueprintUrl:String,defaultConditionId:String},S.targets=["loading"];class I 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)}}I.targets=["blueprintField"],I.values={formId:String,stateDomId:String};class V extends t.Controller{submit(e){e.preventDefault(),this.element.requestSubmit()}}class j extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}j.targets=["content"];class E 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 F 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,o=l.inputId;r=r||l.inputKey||"value",t=(t=t||e.target.value).trim(),n.updateInput(i,{[r]:t},o)}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?d.default(t.startDate.toISOString()):d.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")}}_.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:{}}};class k extends t.Controller{showSearchBar(e){this.searchBarInputTarget.hidden=!1}hideSearchBar(e){this.searchBarInputTarget.hidden=!0}}k.targets=["searchBarInput"];class q extends t.Controller{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let r=e.toString();window.history.replaceState(null,"",[window.location.pathname,r?"?"+r:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}q.values={keepScrollPosition:{type:Boolean,default:!1}};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"],[w,"refine/modal-controller.js"],[T,"refine/search-filter-controller.js"],[h,"refine/server-refresh-controller.js"],[S,"refine/state-controller.js"],[I,"refine/stored-filter-controller.js"],[V,"refine/submit-form-controller.js"],[j,"refine/toggle-controller.js"],[E,"refine/turbo-stream-form-controller.js"],[F,"refine/turbo-stream-link-controller.js"],[P,"./refine/typeahead-list-controller.js"],[D,"refine/update-controller.js"],[_,"refine/date-controller.js"],[k,"refine/inline-advanced-modal-controller.js"],[q,"fields/shoelace/tab-group-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.InlineAdvancedModalController=k,e.ModalController=w,e.PopupController=v,e.SearchFilterController=T,e.ServerRefreshController=h,e.StateController=S,e.StoredFilterController=I,e.SubmitForm=V,e.TabGroupController=q,e.ToggleController=j,e.TurboStreamFormController=E,e.TurboStreamLinkController=F,e.TypeaheadListController=P,e.UpdateController=D,e.controllerDefinitions=O}); | ||
!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,o,s,l){function a(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var d=a(s),u=a(l);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 m 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)}}}m.values={previousCriterionId:Number};class p 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)}}}p.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(),null==e||e.stopPropagation(),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(){i.useClickOutside(this)}disconnect(){}open(e){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 w 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}}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 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)},T=(e,t,r)=>{var i;const n=null==r?void 0:r.component,o=(null==r?void 0:r.meta)||{clauses:[],options:{}},s=(null==r?void 0:r.refinements)||[],{clauses:l,options:a}=o;let d;d="option-condition"===n?a[0]?[a[0].id]:[]:void 0;let u={clause:null==(i=l[0])?void 0:i.id,selected:d};return s.forEach(e=>{const{meta:t,component:r}=e,{clauses:i,options:n}=t;let o;o="option-condition"===r?n[0]?[n[0].id]:[]:void 0,u[e.id]={clause:i[0].id,selected:o}}),{depth:t,type:"criterion",condition_id:e,input:u}};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(T(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"},T(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,o=i&&"or"===i.word||!i,s=n||!r,l=s&&o;r||i?t.splice(l&&n?e-1:l&&!r||s&&!o?e:e-1,2):this.blueprint=[],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(T));const n=this.blueprint[e],s=T(t,i.depth,r);return!o.isEqual(n,s)&&(this.blueprint[e]=s,C(this.element,{blueprint:this.blueprint,formId:this.formIdValue}),!0)}updateInput(e,t,r){const{blueprint:i}=this,n=i[e],o=(r=r||"input").split(", ");o.length>1?n[o[0]][o[1]]={...n[o[0]][o[1]],...t}:n[r]={...n[r],...t},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 V extends t.Controller{submit(e){e.preventDefault(),this.element.requestSubmit()}}class E extends t.Controller{toggle(e){this.contentTargets.forEach(e=>{e.toggleAttribute("hidden")})}}E.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 F 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 k extends h{initialize(){this.updateBlueprint=o.debounce((e,t,r)=>{this.value(e,t,r)},500)}refinedFilter(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{id:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}clause(e){const{criterionIdValue:t,state:r}=this;r.updateInput(t,{clause:e.target.value},e.target.dataset.inputId),this.refreshFromServer()}selected(e){const{target:t}=e,r=Array.prototype.slice.call(t.options).filter(e=>e.selected).map(e=>e.value);this.value(e,r,"selected")}value(e,t,r){const{criterionIdValue:i,state:n}=this,o=e.target.dataset,s=o.inputId;r=r||o.inputKey||"value","string"==typeof(t=t||e.target.value)&&(t=t.trim()),n.updateInput(i,{[r]:t},s)}condition(e){const{criterionIdValue:t,state:r}=this,i=e.target;let n=i.value;n||(n=i.querySelector("select").value);const o=this.state.conditionConfigFor(n);r.replaceCriterion(t,n,o)&&this.refreshFromServer()}cancelEnter(e){"Enter"===e.code&&(e.preventDefault(),e.stopPropagation())}}k.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?d.default(t.startDate.toISOString()):d.default(this.fieldTarget.value,"YYYY-MM-DDTHH:mm").format("YYYY-MM-DDTHH:mm"),n=i.format(r),o=this.includeTimeValue?i.toISOString(!0):i.format("YYYY-MM-DD");this.fieldTarget.value=n,this.hiddenFieldTarget.value=o,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")}}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:{}}};class _ extends t.Controller{connect(){this.observer=new IntersectionObserver(this.handleIntersection.bind(this),{threshold:1}),this.categoryBlockItemTargets.forEach(e=>this.observer.observe(e))}disconnect(){this.observer.disconnect()}handleIntersection(e){e.forEach(e=>{e.isIntersecting&&this.highlightCategory(e.target.dataset.categoryListBlockValue)})}highlightCategory(e){this.categoryShortcutItemTargets.forEach(t=>{t.dataset.inlineAdvancedModalValue===e?t.classList.add("active"):t.classList.remove("active")})}showSearchBar(){this.searchBarInputTarget.hidden=!1}hideSearchBar(){this.searchBarInputTarget.hidden=!0}findCategoryElementByName(e){return this.categoryListItemTargets.find(t=>t.dataset.categoryListItemValue===e)}scrollToCategory(e){const t=this.findCategoryElementByName(e.target.dataset.inlineAdvancedModalValue);t&&t.scrollIntoView({behavior:"smooth",block:"start",inline:"nearest"})}}_.targets=["searchBarInput","categoryListItem","categoryBlockItem","categoryShortcutItem"];class O extends t.Controller{connect(){this.currentScrollYPosition=0,this.navigateToTab=this.navigateToTab.bind(this),this.handleTabShow=this.handleTabShow.bind(this),this.navigateToTab(),document.addEventListener("turbo:load",this.navigateToTab),this.element.addEventListener("sl-tab-show",this.handleTabShow)}disconnect(){document.removeEventListener("turbo:load",this.navigateToTab),this.element.removeEventListener("sl-tab-show",this.handleTabShow)}handleTabShow(e){this.setLocationHash(e),this.keepScrollPositionValue&&this.handleTabChange()}setLocationHash(e){window.location.hash=e.detail.name}navigateToTab(){let e=window.location.hash.toString();if(e)this.element.show(e.slice(1));else{const e=new URLSearchParams(window.location.search),t=e.get("redirect_anchor");if(t){e.delete("redirect_anchor");let r=e.toString();window.history.replaceState(null,"",[window.location.pathname,r?"?"+r:"","#",t].join(""))}}}handleTabChange(){this.currentScrollYPosition=window.scrollY}show(e){const{showPanel:t}=e.params;this.element.show(t)}}O.values={keepScrollPosition:{type:Boolean,default:!1}};const q=[[m,"refine/add-controller.js"],[p,"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"],[w,"refine/search-filter-controller.js"],[h,"refine/server-refresh-controller.js"],[I,"refine/state-controller.js"],[S,"refine/stored-filter-controller.js"],[V,"refine/submit-form-controller.js"],[E,"refine/toggle-controller.js"],[j,"refine/turbo-stream-form-controller.js"],[F,"refine/turbo-stream-link-controller.js"],[P,"./refine/typeahead-list-controller.js"],[k,"refine/update-controller.js"],[D,"refine/date-controller.js"],[_,"refine/inline-advanced-modal-controller.js"],[O,"fields/shoelace/tab-group-controller.js"]].map(function(e){const t=e[0];return{identifier:c(e[1]),controllerConstructor:t}});e.AddController=m,e.CriterionFormController=p,e.DateController=D,e.DefaultsController=f,e.DeleteController=g,e.FilterPillsController=b,e.InlineAdvancedModalController=_,e.ModalController=y,e.PopupController=v,e.SearchFilterController=w,e.ServerRefreshController=h,e.StateController=I,e.StoredFilterController=S,e.SubmitForm=V,e.TabGroupController=O,e.ToggleController=E,e.TurboStreamFormController=j,e.TurboStreamLinkController=F,e.TypeaheadListController=P,e.UpdateController=k,e.controllerDefinitions=q}); | ||
//# sourceMappingURL=refine-stimulus.umd.js.map |
@@ -5,12 +5,61 @@ import { Controller } from "@hotwired/stimulus" | ||
static targets = ['searchBarInput'] | ||
static targets = ['searchBarInput', 'categoryListItem', 'categoryBlockItem', 'categoryShortcutItem'] | ||
showSearchBar(event) { | ||
connect() { | ||
this.observer = new IntersectionObserver( | ||
this.handleIntersection.bind(this), { | ||
threshold: 1 | ||
} | ||
) | ||
this.categoryBlockItemTargets.forEach(item => this.observer.observe(item)) | ||
} | ||
disconnect() { | ||
this.observer.disconnect() | ||
} | ||
handleIntersection(entries) { | ||
entries.forEach(entry => { | ||
if(entry.isIntersecting) { | ||
this.highlightCategory(entry.target.dataset.categoryListBlockValue) | ||
} | ||
}) | ||
} | ||
highlightCategory(categoryName) { | ||
this.categoryShortcutItemTargets.forEach(item => { | ||
if(item.dataset.inlineAdvancedModalValue === categoryName) { | ||
item.classList.add('active') | ||
} else { | ||
item.classList.remove('active') | ||
} | ||
}) | ||
} | ||
showSearchBar() { | ||
this.searchBarInputTarget.hidden = false | ||
} | ||
hideSearchBar(event) { | ||
hideSearchBar() { | ||
this.searchBarInputTarget.hidden = true | ||
} | ||
findCategoryElementByName(categoryName) { | ||
// Use the find method to locate the target with the specified attribute value | ||
return this.categoryListItemTargets.find(item => item.dataset.categoryListItemValue === categoryName) | ||
} | ||
scrollToCategory(event) { | ||
const categoryName = event.target.dataset.inlineAdvancedModalValue | ||
const categoryElement = this.findCategoryElementByName(categoryName) | ||
if(categoryElement) { | ||
categoryElement.scrollIntoView({ | ||
behavior: "smooth", | ||
block: "start", | ||
inline: "nearest" | ||
}) | ||
} | ||
} | ||
} |
@@ -58,3 +58,4 @@ import ServerRefreshController from './server-refresh-controller' | ||
value = value || event.target.value | ||
value = value.trim() | ||
if(typeof value === 'string') | ||
value = value.trim() | ||
state.updateInput( | ||
@@ -61,0 +62,0 @@ criterionIdValue, |
@@ -0,1 +1,4 @@ | ||
### 2.12.0 | ||
* Feature Release - Advanced Condition Select: Fully releases a new option for condition selects built for more complex filters | ||
* Fixes a bug with 2.11.12 where a is_one_of and is_not_one_of clause would break the old UI | ||
### 2.11.12 | ||
@@ -2,0 +5,0 @@ * Trims inputs in old and new UIs for values to remove leading and trailing whitespace |
{ | ||
"name": "@clickfunnels/refine-stimulus", | ||
"version": "2.11.12", | ||
"version": "2.12.0", | ||
"description": "Refine is a flexible query builder for your apps. It lets your users filter down to exactly what they're looking for. Completely configured on the backend.", | ||
@@ -5,0 +5,0 @@ "browserslist": [ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
442212
4269