@nyaruka/temba-components 0.129.4 → 0.129.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -1
- package/dist/temba-components.js +4 -4
- package/dist/temba-components.js.map +1 -1
- package/out-tsc/src/flow/NodeEditor.js +11 -0
- package/out-tsc/src/flow/NodeEditor.js.map +1 -1
- package/out-tsc/src/form/select/Select.js +29 -14
- package/out-tsc/src/form/select/Select.js.map +1 -1
- package/out-tsc/src/live/ContactChat.js +1 -1
- package/out-tsc/src/live/ContactChat.js.map +1 -1
- package/out-tsc/test/temba-select.test.js +73 -0
- package/out-tsc/test/temba-select.test.js.map +1 -1
- package/package.json +1 -1
- package/src/flow/NodeEditor.ts +11 -0
- package/src/form/select/Select.ts +30 -14
- package/src/live/ContactChat.ts +1 -1
- package/test/temba-select.test.ts +107 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,8 +4,15 @@ All notable changes to this project will be documented in this file. Dates are d
|
|
|
4
4
|
|
|
5
5
|
Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
6
6
|
|
|
7
|
-
#### [v0.129.
|
|
7
|
+
#### [v0.129.6](https://github.com/nyaruka/temba-components/compare/v0.129.5...v0.129.6)
|
|
8
8
|
|
|
9
|
+
- Fix message event to use ID for chatevent [`#650`](https://github.com/nyaruka/temba-components/pull/650)
|
|
10
|
+
|
|
11
|
+
#### [v0.129.5](https://github.com/nyaruka/temba-components/compare/v0.129.3...v0.129.5)
|
|
12
|
+
|
|
13
|
+
> 12 August 2025
|
|
14
|
+
|
|
15
|
+
- Don't trigger ref change on internal values change for Select [`#648`](https://github.com/nyaruka/temba-components/pull/648)
|
|
9
16
|
- Cleanup unused chat event types and remove some unused properties on other types [`#647`](https://github.com/nyaruka/temba-components/pull/647)
|
|
10
17
|
- Nestable form layouts [`#644`](https://github.com/nyaruka/temba-components/pull/644)
|
|
11
18
|
- Add KeyValueEditor and field config abstraction [`#643`](https://github.com/nyaruka/temba-components/pull/643)
|
package/dist/temba-components.js
CHANGED
|
@@ -1049,7 +1049,7 @@ let Ar=rr,Mr=!1;const Tr=["es","fr","pt"],Pr="data:image/png;base64,iVBORw0KGgoA
|
|
|
1049
1049
|
.ghost .remove-item {
|
|
1050
1050
|
display: none !important;
|
|
1051
1051
|
}
|
|
1052
|
-
`}constructor(){super(),this.hiddenInputs=[],this.inputStyle={},this.multi=!1,this.searchOnFocus=!1,this.placeholder="",this.name="",this.allowCreate=!1,this.nameKey="name",this.valueKey="value",this.maxItems=0,this.maxItemsText="Maximum items reached",this.queryParam=null,this.input="",this.visibleOptions=[],this.completionOptions=[],this.quietMillis=0,this.searchable=!1,this.cache=!0,this.cacheKey="",this.focused=!1,this.disabled=!1,this.attemptedOpen=!1,this.selectedIndex=-1,this.anchorPosition={left:0,top:0},this.tags=!1,this.emails=!1,this.flavor="default",this.infoText="",this.values=[],this.getName=t=>t[this.nameKey||"name"],this.isMatch=this.isMatchDefault,this.getValue=t=>t[this.valueKey||"value"]||t.id,this.sortFunction=null,this.renderOptionDetail=()=>H``,this.renderSelectedItem=this.renderSelectedItemDefault,this.createArbitraryOption=this.createArbitraryOptionDefault,this.getOptions=this.getOptionsDefault,this.prepareOptions=this.prepareOptionsDefault,this.isComplete=this.isCompleteDefault,this.staticOptions=[],this.allowAnchor=!0,this.alphaSort=(t,e)=>this.endpoint?this.getName(t).localeCompare(this.getName(e)):0,this.next=null,this.lruCache=Ve(20,6e4),this.getNameInternal=t=>this.getName(t),this.renderOptionDefault=this.renderOptionDefault.bind(this),this.renderSelectedItemDefault=this.renderSelectedItemDefault.bind(this),this.prepareOptionsDefault=this.prepareOptionsDefault.bind(this),this.isMatchDefault=this.isMatchDefault.bind(this),this.handleOrderChanged=this.handleOrderChanged.bind(this)}prepareOptionsDefault(t){return t}isMatchDefault(t,e){return(this.getName(t)||"").toLowerCase().indexOf(e)>-1}handleSlotChange(){if(this.staticOptions&&0===this.staticOptions.length)for(const t of this.children)if("TEMBA-OPTION"===t.tagName){const e={};for(const i of t.attributes)e[i.name]=i.value;if(e){let t=!1;void 0!==e.selected&&(delete e.selected,t=!0);const i=this.value||this.getAttribute("value");if(i){this.getValue(e)==i&&(t=!0)}this.staticOptions.push(e),t&&(this.isMultiMode?this.addValue(e):this.setValues([e]))}}this.searchable&&0===this.staticOptions.length&&(this.quietMillis=200)}checkSelectedOption(){if(this.value&&0==this.values.length&&0==this.staticOptions.length&&this.endpoint){const t=this.value;this.resolving=!0,Jt(this.endpoint).then((e=>{if(e&&e.length>0){if(t){const i=e.find((e=>this.getValue(e)===t));if(i)return this.resolving=!1,this.fetching=!1,void this.setValues([i])}this.setValues([e[0]]),this.resolving=!1}}))}else this.staticOptions.length>0&&(null!==this.getAttribute("multi")?this.addValue(this.staticOptions[0]):this.getAttribute("value")?this.setSelectedValue(this.getAttribute("value")):this.setValues([this.staticOptions[0]]))}firstUpdated(t){super.firstUpdated(t),this.anchorElement=this.shadowRoot.querySelector(".select-container"),this.anchorExpressions=this.shadowRoot.querySelector("#anchor"),this.shadowRoot.addEventListener("slotchange",this.handleSlotChange.bind(this))}async createOptionPost(t){return ne(this.endpoint,t).then((e=>{if(e.status>=200&&e.status<300)return{json:e.json,payload:t}}))}updated(t){if(super.updated(t),t.has("sorted")&&(this.sortFunction=this.sorted?this.alphaSort:null),t.has("value")&&this.value&&!this.values.length&&this.setSelectedValue(this.value),t.has("values")&&(this.updateInputs(),this.hasChanges(t.get("values")))){const t=[];if(this.allowCreate){const e=this.values.filter((t=>t.arbitrary));for(const i of e)i.arbitrary&&t.push(this.createOptionPost(i));Promise.all(t).then((t=>{for(const i of t)if(i){const t=e.find((t=>t===i.payload));if(t&&(delete t.arbitrary,i.json))for(const e in i.json)t[e]=i.json[e]}this.values=this.values.filter((t=>!t.arbitrary)),this.cacheKey=(new Date).getTime().toString(),this.fireEvent("change")}))}else this.fireEvent("change")}t.has("cacheKey")&&this.lruCache.clear(),t.has("input")&&!t.has("values")&&!t.has("options")&&this.focused&&(this.lastQuery&&window.clearTimeout(this.lastQuery),this.lastQuery=window.setTimeout((()=>{this.expressions&&this.input.indexOf("@")>-1?this.fetchExpressions():this.fetchOptions(this.input)}),this.quietMillis)),this.endpoint&&t.has("fetching")&&(this.fetching||this.isPastFetchThreshold()||this.fireCustomEvent(je.FetchComplete)),(t.has("cursorIndex")||t.has("visibleOptions"))&&this.endpoint&&!this.fetching&&this.isPastFetchThreshold()&&(this.next?this.fetchOptions(null,null,this.next):this.fetchOptions(this.query,this.page+1)),0===this.values.length&&!this.placeholder&&this.staticOptions.length>0&&this.setValues([this.staticOptions[0]])}hasChanges(t){if(void 0===t)return!1;let e;void 0!==t&&(e=(t||[]).map((t=>this.getValue(t))).join(","));return e!==(this.values||[]).map((t=>t.arbitrary||this.getValue(t))).join(",")}setSelectedValue(t){if(this.staticOptions.length>0){const e=this.staticOptions.find((e=>this.getValue(e)===t));e&&this.setValues([e])}else this.checkSelectedOption()}updateInputs(){for(let t=null;t=this.hiddenInputs.pop();)t.remove();if(0===this.values.length)this.value=null;else{const t=this.getAttribute("name");t&&(this.isMultiMode||1!==this.values.length?this.inputRoot.parentElement&&this.values.forEach((e=>{const i=document.createElement("input");i.setAttribute("type","hidden"),i.setAttribute("name",t),i.setAttribute("value",this.serializeValue(e)),this.hiddenInputs.push(i),this.inputRoot.parentElement.appendChild(i)})):(this.selection=this.values[0],this.value=this.serializeValue(this.values[0])))}}setSelectedOption(t){this.isMultiMode?this.addValue(t):this.setValues([t]),this.isMultiMode&&this.searchable||(this.blur(),this.focused=!1),this.visibleOptions=[],this.attemptedOpen=!1,this.input="",this.next=null,this.complete=!0,this.selectedIndex=-1}isPastFetchThreshold(){return(this.visibleOptions.length>0||this.next)&&!this.complete&&(this.cursorIndex||0)>this.visibleOptions.length-20}handleOptionSelection(t){if(this.isMultiMode&&this.maxItems>0&&this.values.length>=this.maxItems)return void(this.infoText=this.maxItemsText);this.infoText="";const e=t.detail.selected;e.post&&this.endpoint?ne(this.endpoint,e).then((t=>{t.status>=200&&t.status<300?(this.setSelectedOption(t.json),this.lruCache=Ve(20,6e4)):this.blur()})):this.setSelectedOption(e)}handleExpressionSelection(t){const e=t.detail.selected,i=t.detail.tabbed,n=this.shadowRoot.querySelector(".searchbox");bc(this.query,n,e),this.query="",this.completionOptions=[],i?this.fetchExpressions():-1===this.input.indexOf("(")&&this.addInputAsValue()}getOptionsDefault(t){return t.json.results}isCompleteDefault(t,e){const i=e.json;return!i.more&&!i.next}handleRemoveSelection(t){this.removeValue(t),this.visibleOptions=[]}createArbitraryOptionDefault(t,e){return this.emails&&t&&this.isValidEmail(t)||this.tags&&t?{name:t,value:t}:null}isValidEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}get isMultiMode(){return this.multi||this.emails}open(){this.shadowRoot.querySelector(".select-container").click()}isOpen(){return this.visibleOptions.length>0||this.attemptedOpen&&this.focused}setOptions(t){this.staticOptions=t}setVisibleOptions(t){if(t=t.filter((t=>!!this.getNameInternal(t)&&(!this.shouldExclude||!this.shouldExclude(t)))),this.input){if(this.searchable&&!this.queryParam){const e=this.input.trim().toLowerCase();t=t.filter((t=>this.isMatch(t,e)))}const e=this.createArbitraryOption(this.input,t);if(e){e.arbitrary=!0;t.find((t=>this.getValue(t)===this.getValue(e)))||(t.length>0&&t[0].arbitrary?t[0]=e:t.unshift(e))}}this.values.length>0&&(this.isMultiMode?t=t.filter((t=>!this.values.find((e=>this.getValue(e)===this.getValue(t))))):(this.input?this.cursorIndex=0:this.cursorIndex=t.findIndex((t=>this.getValue(t)===this.getValue(this.values[0]))),this.requestUpdate("cursorIndex"))),this.isMultiMode&&this.maxItems>0&&this.values.length>=this.maxItems&&(t=[],this.infoText=this.maxItemsText),this.sortFunction&&t.sort(this.sortFunction),this.visibleOptions=t,this.fireCustomEvent(je.ContentChanged,{options:this.visibleOptions})}fetchExpressions(){const t=document.querySelector("temba-store");if(this.expressions&&t){const t=this.shadowRoot.querySelector(".searchbox"),e=xc(t,"session"===this.expressions);return this.query=e.query,this.completionOptions=e.options,this.visibleOptions=[],this.anchorPosition=e.anchorPosition,void this.fireCustomEvent(je.FetchComplete)}}fetchOptions(t,e=0,i=null){if(this.completionOptions=[],!this.fetching){this.fetching=!0;const n=[...this.staticOptions],o=(t||"").trim().toLowerCase();if(this.tags&&o&&(n.find((t=>this.getValue(t)&&this.getValue(t).toLowerCase()===o))||n.splice(0,0,{name:t,value:t})),this.emails&&o&&this.isValidEmail(o)&&!n.find((t=>this.getValue(t)&&this.getValue(t).toLowerCase()===o))&&n.splice(0,0,{name:t,value:t}),this.endpoint){let s=this.endpoint;i?s=i:(t&&this.queryParam&&(s.indexOf("?")>-1?s+="&":s+="?",s+=this.queryParam+"="+encodeURIComponent(t)),e&&(s.indexOf("?")>-1?s+="&":s+="?",s+="page="+e));const r=this.lruCache.get(s);if(this.cache&&!this.tags&&!this.emails&&r)return 0!==e||this.next?this.setVisibleOptions([...this.visibleOptions,...r.options]):(this.cursorIndex=0,this.setVisibleOptions([...n,...r.options])),this.complete=r.complete,this.next=r.next,void(this.fetching=!1);this.searchable&&!this.queryParam?Jt(s).then((t=>{t=this.prepareOptions(t),!this.cache||this.tags||this.emails||(this.lruCache.set(s,{options:t,complete:!0,next:null}),this.complete=!0,this.next=null,this.setVisibleOptions([...n,...t]),this.fetching=!1)})):Xt(s).then((i=>{let r=this.getOptions(i).filter((t=>this.isMatch(t,o)));r=this.prepareOptions(r),this.next=null;const a=i.json;a.next&&(this.next=a.next),0!==e||this.next?(r.length>0&&this.setVisibleOptions([...this.visibleOptions,...r]),this.complete=this.isComplete(r,i)):(this.cursorIndex=0,this.setVisibleOptions([...n,...r]),this.query=t,this.complete=this.isComplete(this.visibleOptions,i)),!this.cache||this.tags||this.emails||this.lruCache.set(s,{options:r,complete:this.complete,next:this.next}),this.fetching=!1,this.page=e})).catch((t=>{this.fetching=!1,console.error(t)}))}else this.fetching=!1,this.setVisibleOptions(n)}}handleFocus(){this.focused||0!==this.visibleOptions.length||(this.focused=!0)}handleBlur(){this.focused=!1,this.attemptedOpen=!1,this.visibleOptions.length>0&&(this.input="",this.next=null,this.complete=!0,this.visibleOptions=[],this.cursorIndex=0),this.isMultiMode&&this.maxItems>0&&this.values.length>=this.maxItems&&(this.infoText="")}handleClick(){this.selectedIndex=-1,this.requestUpdate("input")}addInputAsValue(){const t=this.shadowRoot.querySelector(".searchbox"),e={name:t.value,value:t.value,expression:!0};this.isMultiMode?this.values.find((t=>t.expression&&t.value&&e.value&&t.value.toLowerCase().trim()==e.value.toLowerCase().trim()))||this.addValue(e):this.setValues([e]),this.input="",this.isMultiMode||this.blur()}handleKeyDown(t){if("Enter"===t.key&&this.expressions&&0===this.completionOptions.length&&this.input.indexOf("@")>-1)this.addInputAsValue();else if("Enter"===t.key&&this.emails&&this.input&&this.isValidEmail(this.input.trim())&&0===this.visibleOptions.length){t.preventDefault();const e={name:this.input.trim(),value:this.input.trim()};this.setSelectedOption(e)}else{if(("Enter"===t.key||"ArrowDown"===t.key||"n"===t.key&&t.ctrlKey)&&0===this.visibleOptions.length&&0===this.completionOptions.length&&!this.input)return this.attemptedOpen=!0,void this.requestUpdate("input");if(this.isMultiMode&&"Backspace"===t.key&&!this.input){if(this.visibleOptions.length>0)return void(this.visibleOptions=[]);-1===this.selectedIndex?(this.selectedIndex=this.values.length-1,this.visibleOptions=[]):(this.popValue(),this.selectedIndex=-1)}else this.selectedIndex=-1}}getStaticOptions(){return this.staticOptions}handleInput(t){const e=t.currentTarget;this.input=e.value}handleCancel(){this.visibleOptions=[],this.attemptedOpen=!1}handleCursorChanged(t){this.cursorIndex=t.detail.index}handleContainerClick(t){if(this.disabled)return t.stopPropagation(),void t.preventDefault();if(this.focused=!0,"INPUT"!==t.target.tagName){const t=this.shadowRoot.querySelector("input");if(t)return t.click(),void t.focus();this.isOpen()?(this.visibleOptions=[],this.attemptedOpen=!1):(this.attemptedOpen=!0,this.requestUpdate("input"),this.requestUpdate())}}getEventHandlers(){return[{event:je.Canceled,method:this.handleCancel},{event:je.CursorChanged,method:this.handleCursorChanged},{event:"blur",method:this.handleBlur},{event:"focus",method:this.handleFocus}]}handleArrowClick(t){this.disabled||this.isOpen()&&(t.preventDefault(),t.stopPropagation(),this.blur())}renderOptionDefault(t){if(!t)return null;const e=t.icon;return H`
|
|
1052
|
+
`}constructor(){super(),this.hiddenInputs=[],this.inputStyle={},this.multi=!1,this.searchOnFocus=!1,this.placeholder="",this.name="",this.allowCreate=!1,this.nameKey="name",this.valueKey="value",this.maxItems=0,this.maxItemsText="Maximum items reached",this.queryParam=null,this.input="",this.visibleOptions=[],this.completionOptions=[],this.quietMillis=0,this.searchable=!1,this.cache=!0,this.cacheKey="",this.focused=!1,this.disabled=!1,this.attemptedOpen=!1,this.selectedIndex=-1,this.anchorPosition={left:0,top:0},this.tags=!1,this.emails=!1,this.flavor="default",this.infoText="",this.values=[],this.getName=t=>t[this.nameKey||"name"],this.isMatch=this.isMatchDefault,this.getValue=t=>t[this.valueKey||"value"]||t.id,this.sortFunction=null,this.renderOptionDetail=()=>H``,this.renderSelectedItem=this.renderSelectedItemDefault,this.createArbitraryOption=this.createArbitraryOptionDefault,this.getOptions=this.getOptionsDefault,this.prepareOptions=this.prepareOptionsDefault,this.isComplete=this.isCompleteDefault,this.staticOptions=[],this.allowAnchor=!0,this.alphaSort=(t,e)=>this.endpoint?this.getName(t).localeCompare(this.getName(e)):0,this.next=null,this.lruCache=Ve(20,6e4),this.getNameInternal=t=>this.getName(t),this.renderOptionDefault=this.renderOptionDefault.bind(this),this.renderSelectedItemDefault=this.renderSelectedItemDefault.bind(this),this.prepareOptionsDefault=this.prepareOptionsDefault.bind(this),this.isMatchDefault=this.isMatchDefault.bind(this),this.handleOrderChanged=this.handleOrderChanged.bind(this)}prepareOptionsDefault(t){return t}isMatchDefault(t,e){return(this.getName(t)||"").toLowerCase().indexOf(e)>-1}handleSlotChange(){if(this.staticOptions&&0===this.staticOptions.length)for(const t of this.children)if("TEMBA-OPTION"===t.tagName){const e={};for(const i of t.attributes)e[i.name]=i.value;if(e){let t=!1;void 0!==e.selected&&(delete e.selected,t=!0);const i=this.value||this.getAttribute("value");if(i){this.getValue(e)==i&&(t=!0)}this.staticOptions.push(e),t&&(this.isMultiMode?this.addValue(e):this.setValues([e]))}}this.searchable&&0===this.staticOptions.length&&(this.quietMillis=200)}checkSelectedOption(){if(this.value&&0==this.values.length&&0==this.staticOptions.length&&this.endpoint){const t=this.value;this.resolving=!0,Jt(this.endpoint).then((e=>{if(e&&e.length>0){if(t){const i=e.find((e=>this.getValue(e)===t));if(i)return this.resolving=!1,this.fetching=!1,void this.setValues([i])}this.setValues([e[0]]),this.resolving=!1}}))}else this.staticOptions.length>0&&(null!==this.getAttribute("multi")?this.addValue(this.staticOptions[0]):this.getAttribute("value")?this.setSelectedValue(this.getAttribute("value")):this.setValues([this.staticOptions[0]]))}firstUpdated(t){super.firstUpdated(t),this.anchorElement=this.shadowRoot.querySelector(".select-container"),this.anchorExpressions=this.shadowRoot.querySelector("#anchor"),this.shadowRoot.addEventListener("slotchange",this.handleSlotChange.bind(this))}async createOptionPost(t){return ne(this.endpoint,t).then((e=>{if(e.status>=200&&e.status<300)return{json:e.json,payload:t}}))}updated(t){if(super.updated(t),t.has("sorted")&&(this.sortFunction=this.sorted?this.alphaSort:null),t.has("value")&&this.value&&!this.values.length&&this.setSelectedValue(this.value),t.has("values")&&(this.updateInputs(),this.hasChanges(t.get("values")))){const t=[];if(this.allowCreate){const e=this.values.filter((t=>t.arbitrary));for(const i of e)i.arbitrary&&t.push(this.createOptionPost(i));Promise.all(t).then((t=>{for(const i of t)if(i){const t=e.find((t=>t===i.payload));if(t&&(delete t.arbitrary,i.json))for(const e in i.json)t[e]=i.json[e]}for(let t=this.values.length-1;t>=0;t--)this.values[t].arbitrary&&this.values.splice(t,1);this.cacheKey=(new Date).getTime().toString(),this.fireEvent("change")}))}else this.fireEvent("change")}t.has("cacheKey")&&this.lruCache.clear(),t.has("input")&&!t.has("values")&&!t.has("options")&&this.focused&&(this.lastQuery&&window.clearTimeout(this.lastQuery),this.lastQuery=window.setTimeout((()=>{this.expressions&&this.input.indexOf("@")>-1?this.fetchExpressions():this.fetchOptions(this.input)}),this.quietMillis)),this.endpoint&&t.has("fetching")&&(this.fetching||this.isPastFetchThreshold()||this.fireCustomEvent(je.FetchComplete)),(t.has("cursorIndex")||t.has("visibleOptions"))&&this.endpoint&&!this.fetching&&this.isPastFetchThreshold()&&(this.next?this.fetchOptions(null,null,this.next):this.fetchOptions(this.query,this.page+1)),0===this.values.length&&!this.placeholder&&this.staticOptions.length>0&&this.setValues([this.staticOptions[0]])}hasChanges(t){if(void 0===t)return!1;let e;void 0!==t&&(e=(t||[]).map((t=>this.getValue(t))).join(","));return e!==(this.values||[]).map((t=>t.arbitrary||this.getValue(t))).join(",")}setSelectedValue(t){if(this.staticOptions.length>0){const e=this.staticOptions.find((e=>this.getValue(e)===t));e&&this.setValues([e])}else this.checkSelectedOption()}updateInputs(){for(let t=null;t=this.hiddenInputs.pop();)t.remove();if(0===this.values.length)this.value=null;else{const t=this.getAttribute("name");t&&(this.isMultiMode||1!==this.values.length?this.inputRoot.parentElement&&this.values.forEach((e=>{const i=document.createElement("input");i.setAttribute("type","hidden"),i.setAttribute("name",t),i.setAttribute("value",this.serializeValue(e)),this.hiddenInputs.push(i),this.inputRoot.parentElement.appendChild(i)})):(this.selection=this.values[0],this.value=this.serializeValue(this.values[0]),this.internals&&this.internals.setFormValue(this.value)))}}setSelectedOption(t){this.isMultiMode?this.addValue(t):this.setValues([t]),this.isMultiMode&&this.searchable||(this.blur(),this.focused=!1),this.visibleOptions=[],this.attemptedOpen=!1,this.input="",this.next=null,this.complete=!0,this.selectedIndex=-1}isPastFetchThreshold(){return(this.visibleOptions.length>0||this.next)&&!this.complete&&(this.cursorIndex||0)>this.visibleOptions.length-20}handleOptionSelection(t){if(this.isMultiMode&&this.maxItems>0&&this.values.length>=this.maxItems)return void(this.infoText=this.maxItemsText);this.infoText="";const e=t.detail.selected;e.post&&this.endpoint?ne(this.endpoint,e).then((t=>{t.status>=200&&t.status<300?(this.setSelectedOption(t.json),this.lruCache=Ve(20,6e4)):this.blur()})):this.setSelectedOption(e)}handleExpressionSelection(t){const e=t.detail.selected,i=t.detail.tabbed,n=this.shadowRoot.querySelector(".searchbox");bc(this.query,n,e),this.query="",this.completionOptions=[],i?this.fetchExpressions():-1===this.input.indexOf("(")&&this.addInputAsValue()}getOptionsDefault(t){return t.json.results}isCompleteDefault(t,e){const i=e.json;return!i.more&&!i.next}handleRemoveSelection(t){this.removeValue(t),this.visibleOptions=[]}createArbitraryOptionDefault(t,e){return this.emails&&t&&this.isValidEmail(t)||this.tags&&t?{name:t,value:t}:null}isValidEmail(t){return/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(t)}get isMultiMode(){return this.multi||this.emails}open(){this.shadowRoot.querySelector(".select-container").click()}isOpen(){return this.visibleOptions.length>0||this.attemptedOpen&&this.focused}setOptions(t){this.staticOptions=t}setVisibleOptions(t){if(t=t.filter((t=>!!this.getNameInternal(t)&&(!this.shouldExclude||!this.shouldExclude(t)))),this.input){if(this.searchable&&!this.queryParam){const e=this.input.trim().toLowerCase();t=t.filter((t=>this.isMatch(t,e)))}const e=this.createArbitraryOption(this.input,t);if(e){e.arbitrary=!0;t.find((t=>this.getValue(t)===this.getValue(e)))||(t.length>0&&t[0].arbitrary?t[0]=e:t.unshift(e))}}this.values.length>0&&(this.isMultiMode?t=t.filter((t=>!this.values.find((e=>this.getValue(e)===this.getValue(t))))):(this.input?this.cursorIndex=0:this.cursorIndex=t.findIndex((t=>this.getValue(t)===this.getValue(this.values[0]))),this.requestUpdate("cursorIndex"))),this.isMultiMode&&this.maxItems>0&&this.values.length>=this.maxItems&&(t=[],this.infoText=this.maxItemsText),this.sortFunction&&t.sort(this.sortFunction),this.visibleOptions=t,this.fireCustomEvent(je.ContentChanged,{options:this.visibleOptions})}fetchExpressions(){const t=document.querySelector("temba-store");if(this.expressions&&t){const t=this.shadowRoot.querySelector(".searchbox"),e=xc(t,"session"===this.expressions);return this.query=e.query,this.completionOptions=e.options,this.visibleOptions=[],this.anchorPosition=e.anchorPosition,void this.fireCustomEvent(je.FetchComplete)}}fetchOptions(t,e=0,i=null){if(this.completionOptions=[],!this.fetching){this.fetching=!0;const n=[...this.staticOptions],o=(t||"").trim().toLowerCase();if(this.tags&&o&&(n.find((t=>this.getValue(t)&&this.getValue(t).toLowerCase()===o))||n.splice(0,0,{name:t,value:t})),this.emails&&o&&this.isValidEmail(o)&&!n.find((t=>this.getValue(t)&&this.getValue(t).toLowerCase()===o))&&n.splice(0,0,{name:t,value:t}),this.endpoint){let s=this.endpoint;i?s=i:(t&&this.queryParam&&(s.indexOf("?")>-1?s+="&":s+="?",s+=this.queryParam+"="+encodeURIComponent(t)),e&&(s.indexOf("?")>-1?s+="&":s+="?",s+="page="+e));const r=this.lruCache.get(s);if(this.cache&&!this.tags&&!this.emails&&r)return 0!==e||this.next?this.setVisibleOptions([...this.visibleOptions,...r.options]):(this.cursorIndex=0,this.setVisibleOptions([...n,...r.options])),this.complete=r.complete,this.next=r.next,void(this.fetching=!1);this.searchable&&!this.queryParam?Jt(s).then((t=>{t=this.prepareOptions(t),!this.cache||this.tags||this.emails||(this.lruCache.set(s,{options:t,complete:!0,next:null}),this.complete=!0,this.next=null,this.setVisibleOptions([...n,...t]),this.fetching=!1)})):Xt(s).then((i=>{let r=this.getOptions(i).filter((t=>this.isMatch(t,o)));r=this.prepareOptions(r),this.next=null;const a=i.json;a.next&&(this.next=a.next),0!==e||this.next?(r.length>0&&this.setVisibleOptions([...this.visibleOptions,...r]),this.complete=this.isComplete(r,i)):(this.cursorIndex=0,this.setVisibleOptions([...n,...r]),this.query=t,this.complete=this.isComplete(this.visibleOptions,i)),!this.cache||this.tags||this.emails||this.lruCache.set(s,{options:r,complete:this.complete,next:this.next}),this.fetching=!1,this.page=e})).catch((t=>{this.fetching=!1,console.error(t)}))}else this.fetching=!1,this.setVisibleOptions(n)}}handleFocus(){this.focused||0!==this.visibleOptions.length||(this.focused=!0)}handleBlur(){this.focused=!1,this.attemptedOpen=!1,this.visibleOptions.length>0&&(this.input="",this.next=null,this.complete=!0,this.visibleOptions=[],this.cursorIndex=0),this.isMultiMode&&this.maxItems>0&&this.values.length>=this.maxItems&&(this.infoText="")}handleClick(){this.selectedIndex=-1,this.requestUpdate("input")}addInputAsValue(){const t=this.shadowRoot.querySelector(".searchbox"),e={name:t.value,value:t.value,expression:!0};this.isMultiMode?this.values.find((t=>t.expression&&t.value&&e.value&&t.value.toLowerCase().trim()==e.value.toLowerCase().trim()))||this.addValue(e):this.setValues([e]),this.input="",this.isMultiMode||this.blur()}handleKeyDown(t){if("Enter"===t.key&&this.expressions&&0===this.completionOptions.length&&this.input.indexOf("@")>-1)this.addInputAsValue();else if("Enter"===t.key&&this.emails&&this.input&&this.isValidEmail(this.input.trim())&&0===this.visibleOptions.length){t.preventDefault();const e={name:this.input.trim(),value:this.input.trim()};this.setSelectedOption(e)}else{if(("Enter"===t.key||"ArrowDown"===t.key||"n"===t.key&&t.ctrlKey)&&0===this.visibleOptions.length&&0===this.completionOptions.length&&!this.input)return this.attemptedOpen=!0,void this.requestUpdate("input");if(this.isMultiMode&&"Backspace"===t.key&&!this.input){if(this.visibleOptions.length>0)return void(this.visibleOptions=[]);-1===this.selectedIndex?(this.selectedIndex=this.values.length-1,this.visibleOptions=[]):(this.popValue(),this.selectedIndex=-1)}else this.selectedIndex=-1}}getStaticOptions(){return this.staticOptions}handleInput(t){const e=t.currentTarget;this.input=e.value}handleCancel(){this.visibleOptions=[],this.attemptedOpen=!1}handleCursorChanged(t){this.cursorIndex=t.detail.index}handleContainerClick(t){if(this.disabled)return t.stopPropagation(),void t.preventDefault();if(this.focused=!0,"INPUT"!==t.target.tagName){const t=this.shadowRoot.querySelector("input");if(t)return t.click(),void t.focus();this.isOpen()?(this.visibleOptions=[],this.attemptedOpen=!1):(this.attemptedOpen=!0,this.requestUpdate("input"),this.requestUpdate())}}getEventHandlers(){return[{event:je.Canceled,method:this.handleCancel},{event:je.CursorChanged,method:this.handleCursorChanged},{event:"blur",method:this.handleBlur},{event:"focus",method:this.handleFocus}]}handleArrowClick(t){this.disabled||this.isOpen()&&(t.preventDefault(),t.stopPropagation(),this.blur())}renderOptionDefault(t){if(!t)return null;const e=t.icon;return H`
|
|
1053
1053
|
<div
|
|
1054
1054
|
class="option-name"
|
|
1055
1055
|
style="flex: 1 1 auto;
|
|
@@ -1065,7 +1065,7 @@ let Ar=rr,Mr=!1;const Tr=["es","fr","pt"],Pr="data:image/png;base64,iVBORw0KGgoA
|
|
|
1065
1065
|
style="margin-right:0.5em;"
|
|
1066
1066
|
></temba-icon>`:null}<span>${this.getName(t)}</span>
|
|
1067
1067
|
</div>
|
|
1068
|
-
`}renderSelectedItemDefault(t){return(this.renderOption||this.renderOptionDefault)(t,!0)}serializeValue(t){return!this.jsonValue&&(this.staticOptions.length>0||this.isMultiMode)?t.value:super.serializeValue(t)}setSelection(t){for(const e of this.staticOptions)if(this.getValue(e)===t)return void(0!==this.values.length&&this.values[0].value==""+t||this.setValues([e]))}handleClear(t){t.preventDefault(),t.stopPropagation(),this.setValues([]),this.visibleOptions.length>0&&(this.visibleOptions=[],this.requestUpdate()),this.fireCustomEvent(je.Selection,{selected:null})}setValues(t){const e=this.values;this.values
|
|
1068
|
+
`}renderSelectedItemDefault(t){return(this.renderOption||this.renderOptionDefault)(t,!0)}serializeValue(t){return!this.jsonValue&&(this.staticOptions.length>0||this.isMultiMode)?t.value:super.serializeValue(t)}setSelection(t){for(const e of this.staticOptions)if(this.getValue(e)===t)return void(0!==this.values.length&&this.values[0].value==""+t||this.setValues([e]))}handleClear(t){t.preventDefault(),t.stopPropagation(),this.setValues([]),this.visibleOptions.length>0&&(this.visibleOptions=[],this.requestUpdate()),this.fireCustomEvent(je.Selection,{selected:null})}setValues(t){const e=this.values;this.values.splice(0,this.values.length,...t),this.requestUpdate("values",e),this.updateInputs(),this.fireEvent("change")}addValue(t){const e=[...this.values];this.values.push(t),this.requestUpdate("values",e),this.updateInputs(),this.fireEvent("change")}removeValue(t){const e=[...this.values],i=this.values.indexOf(t);if(i>-1){this.values.splice(i,1);const e=this.getValue(t);for(const t of this.children)if("TEMBA-OPTION"===t.tagName){if(t.getAttribute("value")===e){t.removeAttribute("selected");break}}}this.requestUpdate("values",e),this.infoText="",this.updateInputs(),this.fireEvent("change")}popValue(){const t=[...this.values];this.values.pop(),this.requestUpdate("values",t),this.infoText="",this.updateInputs(),this.fireEvent("change")}clear(){const t=this.values;this.values.splice(0,this.values.length),this.requestUpdate("values",t),this.updateInputs(),this.fireEvent("change")}shouldShowEmptyMessage(){return this.attemptedOpen&&this.focused&&0===this.visibleOptions.length&&!this.input&&0===this.staticOptions.length&&!this.endpoint}handleOrderChanged(t){const e=t.detail;if(e.swap&&Array.isArray(e.swap)&&2===e.swap.length){const[t,i]=e.swap;if(t!==i&&t>=0&&i>=0&&t<this.values.length&&i<this.values.length){const e=[...this.values],n=this.values.splice(t,1)[0];this.values.splice(i,0,n),this.requestUpdate("values",e),this.updateInputs(),this.fireEvent("change")}}}render(){const t=0===this.values.length?this.placeholder:"",e=H`
|
|
1069
1069
|
<div class="placeholder">${t}</div>
|
|
1070
1070
|
`,i=this.clearable&&this.values.length>0&&!this.isMultiMode?H`<temba-icon
|
|
1071
1071
|
name="${Ee.select_clear}"
|
|
@@ -2924,7 +2924,7 @@ let Ar=rr,Mr=!1;const Tr=["es","fr","pt"],Pr="data:image/png;base64,iVBORw0KGgoA
|
|
|
2924
2924
|
temba-button {
|
|
2925
2925
|
--button-border: 1px solid #ddd;
|
|
2926
2926
|
}
|
|
2927
|
-
`}constructor(){super(),this.contactsEndpoint="/api/v2/contacts.json",this.currentNote="",this.showDetails=!0,this.currentTicket=null,this.currentContact=null,this.agent="",this.blockFetching=!1,this.showInterrupt=!1,this.avatar=Pr,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1}firstUpdated(t){super.firstUpdated(t)}connectedCallback(){super.connectedCallback(),this.chat=this.shadowRoot.querySelector("temba-chat")}disconnectedCallback(){super.disconnectedCallback(),this.refreshId&&clearInterval(this.refreshId)}updated(t){super.updated(t),(t.has("data")||t.has("currentContact"))&&(this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),this.currentContact=this.data),t.has("currentContact")&&(this.chat=this.shadowRoot.querySelector("temba-chat"),this.reset(),this.fetchPreviousMessages())}reset(){this.chat&&this.chat.reset(),this.blockFetching=!1,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1,this.errorMessage=null;const t=this.shadowRoot.querySelector("temba-compose");t&&t.reset()}handleInterrupt(){this.fireCustomEvent(je.Interrupt,{contact:this.currentContact})}handleRetry(){this.shadowRoot.querySelector("temba-compose").triggerSend()}handleSend(t){this.errorMessage=null;const e=t.currentTarget,i=t.detail.langValues.und,n={contact:this.currentContact.uuid},o=i.text;o&&o.length>0&&(n.text=o);const s=i.attachments;if(s&&s.length>0){const t=s.map((t=>t.uuid));n.attachments=t}this.currentTicket&&(n.ticket=this.currentTicket.uuid);const r="Send failed, please try again.";ne("/api/v2/messages.json",n).then((t=>{t.status<400?(this.checkForNewMessages(),e.reset(),this.fireCustomEvent(je.MessageSent,{msg:n})):this.errorMessage=r})).catch((()=>{this.errorMessage=r}))}getEndpoint(){return this.contact?`/contact/history/${this.contact}/?_format=json`:null}scheduleRefresh(){let t=(new Date).getTime()-this.newestEventTime/1e3-5e3;this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),t=Math.min(t,15e3),t=Math.max(t,2e3),this.refreshId=setTimeout((()=>{this.checkForNewMessages()}),t)}getEventMessage(t){let e=null;switch(t.type){case Zc.TICKET_OPENED:e={type:Vc.Inline,text:eh(t,"opened")};break;case Zc.TICKET_ASSIGNED:e={type:Vc.Inline,text:ih(t)};break;case Zc.TICKET_REOPENED:e={type:Vc.Inline,text:eh(t,"reopened")};break;case Zc.TICKET_CLOSED:e={type:Vc.Inline,text:eh(t,"closed")};break;case Zc.TICKET_TOPIC_CHANGED:e={type:Vc.Inline,text:`Topic changed to **${t.topic.name}**`};break;case Zc.FLOW_ENTERED:case Zc.FLOW_EXITED:e={type:Vc.Inline,text:Kc(t)};break;case Zc.CONTACT_FIELD_CHANGED:e={type:Vc.Inline,text:Qc(t)};break;case Zc.CONTACT_NAME_CHANGED:e={type:Vc.Inline,text:Jc(t)};break;case Zc.CONTACT_URNS_CHANGED:e={type:Vc.Inline,text:th(t)};break;case Zc.CONTACT_GROUPS_CHANGED:e={type:Vc.Inline,text:nh(t)};break;case Zc.AIRTIME_TRANSFERRED:e={type:Vc.Inline,text:oh(t)};break;case Zc.CALL_STARTED:e={type:Vc.Inline,text:"Call Started"};break;case Zc.CHANNEL_EVENT:e={type:Vc.Inline,text:Xc(t)};break;case Zc.CONTACT_LANGUAGE_CHANGED:e={type:Vc.Inline,text:sh(t)};break;case Zc.OPTIN_REQUESTED:e={type:Vc.Inline,text:rh(t)}}return e&&t.created_on?e.date=new Date(t.created_on):console.error("Unknown event type",t),e}getUserForEvent(t){let e=null;return"msg_received"===t.type?e={name:this.currentContact.name}:t.created_by&&(e={email:t.created_by.email,name:`${t.created_by.first_name} ${t.created_by.last_name}`.trim(),avatar:t.created_by.avatar}),e}createMessages(t){if(t.events){let e=[];return t.events.forEach((t=>{const i=1e3*new Date(t.created_on).getTime();if(i>this.newestEventTime&&(this.newestEventTime=i),"ticket_note_added"===t.type){const i=t;e.push({type:Vc.Note,id:t.created_on+t.type,user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note})}else if("ticket_opened"===t.type){const i=t;e.push({type:Vc.Note,id:t.created_on+t.type+"_note",user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note}),e.push(this.getEventMessage(t))}else if("msg_created"===t.type||"msg_received"===t.type||"broadcast_created"===t.type){const i=t;e.push({
|
|
2927
|
+
`}constructor(){super(),this.contactsEndpoint="/api/v2/contacts.json",this.currentNote="",this.showDetails=!0,this.currentTicket=null,this.currentContact=null,this.agent="",this.blockFetching=!1,this.showInterrupt=!1,this.avatar=Pr,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1}firstUpdated(t){super.firstUpdated(t)}connectedCallback(){super.connectedCallback(),this.chat=this.shadowRoot.querySelector("temba-chat")}disconnectedCallback(){super.disconnectedCallback(),this.refreshId&&clearInterval(this.refreshId)}updated(t){super.updated(t),(t.has("data")||t.has("currentContact"))&&(this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),this.currentContact=this.data),t.has("currentContact")&&(this.chat=this.shadowRoot.querySelector("temba-chat"),this.reset(),this.fetchPreviousMessages())}reset(){this.chat&&this.chat.reset(),this.blockFetching=!1,this.ticket=null,this.lastEventTime=null,this.newestEventTime=null,this.refreshId=null,this.polling=!1,this.errorMessage=null;const t=this.shadowRoot.querySelector("temba-compose");t&&t.reset()}handleInterrupt(){this.fireCustomEvent(je.Interrupt,{contact:this.currentContact})}handleRetry(){this.shadowRoot.querySelector("temba-compose").triggerSend()}handleSend(t){this.errorMessage=null;const e=t.currentTarget,i=t.detail.langValues.und,n={contact:this.currentContact.uuid},o=i.text;o&&o.length>0&&(n.text=o);const s=i.attachments;if(s&&s.length>0){const t=s.map((t=>t.uuid));n.attachments=t}this.currentTicket&&(n.ticket=this.currentTicket.uuid);const r="Send failed, please try again.";ne("/api/v2/messages.json",n).then((t=>{t.status<400?(this.checkForNewMessages(),e.reset(),this.fireCustomEvent(je.MessageSent,{msg:n})):this.errorMessage=r})).catch((()=>{this.errorMessage=r}))}getEndpoint(){return this.contact?`/contact/history/${this.contact}/?_format=json`:null}scheduleRefresh(){let t=(new Date).getTime()-this.newestEventTime/1e3-5e3;this.refreshId&&(clearTimeout(this.refreshId),this.refreshId=null),t=Math.min(t,15e3),t=Math.max(t,2e3),this.refreshId=setTimeout((()=>{this.checkForNewMessages()}),t)}getEventMessage(t){let e=null;switch(t.type){case Zc.TICKET_OPENED:e={type:Vc.Inline,text:eh(t,"opened")};break;case Zc.TICKET_ASSIGNED:e={type:Vc.Inline,text:ih(t)};break;case Zc.TICKET_REOPENED:e={type:Vc.Inline,text:eh(t,"reopened")};break;case Zc.TICKET_CLOSED:e={type:Vc.Inline,text:eh(t,"closed")};break;case Zc.TICKET_TOPIC_CHANGED:e={type:Vc.Inline,text:`Topic changed to **${t.topic.name}**`};break;case Zc.FLOW_ENTERED:case Zc.FLOW_EXITED:e={type:Vc.Inline,text:Kc(t)};break;case Zc.CONTACT_FIELD_CHANGED:e={type:Vc.Inline,text:Qc(t)};break;case Zc.CONTACT_NAME_CHANGED:e={type:Vc.Inline,text:Jc(t)};break;case Zc.CONTACT_URNS_CHANGED:e={type:Vc.Inline,text:th(t)};break;case Zc.CONTACT_GROUPS_CHANGED:e={type:Vc.Inline,text:nh(t)};break;case Zc.AIRTIME_TRANSFERRED:e={type:Vc.Inline,text:oh(t)};break;case Zc.CALL_STARTED:e={type:Vc.Inline,text:"Call Started"};break;case Zc.CHANNEL_EVENT:e={type:Vc.Inline,text:Xc(t)};break;case Zc.CONTACT_LANGUAGE_CHANGED:e={type:Vc.Inline,text:sh(t)};break;case Zc.OPTIN_REQUESTED:e={type:Vc.Inline,text:rh(t)}}return e&&t.created_on?e.date=new Date(t.created_on):console.error("Unknown event type",t),e}getUserForEvent(t){let e=null;return"msg_received"===t.type?e={name:this.currentContact.name}:t.created_by&&(e={email:t.created_by.email,name:`${t.created_by.first_name} ${t.created_by.last_name}`.trim(),avatar:t.created_by.avatar}),e}createMessages(t){if(t.events){let e=[];return t.events.forEach((t=>{const i=1e3*new Date(t.created_on).getTime();if(i>this.newestEventTime&&(this.newestEventTime=i),"ticket_note_added"===t.type){const i=t;e.push({type:Vc.Note,id:t.created_on+t.type,user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note})}else if("ticket_opened"===t.type){const i=t;e.push({type:Vc.Note,id:t.created_on+t.type+"_note",user:this.getUserForEvent(i),date:new Date(i.created_on),text:i.note}),e.push(this.getEventMessage(t))}else if("msg_created"===t.type||"msg_received"===t.type||"broadcast_created"===t.type){const i=t;e.push({id:t.uuid,type:"msg_received"===i.type?"msg_in":"msg_out",user:this.getUserForEvent(i),date:new Date(i.created_on),attachments:i.msg.attachments,text:i.msg.text,sendError:"E"===i.status||"F"===i.status,popup:H`<div
|
|
2928
2928
|
style="display: flex; flex-direction: row; align-items:center; justify-content: space-between;font-size:0.9em;line-height:1em;min-width:10em"
|
|
2929
2929
|
>
|
|
2930
2930
|
<div style="justify-content:left;text-align:left">
|
|
@@ -9848,7 +9848,7 @@ var hA=function(){if("undefined"!=typeof window){if(window.devicePixelRatio)retu
|
|
|
9848
9848
|
color: var(--color-error, tomato);
|
|
9849
9849
|
margin-right: 8px;
|
|
9850
9850
|
}
|
|
9851
|
-
`}connectedCallback(){super.connectedCallback(),this.initializeFormData()}updated(t){super.updated(t),(t.has("node")||t.has("action"))&&(this.node||this.action?this.openDialog():this.isOpen=!1)}openDialog(){this.initializeFormData(),this.errors={},this.isOpen=!0}closeDialog(){this.isOpen=!1,this.formData={},this.errors={},this.groupCollapseState={}}initializeFormData(){if(this.action){const t=Cb[this.action.type];(null==t?void 0:t.toFormData)?this.formData=t.toFormData(this.action):(this.formData={...this.action},this.applySmartSelectTransformations(t)),this.processFormDataForEditing(),this.originalFormData=JSON.parse(JSON.stringify(this.formData))}else if(this.node){const t=this.getNodeConfig();(null==t?void 0:t.toFormData)?this.formData=t.toFormData(this.node):this.formData={...this.node},this.processFormDataForEditing(),this.originalFormData=JSON.parse(JSON.stringify(this.formData))}}processFormDataForEditing(){const t={...this.formData};Object.keys(t).forEach((e=>{const i=t[e];if(i&&"object"==typeof i&&!Array.isArray(i)){this.isKeyValueField(e)&&(t[e]=Object.entries(i).map((([t,e])=>({key:t,value:e}))))}})),this.formData=t}applySmartSelectTransformations(t){if(!t)return;const e=t.form;e&&Object.entries(e).forEach((([t,e])=>{if(this.shouldApplySmartSelectTransformation(t,e)){const e=this.formData[t];Array.isArray(e)&&e.length>0&&"string"==typeof e[0]&&(this.formData[t]=e.map((t=>({name:t,value:t}))))}}))}shouldApplySmartSelectTransformation(t,e){var i;const n=e;return"select"===e.type&&(n.multi||n.tags)&&!this.action||!(null===(i=Cb[this.action.type])||void 0===i?void 0:i.toFormData)}isKeyValueField(t){var e;if(this.action){const i=Cb[this.action.type],n=null==i?void 0:i.form;return"key-value"===(null===(e=null==n?void 0:n[t])||void 0===e?void 0:e.type)}return!1}getNodeConfig(){return this.nodeUI&&this.nodeUI.type?Sb[this.nodeUI.type]:null}getHeaderColor(){if(this.action){const t=Cb[this.action.type];return(null==t?void 0:t.color)||"#666666"}if(this.node){const t=this.getNodeConfig();return(null==t?void 0:t.color)||"#666666"}return"#666666"}handleDialogButtonClick(t){const e=t.detail.button;"Save"===e.name?this.handleSave():"Cancel"===e.name&&this.handleCancel()}handleSave(){const t=this.validateForm();if(!t.valid)return this.errors=t.errors,void this.expandGroupsWithErrors(t.errors);const e=this.processFormDataForSave();if(this.node&&this.node.router){const t=this.formDataToNode(e);this.fireCustomEvent(je.NodeSaved,{node:t})}else if(this.action){const t=this.formDataToAction(e);this.fireCustomEvent(je.ActionSaved,{action:t})}else if(this.node){const t=this.formDataToNode(e);this.fireCustomEvent(je.NodeSaved,{node:t})}}processFormDataForSave(){const t={...this.formData};return Object.keys(t).forEach((e=>{const i=t[e];if(Array.isArray(i)&&i.length>0&&"object"==typeof i[0]&&"key"in i[0]&&"value"in i[0]){const n={};i.forEach((({key:t,value:e})=>{""===t.trim()&&""===e.trim()||(n[t]=e)})),t[e]=n}else if(Array.isArray(i)&&0===i.length){this.isKeyValueField(e)&&(t[e]={})}})),t}handleCancel(){this.fireCustomEvent(je.NodeEditCancelled,{})}validateForm(){const t={};if(this.action){const e=Cb[this.action.type];if((null==e?void 0:e.form)&&Object.entries(null==e?void 0:e.form).forEach((([e,i])=>{const n=this.formData[e];i.required&&(!n||Array.isArray(n)&&0===n.length)&&(t[e]=`${i.label||e} is required`),"string"==typeof n&&i.minLength&&n.length<i.minLength&&(t[e]=`${i.label||e} must be at least ${i.minLength} characters`),"string"==typeof n&&i.maxLength&&n.length>i.maxLength&&(t[e]=`${i.label||e} must be no more than ${i.maxLength} characters`)})),null==e?void 0:e.validate){let i;i=e.fromFormData?e.fromFormData(this.formData):{...this.action,...this.formData};const n=e.validate(i);Object.assign(t,n.errors)}}else if(this.node){const e=this.getNodeConfig();(null==e?void 0:e.properties)&&Object.entries(e.properties).forEach((([e,i])=>{const n=this.formData[e];i.required&&(!n||Array.isArray(n)&&0===n.length)&&(t[e]=`${i.label||e} is required`)}))}return this.validateKeyValueUniqueness(t),{valid:0===Object.keys(t).length,errors:t}}validateKeyValueUniqueness(t){Object.entries(this.formData).forEach((([e,i])=>{if(Array.isArray(i)&&i.length>0&&"object"==typeof i[0]&&"key"in i[0]&&"value"in i[0]){let n=!1;i.forEach((({key:t,value:e})=>{""===t.trim()&&""!==e.trim()&&(n=!0)}));const o=i.filter((({key:t})=>""!==t.trim())).map((({key:t})=>t.trim())),s=new Set(o);o.length!==s.size&&(n=!0),n&&(t[e]="Please resolve validation errors to continue")}}))}formDataToNode(t=this.formData){var e;if(!this.node)throw new Error("No node to update");let i={...this.node};if(this.node.actions&&this.node.actions.length>0&&(i.actions=this.node.actions.map((e=>{if(this.action&&e.uuid===this.action.uuid){const i=Cb[e.type];return(null==i?void 0:i.fromFormData)?i.fromFormData(t):{...e,...t}}return e}))),this.node.router){const n=this.getNodeConfig();if(null==n?void 0:n.fromFormData)i=n.fromFormData(t,i);else if(i.router={...this.node.router},void 0!==t.result_name&&(i.router.result_name=t.result_name),null===(e=null==n?void 0:n.router)||void 0===e?void 0:e.rules){const t=i.router.categories||[],e=i.exits||[],o=[],s=[],r=new Map;if(n.router.rules.forEach((t=>{r.has(t.categoryName)||r.set(t.categoryName,[]),r.get(t.categoryName).push(t)})),r.forEach(((i,n)=>{const r=t.find((t=>t.name===n));if(r){o.push(r);const t=e.find((t=>t.uuid===r.exit_uuid));t&&s.push(t)}else{const t=Ut(),e=Ut();o.push({uuid:t,name:n,exit_uuid:e}),s.push({uuid:e,destination_uuid:null})}})),n.router.defaultCategory){if(!o.find((t=>t.name===n.router.defaultCategory))){const i=t.find((t=>t.name===n.router.defaultCategory));if(i){o.push(i);const t=e.find((t=>t.uuid===i.exit_uuid));t&&s.push(t)}else{const t=Ut(),e=Ut();o.push({uuid:t,name:n.router.defaultCategory,exit_uuid:e}),s.push({uuid:e,destination_uuid:null})}}}i.router.categories=o,i.exits=s}}else Object.keys(t).forEach((e=>{"uuid"!==e&&"actions"!==e&&"exits"!==e&&"router"!==e&&(i[e]=t[e])}));return i}formDataToAction(t=this.formData){if(!this.action)throw new Error("No action to update");const e=Cb[this.action.type];if(null==e?void 0:e.fromFormData)return e.fromFormData(t);{const i=this.reverseSmartSelectTransformations(t,e);return{...this.action,...i}}}reverseSmartSelectTransformations(t,e){if(!e||!e.form)return t;const i={...t};return Object.entries(e.form).forEach((([t,e])=>{if(this.shouldApplySmartSelectTransformation(t,e)){const e=i[t];Array.isArray(e)&&e.length>0&&"object"==typeof e[0]&&"value"in e[0]&&(i[t]=e.map((t=>t.value||t.name||t)))}})),i}handleFormFieldChange(t,e){const i=e.target;let n;if(n="TEMBA-CHECKBOX"===i.tagName?i.checked:"TEMBA-SELECT"===i.tagName&&(i.multi||i.emails||i.tags)?i.values||[]:void 0!==i.values?i.values:i.value,this.formData={...this.formData,[t]:n},this.errors[t]){const e={...this.errors};delete e[t],this.errors=e}this.updateComputedFields(t),this.requestUpdate()}updateComputedFields(t){if(!this.action)return;const e=Cb[this.action.type];(null==e?void 0:e.form)&&Object.entries(e.form).forEach((([e,i])=>{var n;if((null===(n=i.dependsOn)||void 0===n?void 0:n.includes(t))&&i.computeValue){const t=this.formData[e],n=i.computeValue(this.formData,t,this.originalFormData);this.formData={...this.formData,[e]:n}}}))}renderNewField(t,e,i){var n;if(null===(n=e.conditions)||void 0===n?void 0:n.visible)try{if(!e.conditions.visible(this.formData))return H``}catch(e){console.error(`Error checking visibility for ${t}:`,e)}const o=this.errors[t]?[this.errors[t]]:[],s=e.maxWidth?`max-width: ${e.maxWidth};`:"",r=this.renderFieldContent(t,e,i,o);return s?H`<div style="${s}">${r}</div>`:r}renderFieldContent(t,e,i,n){var o;switch(e.type){case"text":return H`<temba-textinput
|
|
9851
|
+
`}connectedCallback(){super.connectedCallback(),this.initializeFormData()}updated(t){super.updated(t),(t.has("node")||t.has("action"))&&(this.node||this.action?this.openDialog():this.isOpen=!1)}openDialog(){this.initializeFormData(),this.errors={},this.isOpen=!0}closeDialog(){this.isOpen=!1,this.formData={},this.errors={},this.groupCollapseState={}}initializeFormData(){if(this.action){const t=Cb[this.action.type];(null==t?void 0:t.toFormData)?this.formData=t.toFormData(this.action):(this.formData={...this.action},this.applySmartSelectTransformations(t)),this.processFormDataForEditing(),this.originalFormData=JSON.parse(JSON.stringify(this.formData))}else if(this.node){const t=this.getNodeConfig();(null==t?void 0:t.toFormData)?this.formData=t.toFormData(this.node):this.formData={...this.node},this.processFormDataForEditing(),this.originalFormData=JSON.parse(JSON.stringify(this.formData))}Object.keys(this.formData).forEach((t=>{const e=this.formData[t];Array.isArray(e)?this.formData[t]=[...e]:e&&"object"==typeof e&&(this.formData[t]={...e})}))}processFormDataForEditing(){const t={...this.formData};Object.keys(t).forEach((e=>{const i=t[e];if(i&&"object"==typeof i&&!Array.isArray(i)){this.isKeyValueField(e)&&(t[e]=Object.entries(i).map((([t,e])=>({key:t,value:e}))))}})),this.formData=t}applySmartSelectTransformations(t){if(!t)return;const e=t.form;e&&Object.entries(e).forEach((([t,e])=>{if(this.shouldApplySmartSelectTransformation(t,e)){const e=this.formData[t];Array.isArray(e)&&e.length>0&&"string"==typeof e[0]&&(this.formData[t]=e.map((t=>({name:t,value:t}))))}}))}shouldApplySmartSelectTransformation(t,e){var i;const n=e;return"select"===e.type&&(n.multi||n.tags)&&!this.action||!(null===(i=Cb[this.action.type])||void 0===i?void 0:i.toFormData)}isKeyValueField(t){var e;if(this.action){const i=Cb[this.action.type],n=null==i?void 0:i.form;return"key-value"===(null===(e=null==n?void 0:n[t])||void 0===e?void 0:e.type)}return!1}getNodeConfig(){return this.nodeUI&&this.nodeUI.type?Sb[this.nodeUI.type]:null}getHeaderColor(){if(this.action){const t=Cb[this.action.type];return(null==t?void 0:t.color)||"#666666"}if(this.node){const t=this.getNodeConfig();return(null==t?void 0:t.color)||"#666666"}return"#666666"}handleDialogButtonClick(t){const e=t.detail.button;"Save"===e.name?this.handleSave():"Cancel"===e.name&&this.handleCancel()}handleSave(){const t=this.validateForm();if(!t.valid)return this.errors=t.errors,void this.expandGroupsWithErrors(t.errors);const e=this.processFormDataForSave();if(this.node&&this.node.router){const t=this.formDataToNode(e);this.fireCustomEvent(je.NodeSaved,{node:t})}else if(this.action){const t=this.formDataToAction(e);this.fireCustomEvent(je.ActionSaved,{action:t})}else if(this.node){const t=this.formDataToNode(e);this.fireCustomEvent(je.NodeSaved,{node:t})}}processFormDataForSave(){const t={...this.formData};return Object.keys(t).forEach((e=>{const i=t[e];if(Array.isArray(i)&&i.length>0&&"object"==typeof i[0]&&"key"in i[0]&&"value"in i[0]){const n={};i.forEach((({key:t,value:e})=>{""===t.trim()&&""===e.trim()||(n[t]=e)})),t[e]=n}else if(Array.isArray(i)&&0===i.length){this.isKeyValueField(e)&&(t[e]={})}})),t}handleCancel(){this.fireCustomEvent(je.NodeEditCancelled,{})}validateForm(){const t={};if(this.action){const e=Cb[this.action.type];if((null==e?void 0:e.form)&&Object.entries(null==e?void 0:e.form).forEach((([e,i])=>{const n=this.formData[e];i.required&&(!n||Array.isArray(n)&&0===n.length)&&(t[e]=`${i.label||e} is required`),"string"==typeof n&&i.minLength&&n.length<i.minLength&&(t[e]=`${i.label||e} must be at least ${i.minLength} characters`),"string"==typeof n&&i.maxLength&&n.length>i.maxLength&&(t[e]=`${i.label||e} must be no more than ${i.maxLength} characters`)})),null==e?void 0:e.validate){let i;i=e.fromFormData?e.fromFormData(this.formData):{...this.action,...this.formData};const n=e.validate(i);Object.assign(t,n.errors)}}else if(this.node){const e=this.getNodeConfig();(null==e?void 0:e.properties)&&Object.entries(e.properties).forEach((([e,i])=>{const n=this.formData[e];i.required&&(!n||Array.isArray(n)&&0===n.length)&&(t[e]=`${i.label||e} is required`)}))}return this.validateKeyValueUniqueness(t),{valid:0===Object.keys(t).length,errors:t}}validateKeyValueUniqueness(t){Object.entries(this.formData).forEach((([e,i])=>{if(Array.isArray(i)&&i.length>0&&"object"==typeof i[0]&&"key"in i[0]&&"value"in i[0]){let n=!1;i.forEach((({key:t,value:e})=>{""===t.trim()&&""!==e.trim()&&(n=!0)}));const o=i.filter((({key:t})=>""!==t.trim())).map((({key:t})=>t.trim())),s=new Set(o);o.length!==s.size&&(n=!0),n&&(t[e]="Please resolve validation errors to continue")}}))}formDataToNode(t=this.formData){var e;if(!this.node)throw new Error("No node to update");let i={...this.node};if(this.node.actions&&this.node.actions.length>0&&(i.actions=this.node.actions.map((e=>{if(this.action&&e.uuid===this.action.uuid){const i=Cb[e.type];return(null==i?void 0:i.fromFormData)?i.fromFormData(t):{...e,...t}}return e}))),this.node.router){const n=this.getNodeConfig();if(null==n?void 0:n.fromFormData)i=n.fromFormData(t,i);else if(i.router={...this.node.router},void 0!==t.result_name&&(i.router.result_name=t.result_name),null===(e=null==n?void 0:n.router)||void 0===e?void 0:e.rules){const t=i.router.categories||[],e=i.exits||[],o=[],s=[],r=new Map;if(n.router.rules.forEach((t=>{r.has(t.categoryName)||r.set(t.categoryName,[]),r.get(t.categoryName).push(t)})),r.forEach(((i,n)=>{const r=t.find((t=>t.name===n));if(r){o.push(r);const t=e.find((t=>t.uuid===r.exit_uuid));t&&s.push(t)}else{const t=Ut(),e=Ut();o.push({uuid:t,name:n,exit_uuid:e}),s.push({uuid:e,destination_uuid:null})}})),n.router.defaultCategory){if(!o.find((t=>t.name===n.router.defaultCategory))){const i=t.find((t=>t.name===n.router.defaultCategory));if(i){o.push(i);const t=e.find((t=>t.uuid===i.exit_uuid));t&&s.push(t)}else{const t=Ut(),e=Ut();o.push({uuid:t,name:n.router.defaultCategory,exit_uuid:e}),s.push({uuid:e,destination_uuid:null})}}}i.router.categories=o,i.exits=s}}else Object.keys(t).forEach((e=>{"uuid"!==e&&"actions"!==e&&"exits"!==e&&"router"!==e&&(i[e]=t[e])}));return i}formDataToAction(t=this.formData){if(!this.action)throw new Error("No action to update");const e=Cb[this.action.type];if(null==e?void 0:e.fromFormData)return e.fromFormData(t);{const i=this.reverseSmartSelectTransformations(t,e);return{...this.action,...i}}}reverseSmartSelectTransformations(t,e){if(!e||!e.form)return t;const i={...t};return Object.entries(e.form).forEach((([t,e])=>{if(this.shouldApplySmartSelectTransformation(t,e)){const e=i[t];Array.isArray(e)&&e.length>0&&"object"==typeof e[0]&&"value"in e[0]&&(i[t]=e.map((t=>t.value||t.name||t)))}})),i}handleFormFieldChange(t,e){const i=e.target;let n;if(n="TEMBA-CHECKBOX"===i.tagName?i.checked:"TEMBA-SELECT"===i.tagName&&(i.multi||i.emails||i.tags)?i.values||[]:void 0!==i.values?i.values:i.value,this.formData={...this.formData,[t]:n},this.errors[t]){const e={...this.errors};delete e[t],this.errors=e}this.updateComputedFields(t),this.requestUpdate()}updateComputedFields(t){if(!this.action)return;const e=Cb[this.action.type];(null==e?void 0:e.form)&&Object.entries(e.form).forEach((([e,i])=>{var n;if((null===(n=i.dependsOn)||void 0===n?void 0:n.includes(t))&&i.computeValue){const t=this.formData[e],n=i.computeValue(this.formData,t,this.originalFormData);this.formData={...this.formData,[e]:n}}}))}renderNewField(t,e,i){var n;if(null===(n=e.conditions)||void 0===n?void 0:n.visible)try{if(!e.conditions.visible(this.formData))return H``}catch(e){console.error(`Error checking visibility for ${t}:`,e)}const o=this.errors[t]?[this.errors[t]]:[],s=e.maxWidth?`max-width: ${e.maxWidth};`:"",r=this.renderFieldContent(t,e,i,o);return s?H`<div style="${s}">${r}</div>`:r}renderFieldContent(t,e,i,n){var o;switch(e.type){case"text":return H`<temba-textinput
|
|
9852
9852
|
name="${t}"
|
|
9853
9853
|
label="${e.label}"
|
|
9854
9854
|
?required="${e.required}"
|