@trintel/zooy 1.8.0 → 1.9.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trintel/zooy",
3
- "version": "1.8.0",
3
+ "version": "1.9.2",
4
4
  "description": "UI Building Blocks",
5
5
  "license": "Apache-2.0",
6
6
  "author": {
@@ -1,52 +0,0 @@
1
- const g=require("./component-library-registry-BBQV6Kpv.js");let p=require("badu"),c=require("ramda"),o=require("lit");var T={json:t=>JSON.stringify(t,null,2),tpl:(t,r,e)=>{const i=e?.getAttribute("zoo-bind-attr-tpl")||e?.getAttribute("zoo-bind-tpl");if(!i)return t;try{return new Function("value","data",`return \`${i}\`;`)(t,r)}catch(n){return console.warn("[Binder] Invalid template:",i,n),t}}},w=class{#s;#t;#r;#e=null;#i;constructor(t,r,e,i={}){if(!r)throw new Error("Binder requires a URL");if(!e||!(e instanceof Element))throw new Error("Binder requires a valid rootEl Element");this.#s=t,this.#t=new URL(r,window.location.origin),this.#r=e,this.#i={...T,...i.formatters},i.urlParams?this.#a(i.urlParams):this.#n()}get url(){return this.#t}get data(){return this.#e}get limit(){return parseInt(this.#t.searchParams.get("limit")||"0",10)}get offset(){return parseInt(this.#t.searchParams.get("offset")||"0",10)}get isPaginated(){return(0,c.both)((0,c.has)("count"),(0,c.has)("results"))(this.#e)}#a(t){return Object.entries(t).forEach(([r,e])=>{if(!(0,p.isDefAndNotNull)(e)||e===""||Array.isArray(e)&&e.length<1){this.#t.searchParams.delete(r);return}if(Array.isArray(e)){this.#t.searchParams.set(r,e.join(","));return}this.#t.searchParams.set(r,e)}),this.#n(),this.#t}#n(){const t=this.#t.href.split(this.url.origin)[1].slice(1);this.#r.querySelectorAll("[zoo-bind-binderurl]").forEach(r=>{r.setAttribute("zoo-bind-binderurl",t)})}async fetchData(t={}){const r=await this.#s.user.fetchJson(this.#a(t).toString(),this.#s.abortController.signal);this.setData(r)}setData(t){this.#e=t,this.render()}render(){if(!(0,p.isDefAndNotNull)(this.#e)){console.warn("[Binder] No data to render");return}this.#n(),this.#o(this.#r,this.#e,0),this.#c()}#o(t,r,e=0,i={}){const n=i.removeAttributes??!1;t.querySelectorAll("[zoo-bind-attr]").forEach(s=>{s.closest("[zoo-template]")||(s.getAttribute("zoo-bind-attr").split(",").forEach(a=>{const[l,u]=a.split(":").map(f=>f.trim()),[d,m]=u.split("|").map(f=>f.trim());let h=this.#l(r,d,e);m&&this.#i[m]&&(h=this.#i[m](h,r,s)),(0,p.isDefAndNotNull)(h)&&s.setAttribute(l,h)}),n&&(s.removeAttribute("zoo-bind-attr"),s.removeAttribute("zoo-bind-attr-tpl")))}),t.querySelectorAll("[zoo-bind]").forEach(s=>{if(s.closest("[zoo-template]"))return;const[a,l]=s.getAttribute("zoo-bind").split("|").map(d=>d.trim());let u=this.#l(r,a,e);l&&this.#i[l]&&(u=this.#i[l](u,r,s)),s.textContent=u??"",n&&(s.removeAttribute("zoo-bind"),s.removeAttribute("zoo-bind-tpl"))})}#c(){this.#r.querySelectorAll("[zoo-template]").forEach(t=>{const r=t.getAttribute("zoo-template"),e=t.getAttribute("zoo-template-bind");if(!r){console.warn("[Binder] Consumer missing template ID",t);return}const i=this.#r.querySelector(`#${r}`);if(!i||i.tagName!=="TEMPLATE"){console.error(`[DataBinder] Template not found or invalid: ${r}`);return}const n=e?(0,c.path)(e.split("."),this.#e):this.#e;if(!n){console.warn(`[DataBinder] Data slice is undefined. Path: ${e}. Skipping render for this consumer.`);return}if(!Array.isArray(n)){console.error(`[DataBinder] Data slice is not an array. Path: ${e}`,n);return}if(t.innerHTML="",n.forEach((s,a)=>{const l=this.#u(i,s,a);t.appendChild(l)}),g.ComponentLibraryRegistry.has("carbon")){const s=g.ComponentLibraryRegistry.get("carbon");s.render.call(this.#s,t,s.cache).catch(a=>console.error("[Binder] Carbon init failed:",a))}})}#u(t,r,e){const i=t.content.cloneNode(!0);return this.#o(i,r,e,{removeAttributes:!0}),i}#l(t,r,e){const i={$index:()=>e,$index__paged:()=>this.offset+e,$index1:()=>e+1,$index1__paged:()=>this.offset+e+1};return i[r]?i[r]():(0,c.path)(r.split("."),t)}},v=new Map(Object.entries({event:"event",endpoint:"endpoint",href:"href",url:"url",target:"target","record-id":"recordId","zoo-sort-field":"sortField","zoo-view":"view","zoo-event":"event","zoo-href":"href"})),b=t=>{let r={};return Array.from(t.attributes).forEach(e=>{const i=e.name,n=e.value;v.has(i)?r[v.get(i)]=n:(i.startsWith("data-")||i.startsWith("zoo-"))&&(r=(0,c.assocPath)(i.split("-"),n,r))}),r},y=(t,r,e="event")=>t.getAttribute(r)||t.getAttribute(e),z=class extends o.LitElement{static properties={token:{type:String},prefix:{type:String},postfix:{type:String}};static styles=o.css`
2
- :host {
3
- display: inline-block;
4
- }
5
-
6
- .tag {
7
- text-align: center;
8
- display: inline-flex;
9
- align-items: center;
10
- justify-content: center;
11
- line-height: initial;
12
- width: max-content;
13
- padding: 0.2em 1em;
14
- border-radius: 1em;
15
- font-size: var(--zoo-theme-chips-font-size, 0.75rem);
16
- white-space: nowrap;
17
- word-break: break-word;
18
- box-sizing: border-box;
19
- }
20
- `;render(){const t=`${this.prefix??""}${this.token??"default"}${this.postfix??""}`;return o.html`
21
- <span
22
- class="tag"
23
- style="
24
- background-color: var(--zoo-tag-${t}-bg, var(--zoo-tag-default-bg, #9e9e9e));
25
- color: var(--zoo-tag-${t}-fg, var(--zoo-tag-default-fg, #ffffff));
26
- "
27
- >
28
- <slot></slot>
29
- </span>
30
- `}};customElements.get("zoo-tag")||customElements.define("zoo-tag",z);var _=t=>{const r=Math.floor((new Date-t)/1e3),e=[{name:"year",seconds:31536e3},{name:"month",seconds:2592e3},{name:"week",seconds:604800},{name:"day",seconds:86400},{name:"hour",seconds:3600},{name:"minute",seconds:60},{name:"second",seconds:1}];if(r<0){const i=Math.abs(r);for(const n of e){const s=Math.floor(i/n.seconds);if(s>=1)return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(s,n.name)}return"just now"}for(const i of e){const n=Math.floor(r/i.seconds);if(n>=1)return new Intl.RelativeTimeFormat("en",{numeric:"auto"}).format(-n,i.name)}return"just now"},k=t=>{const[{value:r},,{value:e},,{value:i},,{value:n},,{value:s},,{value:a}]=new Intl.DateTimeFormat("en",{day:"2-digit",month:"short",year:"2-digit",hour:"2-digit",minute:"2-digit",second:"2-digit",hourCycle:"h23"}).formatToParts(t);return`${e} ${r} ${i} ${n}:${s}:${a}`},E=t=>{const[{value:r},,{value:e},,{value:i}]=new Intl.DateTimeFormat("en",{day:"2-digit",month:"short",year:"2-digit"}).formatToParts(t);return`${e} ${r} ${i}`},A=class extends o.LitElement{static properties={timestamp:{type:Number},kind:{type:String},concat:{type:String}};static styles=o.css`
31
- :host {
32
- display: inline;
33
- }
34
-
35
- .relative {
36
- color: var(--zoo-timestamp-relative-color, inherit);
37
- font-weight: var(--zoo-timestamp-relative-weight, inherit);
38
- font-size: var(--zoo-timestamp-relative-size, inherit);
39
- }
40
-
41
- .static {
42
- color: var(--zoo-timestamp-static-color, inherit);
43
- font-weight: var(--zoo-timestamp-static-weight, inherit);
44
- font-size: var(--zoo-timestamp-static-size, inherit);
45
- }
46
-
47
- .separator {
48
- color: var(--zoo-timestamp-separator-color, inherit);
49
- }
50
- `;constructor(){super(),this.timestamp=Date.now(),this.kind="both",this.concat="r (s)",this._boundTickHandler=this._onTimeTick.bind(this),this._isListening=!1}_shouldListenToTicks(){return this.kind==="relative"||this.kind==="both"}connectedCallback(){super.connectedCallback(),this._updateTickListener()}disconnectedCallback(){this._removeTickListener(),super.disconnectedCallback()}updated(t){super.updated(t),t.has("kind")&&this._updateTickListener()}_updateTickListener(){const t=this._shouldListenToTicks();t&&!this._isListening?(document.addEventListener("zoo-tick-60",this._boundTickHandler),this._isListening=!0):!t&&this._isListening&&this._removeTickListener()}_removeTickListener(){this._isListening&&(document.removeEventListener("zoo-tick-60",this._boundTickHandler),this._isListening=!1)}_onTimeTick(){this.requestUpdate()}_parseTemplate(t){const r=[];let e=t;for(;e.length>0;){const i=e.indexOf("r"),n=[i,e.indexOf("s")].filter(s=>s!==-1).sort((s,a)=>s-a)[0];if(n===void 0){e.length>0&&r.push({type:"text",value:e});break}n>0&&r.push({type:"text",value:e.substring(0,n)}),n===i?r.push({type:"relative",value:""}):r.push({type:"static",value:""}),e=e.substring(n+1)}return r}_getFormattedParts(){let t=this.timestamp;t<9466848e5&&(t=t*1e3);const r=new Date(t),e=_(r),i=k(r),n=E(r);switch(this.kind){case"relative":return[{type:"relative",value:e}];case"datetime":return[{type:"static",value:i}];case"date":return[{type:"static",value:n}];case"both":return this._parseTemplate(this.concat).map(s=>s.type==="relative"?{type:"relative",value:e}:s.type==="static"?{type:"static",value:i}:s);default:return this._parseTemplate(this.concat).map(s=>s.type==="relative"?{type:"relative",value:e}:s.type==="static"?{type:"static",value:i}:s)}}render(){let t=this.timestamp;t<9466848e5&&(t=t*1e3);const r=new Date(t),e=this._getFormattedParts();return o.html`<time datetime="${r.toISOString()}">
51
- ${e.map(i=>i.type==="relative"?o.html`<span class="relative">${i.value}</span>`:i.type==="static"?o.html`<span class="static">${i.value}</span>`:o.html`<span class="separator">${i.value}</span>`)}
52
- </time>`}};customElements.get("zoo-timestamp")||customElements.define("zoo-timestamp",A);var $=g.__exportAll({ZooTag:()=>z,ZooTimestamp:()=>A,getEventAttribute:()=>y,getSemanticAttributes:()=>b});Object.defineProperty(exports,"Binder",{enumerable:!0,get:function(){return w}});Object.defineProperty(exports,"getEventAttribute",{enumerable:!0,get:function(){return y}});Object.defineProperty(exports,"getSemanticAttributes",{enumerable:!0,get:function(){return b}});Object.defineProperty(exports,"zoo_exports",{enumerable:!0,get:function(){return $}});