@nyaruka/temba-components 0.121.1 → 0.121.2
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,14 @@ 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.121.2](https://github.com/nyaruka/temba-components/compare/v0.121.1...v0.121.2)
|
|
8
|
+
|
|
9
|
+
- Fallback to keyed assets for completion [`051adf9`](https://github.com/nyaruka/temba-components/commit/051adf9d8b98d2be362a6ce4b206ed2807284d8d)
|
|
10
|
+
|
|
7
11
|
#### [v0.121.1](https://github.com/nyaruka/temba-components/compare/v0.121.0...v0.121.1)
|
|
8
12
|
|
|
13
|
+
> 5 May 2025
|
|
14
|
+
|
|
9
15
|
- Don't update positions if they don't exist yet [`4278e31`](https://github.com/nyaruka/temba-components/commit/4278e31bc97faa361b19c40895fd819b00712e94)
|
|
10
16
|
|
|
11
17
|
#### [v0.121.0](https://github.com/nyaruka/temba-components/compare/v0.120.8...v0.121.0)
|
|
@@ -15,11 +21,16 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
|
|
|
15
21
|
- Add AppState using zustand and immer [`#496`](https://github.com/nyaruka/temba-components/pull/496)
|
|
16
22
|
- Add immer [`48ed498`](https://github.com/nyaruka/temba-components/commit/48ed498de5acf1a3d20b724b75c09e8a1fad5d58)
|
|
17
23
|
|
|
18
|
-
#### [v0.120.8](https://github.com/nyaruka/temba-components/compare/v0.120.
|
|
24
|
+
#### [v0.120.8](https://github.com/nyaruka/temba-components/compare/v0.120.7...v0.120.8)
|
|
19
25
|
|
|
20
26
|
> 30 April 2025
|
|
21
27
|
|
|
22
28
|
- Add locals to completion [`#495`](https://github.com/nyaruka/temba-components/pull/495)
|
|
29
|
+
|
|
30
|
+
#### [v0.120.7](https://github.com/nyaruka/temba-components/compare/v0.120.6...v0.120.7)
|
|
31
|
+
|
|
32
|
+
> 30 April 2025
|
|
33
|
+
|
|
23
34
|
- Add new icon for Microsoft AI and remove some unused ones [`#494`](https://github.com/nyaruka/temba-components/pull/494)
|
|
24
35
|
|
|
25
36
|
#### [v0.120.6](https://github.com/nyaruka/temba-components/compare/v0.120.5...v0.120.6)
|
package/dist/temba-components.js
CHANGED
|
@@ -397,7 +397,7 @@ let fr=Ks,vr=!1;const yr=["es","fr","pt"],br="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(){const t=this.getState();this.ready=!1,this.clearCache(),this.settings=JSON.parse(oe("settings")||"{}");const e=[];this.completionEndpoint&&e.push(Vt(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&e.push(this.refreshFields()),this.globalsEndpoint&&e.push(Kt(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&(t.fetchAllLanguages(this.languagesEndpoint),e.push(Kt(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})})))),this.groupsEndpoint&&e.push(Kt(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&(t.fetchWorkspace(this.workspaceEndpoint),e.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&&e.push(this.refreshShortcuts()),this.initialHttpComplete=Promise.all(e),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=yr.find((e=>e===t));e&&ga(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>`}getCompletions(t){const e=this.getState().flow.info;return"results"===t?e.results.map((t=>t.key)):"locals"===t?e.locals:
|
|
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(){const t=this.getState();this.ready=!1,this.clearCache(),this.settings=JSON.parse(oe("settings")||"{}");const e=[];this.completionEndpoint&&e.push(Vt(this.completionEndpoint).then((t=>{this.schema=t.json.context,this.fnOptions=t.json.functions}))),this.fieldsEndpoint&&e.push(this.refreshFields()),this.globalsEndpoint&&e.push(Kt(this.globalsEndpoint).then((t=>{this.keyedAssets.globals=t.map((t=>t.key))}))),this.languagesEndpoint&&(t.fetchAllLanguages(this.languagesEndpoint),e.push(Kt(this.languagesEndpoint).then((t=>{this.languages=t.reduce((function(t,e){return t[e.value]=e.name,t}),{})})))),this.groupsEndpoint&&e.push(Kt(this.groupsEndpoint).then((t=>{t.forEach((t=>{this.groups[t.uuid]=t}))}))),this.workspaceEndpoint&&(t.fetchWorkspace(this.workspaceEndpoint),e.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&&e.push(this.refreshShortcuts()),this.initialHttpComplete=Promise.all(e),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=yr.find((e=>e===t));e&&ga(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>`}getCompletions(t){const e=this.getState().flow.info;return"results"===t?e.results.map((t=>t.key)):"locals"===t?e.locals:this.keyedAssets[t]||[]}getApp(){return ma}getState(){return ma.getState()}}t([ce({type:Number})],fa.prototype,"ttl",void 0),t([ce({type:Number})],fa.prototype,"max",void 0),t([ce({type:Boolean})],fa.prototype,"ready",void 0),t([ce({type:Boolean})],fa.prototype,"loader",void 0),t([ce({type:String,attribute:"completion"})],fa.prototype,"completionEndpoint",void 0),t([ce({type:String,attribute:"fields"})],fa.prototype,"fieldsEndpoint",void 0),t([ce({type:String,attribute:"groups"})],fa.prototype,"groupsEndpoint",void 0),t([ce({type:String,attribute:"globals"})],fa.prototype,"globalsEndpoint",void 0),t([ce({type:String,attribute:"languages"})],fa.prototype,"languagesEndpoint",void 0),t([ce({type:String,attribute:"workspace"})],fa.prototype,"workspaceEndpoint",void 0),t([ce({type:String,attribute:"shortcuts"})],fa.prototype,"shortcutsEndpoint",void 0),t([ce({type:Object,attribute:!1})],fa.prototype,"schema",void 0),t([ce({type:Object,attribute:!1})],fa.prototype,"fnOptions",void 0),t([ce({type:Object,attribute:!1})],fa.prototype,"keyedAssets",void 0);class va 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
|
}
|