@nyaruka/temba-components 0.120.5 → 0.120.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
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.120.6](https://github.com/nyaruka/temba-components/compare/v0.120.5...v0.120.6)
|
|
8
|
+
|
|
9
|
+
- Add flow contents cache to store [`#493`](https://github.com/nyaruka/temba-components/pull/493)
|
|
10
|
+
- Remove debug [`6bed1c5`](https://github.com/nyaruka/temba-components/commit/6bed1c59e8da86a395c13e94a3a861c3f2779812)
|
|
11
|
+
|
|
7
12
|
#### [v0.120.5](https://github.com/nyaruka/temba-components/compare/v0.120.4...v0.120.5)
|
|
8
13
|
|
|
14
|
+
> 28 April 2025
|
|
15
|
+
|
|
9
16
|
- Detect changes from aribtrary options [`a9a2489`](https://github.com/nyaruka/temba-components/commit/a9a2489bc07e29f781f5f43061f038de77e26c37)
|
|
10
17
|
|
|
11
18
|
#### [v0.120.4](https://github.com/nyaruka/temba-components/compare/v0.120.3...v0.120.4)
|
package/dist/temba-components.js
CHANGED
|
@@ -397,7 +397,7 @@ let fr=Ks,vr=!1;const br=["es","fr","pt"],yr="data:image/png;base64,iVBORw0KGgoA
|
|
|
397
397
|
width: 100%;
|
|
398
398
|
top: 0.5em;
|
|
399
399
|
}
|
|
400
|
-
`}markDirty(t){this.dirtyElements.includes(t)||this.dirtyElements.push(t)}cleanAll(){this.dirtyElements.forEach((t=>t.markClean())),this.dirtyElements=[]}markClean(t){this.dirtyElements=this.dirtyElements.filter((e=>e!==t))}getDirtyMessage(){if(this.dirtyElements.length>0)return this.dirtyElements[0].dirtyMessage||"You have unsaved changes, are you sure you want to continue?"}getLocale(){return this.locale[0]}clearCache(){this.cache=Le(this.max,this.ttl)}reset(){this.ready=!1,this.clearCache(),this.settings=JSON.parse(oe("settings")||"{}");const t=[];this.completionEndpoint&&t.push(Vt(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&t.push(this.refreshFields()),this.globalsEndpoint&&t.push(Kt(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&t.push(Kt(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})}))),this.groupsEndpoint&&t.push(Kt(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&t.push(Vt(this.workspaceEndpoint).then((t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.shortcutsEndpoint&&t.push(this.refreshShortcuts()),this.initialHttpComplete=Promise.all(t),this.initialHttpComplete.then((()=>{this.ready=!0}))}getShortcuts(){return this.shortcuts||[]}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}async refreshGlobals(){return Kt(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))}async refreshShortcuts(){return Kt(this.shortcutsEndpoint).then((t=>{this.shortcuts=t}))}async refreshFields(){return Kt(this.fieldsEndpoint).then((t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach((t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)})),this.featuredFields.sort(((t,e)=>e.priority-t.priority)),this.keyedAssets.fields.sort(),this.fireCustomEvent($e.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})}))}shiftAndRound(t,e,i){const o=Math.round(t.shiftTo(e).get(e));return 1==o?`1 ${i}`:`${o} ${e}`}getCountdown(t){const e=t.diff(Hs.now()).rescale();return e.months>0?"> 1 month":e.days>1?`~ ${this.shiftAndRound(e,"days","day")}`:e.hours>0?`~ ${this.shiftAndRound(e,"hours","hour")}`:`~ ${this.shiftAndRound(e,"minutes","minute")}`}getShortDuration(t,e=null){const i=e||Hs.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=Hs.fromISO(t),o=e?Hs.fromISO(e):Hs.now();return this.getShortDuration(i,o)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){if(super.updated(t),t.has("ready")&&this.ready){const t=this.getLanguageCode(),e=br.find((e=>e===t));e&&wr(e)}}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){return this.languages[t]}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return Hs.fromISO(t).setLocale(this.getLocale()).toLocaleString(Hs.DATETIME_SHORT)}postJSON(t,e=""){return Qt(t,e)}postForm(t,e,i={}){return((t,e,i={})=>{const o=new FormData;return Object.keys(e).forEach((t=>{o.append(t,e[t])})),Jt(t,o,i)})(t,e,i)}postUrl(t,e="",i={},o=null){return Yt(t,e,i,o)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise((e=>{e(this.cache.get(t))})):Vt(t,e.controller,e.headers||{}).then((i=>new Promise(((o,n)=>{i.status>=200&&i.status<=300?(e.skipCache||this.cache.set(t,i),o(i)):n("Status: "+i.status)}))))}getResults(t,e){e=e||{};const i="results_"+t,o=this.cache.get(i);return!e.force&&o?new Promise((t=>{t(o)})):new Promise((e=>{const o=this.pendingResolves[t]||[];o.push(e),this.pendingResolves[t]=o,o.length<=1&&Wt(t).then((e=>{this.cache.set(i,e);const o=this.pendingResolves[t]||[];for(;o.length>0;){o.pop()(e)}}))}))}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent($e.StoreUpdated,{url:t,data:e})}removeFromCache(t){this.cache.delete(t)}resolveUsers(t,e){return new Promise((i=>{const o=new Set;t.forEach((t=>{e.forEach((e=>{const i=e.split(".");let n=t;for(let t=0;t<i.length&&(n=n[i[t]],n);t++);n&&n.email&&o.add(n.email)}))}));const n=[];o.forEach((t=>{n.push(this.getUrl(`/api/v2/users.json?email=${encodeURIComponent(t)}`,{force:!0}))})),Promise.all(n).then((o=>{o.forEach((i=>{if(i&&i.json){const o=i.json.results;if(o&&1===o.length){const i=o[0];t.forEach((t=>{e.forEach((e=>{const o=e.split(".");let n=t,s=n;for(let t=0;t<o.length&&(s=n,n=n[o[t]],n);t++);if(n&&n.email===i.email){const t=s[o[o.length-1]];t.avatar=i.avatar,t.name=_r(i),s[o[o.length-1]].avatar=i.avatar}}))}))}}})),i()}))}))}makeRequest(t,e){const i=this.fetching[t],o=(new Date).getTime();if(i)return void setTimeout((()=>{this.makeRequest(t,e)}),500);let n=this.cache.get(t);n&&!e.force?(n=e.prepareData?e.prepareData(n):n,this.fireCustomEvent($e.StoreUpdated,{url:t,data:n})):(e=e||{},this.fetching[t]=o,Wt(t).then((i=>{i?(this.cache.set(t,i),delete this.fetching[t],i=e.prepareData?e.prepareData(i):i,this.fireCustomEvent($e.StoreUpdated,{url:t,data:i})):delete this.fetching[t]})))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return V`<temba-loading size="10" units="8"></temba-loading>`}}t([ce({type:Number})],kr.prototype,"ttl",void 0),t([ce({type:Number})],kr.prototype,"max",void 0),t([ce({type:Boolean})],kr.prototype,"ready",void 0),t([ce({type:Boolean})],kr.prototype,"loader",void 0),t([ce({type:String,attribute:"completion"})],kr.prototype,"completionEndpoint",void 0),t([ce({type:String,attribute:"fields"})],kr.prototype,"fieldsEndpoint",void 0),t([ce({type:String,attribute:"groups"})],kr.prototype,"groupsEndpoint",void 0),t([ce({type:String,attribute:"globals"})],kr.prototype,"globalsEndpoint",void 0),t([ce({type:String,attribute:"languages"})],kr.prototype,"languagesEndpoint",void 0),t([ce({type:String,attribute:"workspace"})],kr.prototype,"workspaceEndpoint",void 0),t([ce({type:String,attribute:"shortcuts"})],kr.prototype,"shortcutsEndpoint",void 0),t([ce({type:Object,attribute:!1})],kr.prototype,"schema",void 0),t([ce({type:Object,attribute:!1})],kr.prototype,"fnOptions",void 0),t([ce({type:Object,attribute:!1})],kr.prototype,"keyedAssets",void 0);class Ar extends pe{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.internalFocusDisabled=!1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.scrollParent=null,this.setCursor=ee((function(t){this.internalFocusDisabled||t!==this.cursorIndex&&(this.cursorIndex=t)}),50)}static get styles(){return r`
|
|
400
|
+
`}markDirty(t){this.dirtyElements.includes(t)||this.dirtyElements.push(t)}cleanAll(){this.dirtyElements.forEach((t=>t.markClean())),this.dirtyElements=[]}markClean(t){this.dirtyElements=this.dirtyElements.filter((e=>e!==t))}getDirtyMessage(){if(this.dirtyElements.length>0)return this.dirtyElements[0].dirtyMessage||"You have unsaved changes, are you sure you want to continue?"}getLocale(){return this.locale[0]}clearCache(){this.cache=Le(this.max,this.ttl)}reset(){this.ready=!1,this.clearCache(),this.settings=JSON.parse(oe("settings")||"{}");const t=[];this.completionEndpoint&&t.push(Vt(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&t.push(this.refreshFields()),this.globalsEndpoint&&t.push(Kt(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&t.push(Kt(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})}))),this.groupsEndpoint&&t.push(Kt(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&t.push(Vt(this.workspaceEndpoint).then((t=>{this.workspace=t.json;const e=t.headers.get("content-language");e&&(this.locale=[e,...this.locale])}))),this.shortcutsEndpoint&&t.push(this.refreshShortcuts()),this.initialHttpComplete=Promise.all(t),this.initialHttpComplete.then((()=>{this.ready=!0}))}getShortcuts(){return this.shortcuts||[]}firstUpdated(){this.reset()}getLanguageCode(){return this.locale.length>0?this.locale[0].split("-")[0]:"en"}async refreshGlobals(){return Kt(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))}async refreshShortcuts(){return Kt(this.shortcutsEndpoint).then((t=>{this.shortcuts=t}))}async refreshFields(){return Kt(this.fieldsEndpoint).then((t=>{this.keyedAssets.fields=[],this.featuredFields=[],t.forEach((t=>{this.keyedAssets.fields.push(t.key),this.fields[t.key]=t,t.featured&&this.featuredFields.push(t)})),this.featuredFields.sort(((t,e)=>e.priority-t.priority)),this.keyedAssets.fields.sort(),this.fireCustomEvent($e.StoreUpdated,{url:this.fieldsEndpoint,data:this.keyedAssets.fields})}))}shiftAndRound(t,e,i){const o=Math.round(t.shiftTo(e).get(e));return 1==o?`1 ${i}`:`${o} ${e}`}getCountdown(t){const e=t.diff(Hs.now()).rescale();return e.months>0?"> 1 month":e.days>1?`~ ${this.shiftAndRound(e,"days","day")}`:e.hours>0?`~ ${this.shiftAndRound(e,"hours","hour")}`:`~ ${this.shiftAndRound(e,"minutes","minute")}`}getShortDuration(t,e=null){const i=e||Hs.now();return t.setLocale(this.locale[0]).toRelative({base:i,style:"long"})}getShortDurationFromIso(t,e=null){const i=Hs.fromISO(t),o=e?Hs.fromISO(e):Hs.now();return this.getShortDuration(i,o)}setKeyedAssets(t,e){this.keyedAssets[t]=e}updated(t){if(super.updated(t),t.has("ready")&&this.ready){const t=this.getLanguageCode(),e=br.find((e=>e===t));e&&wr(e)}}getCompletionSchema(){return this.schema}getFunctions(){return this.fnOptions}getKeyedAssets(){return this.keyedAssets}getFieldKeys(){return this.keyedAssets.fields||[]}getContactField(t){return this.fields[t]}getFeaturedFields(){return this.featuredFields}getLanguageName(t){return this.languages[t]}isDynamicGroup(t){const e=this.groups[t];return!(e&&!e.query)}getWorkspace(){return this.workspace}formatDate(t){return Hs.fromISO(t).setLocale(this.getLocale()).toLocaleString(Hs.DATETIME_SHORT)}postJSON(t,e=""){return Qt(t,e)}postForm(t,e,i={}){return((t,e,i={})=>{const o=new FormData;return Object.keys(e).forEach((t=>{o.append(t,e[t])})),Jt(t,o,i)})(t,e,i)}postUrl(t,e="",i={},o=null){return Yt(t,e,i,o)}getUrl(t,e){return!(e=e||{}).force&&this.cache.has(t)?new Promise((e=>{e(this.cache.get(t))})):Vt(t,e.controller,e.headers||{}).then((i=>new Promise(((o,n)=>{i.status>=200&&i.status<=300?(e.skipCache||this.cache.set(t,i),o(i)):n("Status: "+i.status)}))))}getResults(t,e){e=e||{};const i="results_"+t,o=this.cache.get(i);return!e.force&&o?new Promise((t=>{t(o)})):new Promise((e=>{const o=this.pendingResolves[t]||[];o.push(e),this.pendingResolves[t]=o,o.length<=1&&Wt(t).then((e=>{this.cache.set(i,e);const o=this.pendingResolves[t]||[];for(;o.length>0;){o.pop()(e)}}))}))}updateCache(t,e){this.cache.set(t,e),this.fireCustomEvent($e.StoreUpdated,{url:t,data:e})}removeFromCache(t){this.cache.delete(t)}resolveUsers(t,e){return new Promise((i=>{const o=new Set;t.forEach((t=>{e.forEach((e=>{const i=e.split(".");let n=t;for(let t=0;t<i.length&&(n=n[i[t]],n);t++);n&&n.email&&o.add(n.email)}))}));const n=[];o.forEach((t=>{n.push(this.getUrl(`/api/v2/users.json?email=${encodeURIComponent(t)}`,{force:!0}))})),Promise.all(n).then((o=>{o.forEach((i=>{if(i&&i.json){const o=i.json.results;if(o&&1===o.length){const i=o[0];t.forEach((t=>{e.forEach((e=>{const o=e.split(".");let n=t,s=n;for(let t=0;t<o.length&&(s=n,n=n[o[t]],n);t++);if(n&&n.email===i.email){const t=s[o[o.length-1]];t.avatar=i.avatar,t.name=_r(i),s[o[o.length-1]].avatar=i.avatar}}))}))}}})),i()}))}))}makeRequest(t,e){const i=this.fetching[t],o=(new Date).getTime();if(i)return void setTimeout((()=>{this.makeRequest(t,e)}),500);let n=this.cache.get(t);n&&!e.force?(n=e.prepareData?e.prepareData(n):n,this.fireCustomEvent($e.StoreUpdated,{url:t,data:n})):(e=e||{},this.fetching[t]=o,Wt(t).then((i=>{i?(this.cache.set(t,i),delete this.fetching[t],i=e.prepareData?e.prepareData(i):i,this.fireCustomEvent($e.StoreUpdated,{url:t,data:i})):delete this.fetching[t]})))}get(t,e=null){return this.settings[t]||e}set(t,e){this.settings[t]=e}render(){if(!this.ready&&this.loader)return V`<temba-loading size="10" units="8"></temba-loading>`}setFlowContents(t){this.flowContents=t}setFlowInfo(t){this.flowContents.info=t}async loadFlow(t,e="latest"){const i=await Vt(`/flow/revisions/${t}/${e}/?version=14.3`);return this.flowContents=i.json,this.flowContents}getFlowResults(){return this.flowContents.info.results}}t([ce({type:Number})],kr.prototype,"ttl",void 0),t([ce({type:Number})],kr.prototype,"max",void 0),t([ce({type:Boolean})],kr.prototype,"ready",void 0),t([ce({type:Boolean})],kr.prototype,"loader",void 0),t([ce({type:String,attribute:"completion"})],kr.prototype,"completionEndpoint",void 0),t([ce({type:String,attribute:"fields"})],kr.prototype,"fieldsEndpoint",void 0),t([ce({type:String,attribute:"groups"})],kr.prototype,"groupsEndpoint",void 0),t([ce({type:String,attribute:"globals"})],kr.prototype,"globalsEndpoint",void 0),t([ce({type:String,attribute:"languages"})],kr.prototype,"languagesEndpoint",void 0),t([ce({type:String,attribute:"workspace"})],kr.prototype,"workspaceEndpoint",void 0),t([ce({type:String,attribute:"shortcuts"})],kr.prototype,"shortcutsEndpoint",void 0),t([ce({type:Object,attribute:!1})],kr.prototype,"schema",void 0),t([ce({type:Object,attribute:!1})],kr.prototype,"fnOptions",void 0),t([ce({type:Object,attribute:!1})],kr.prototype,"keyedAssets",void 0);class Ar extends pe{constructor(){super(...arguments),this.marginHorizontal=0,this.marginVertical=7,this.scrollPct=75,this.cursorIndex=-1,this.internalFocusDisabled=!1,this.nameKey="name",this.loading=!1,this.hideShadow=!1,this.getName=function(t){return t[this.nameKey||"name"]},this.renderInputOption=function(){return null},this.scrollHeight=0,this.triggerScroll=!1,this.scrollParent=null,this.setCursor=ee((function(t){this.internalFocusDisabled||t!==this.cursorIndex&&(this.cursorIndex=t)}),50)}static get styles(){return r`
|
|
401
401
|
:host {
|
|
402
402
|
--transition-speed: 0;
|
|
403
403
|
}
|