@zydon/common 2.7.33 → 2.7.35

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.
@@ -0,0 +1,3 @@
1
+ var n="@",o="@[__display__](__id__)";function a(e,t,r){return r?t?.replace(/ /g,"\xA0")||e.replace(/ /g,"\xA0"):t||e}
2
+
3
+ export { n as a, o as b, a as c };
@@ -2,13 +2,14 @@ import { ReactNode } from 'react';
2
2
  import { BaseSuggestionData, MentionData, SuggestionDataSource, SuggestionOverlaySlotProps } from '../../types/fieldMentions.js';
3
3
  import { TextFieldVariants, TextFieldProps } from '@mui/material/TextField';
4
4
  import '@mui/material/Popper';
5
+ import '@mui/material/styles';
6
+ import '@mui/system';
5
7
 
6
8
  interface FieldMentionsBaseProps<T extends BaseSuggestionData> {
7
9
  value?: string;
8
10
  defaultValue?: string;
9
11
  onChange?: (newValue: string, newPlainText: string, mentions: MentionData[]) => void;
10
12
  dataSources: SuggestionDataSource<T>[];
11
- highlightColor?: string;
12
13
  inputRef?: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
13
14
  highlightTextColor?: boolean;
14
15
  slotProps?: {
@@ -1,19 +1,19 @@
1
1
  import { a as a$1 } from '../../chunk-WIPXRHSG.js';
2
- import { b, c, a } from '../../chunk-SPIMM5MW.js';
2
+ import { b, c, a } from '../../chunk-4LP75UX2.js';
3
3
  import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
4
- import Ze from '@mui/material/TextField';
4
+ import Ye from '@mui/material/TextField';
5
5
  import A from '@mui/material/Box';
6
6
  import Be from '@mui/material/Portal';
7
7
  import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
8
- import z from 'invariant';
9
- import Qe from '@mui/material/CircularProgress';
10
- import ze from '@mui/material/List';
11
- import Ge from '@mui/material/Paper';
12
- import Je from '@mui/material/Popper';
13
- import Xe from '@mui/material/Stack';
8
+ import Q from 'invariant';
9
+ import Ke from '@mui/material/CircularProgress';
10
+ import Qe from '@mui/material/List';
11
+ import ze from '@mui/material/Paper';
12
+ import Ge from '@mui/material/Popper';
13
+ import Je from '@mui/material/Stack';
14
14
  import Ae from '@mui/material/ListItemButton';
15
15
 
16
- var we=({display:e,color:t,highlightTextColor:n})=>jsxs(A,{component:"span",sx:{position:"relative",color:n?t:"transparent"},children:[e,!n&&jsx(A,{component:"span",sx:{position:"absolute",left:"-1px",top:"-2px",bottom:0,right:"-1px",bgcolor:t,borderRadius:"3px",color:"transparent"}})]}),ge=we;function G(e){return typeof e=="number"}function Ce(e){let t=/^\/(.+)\/(\w+)?$/;return new RegExp(e.map(n=>{let[,o,r]=t.exec(n.toString())||[];return z(!r,`RegExp flags are not supported. Change /${o}/${r} into /${o}/`),`(${o})`}).join("|"),"g")}function de(e){let t=0;return e.indexOf("__id__")>=0&&t++,e.indexOf("__display__")>=0&&t++,t}function ce(e,t){z(t==="id"||t==="display",`Second arg must be either "id" or "display", got: "${t}"`);let n=e.indexOf("__display__"),o=e.indexOf("__id__");return z(n>=0||o>=0,`The markup '${e}' does not contain at least one of the placeholders '__id__' or '__display__'`),n>=0&&o>=0?t==="id"&&o<=n||t==="display"&&n<=o?0:1:0}function H(e,t,n,o,r){let u=Ce(t.map(a=>a.regex?ve(a.regex,a.markup||b):ke(a.markup||b))),f=2,c$1=t.map(({markup:a})=>{let d=f;return f+=de(a||b)+1,d}),i,l=0,g=0;for(;(i=u.exec(e))!==null;){let a=c$1.find(B=>!!i?.[B]);if(a===void 0)continue;let d=c$1.indexOf(a),{markup:h,displayTransform:p}=t[d],x=a+ce(h||b,"id"),S=a+ce(h||b,"display"),T=i[x],R=p?p(T,i[S]):c(T,i[S],r),b$1=e.substring(l,i.index);o?.(b$1,l,g),g+=b$1.length,n(i[0],i.index,g,T,R,d,l),g+=R.length,l=u.lastIndex;}l<e.length&&o?.(e.substring(l),l,g);}function k(e,t,n){let o="";return H(e,t,(r,u,f,c,i)=>{o+=i;},r=>{o+=r;},n),o}var ve=(e,t)=>{let n=(new RegExp(e.toString()+"|").exec("")?.length||0)-1,o=de(t);return z(n===o,`Number of capturing groups in RegExp ${e.toString()} (${n}) does not match the number of placeholders in the markup '${t}' (${o})`),e},ke=e=>{let t=Q(e),n=e[e.indexOf("__display__")+11],o=e[e.indexOf("__id__")+6];return new RegExp(t.replace("__display__",`([^${Q(n||"")}]+?)`).replace("__id__",`([^${Q(o||"")}]+?)`))},Q=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");function fe(e,t,n,o,r,u,f){let c=k(e,u,f),i=c.length-t.length;n===null&&(n=r+i),o===null&&(o=n),n===o&&o===r&&c.length===t.length&&(n=n-1);let l=t.slice(n,r),g=Math.min(n,r),a=o;n===r&&(a=Math.max(o,n+i));let d=I(e,u,g,"START"),h=I(e,u,a,"END"),p=I(e,u,g,"NULL"),x=I(e,u,a,"NULL"),S=p===null||x===null,T=K(e,d||0,h||0,l);if(!S){let R=k(T,u,f);if(R!==t){for(g=0;t[g]===R[g];)g++;l=t.slice(g,r),a=c.lastIndexOf(t.substring(r)),d=I(e,u,g,"START"),h=I(e,u,a,"END"),T=K(e,d||0,h||0,l);}}return T}function I(e,t,n,o="START"){if(typeof n!="number")return n;let r;return H(e,t,(c,i,l,g,a)=>{r===void 0&&l+a.length>n&&(o==="NULL"?r=null:r=i+(o==="END"?c.length:0));},(c,i,l)=>{r===void 0&&l+c.length>=n&&(r=i+n-l);}),r===void 0?e.length:r}function K(e,t,n,o){return e.substring(0,t)+o+e.substring(n)}function me(e,t,n){let o;return H(e,t,(u,f,c,i,l)=>{c<=n&&c+l.length>n&&(o=c);}),o}function J(e,t){let n=[];return H(e,t,(o,r,u,f,c,i)=>{n.push({id:f,display:c,dataSourceIndex:i,index:r,plainTextIndex:u});}),n}function he(e){return Object.values(e).reduce((t,{results:n})=>t+n.length,0)}function Se(e,t){let n=J(e,t),o=n[n.length-1];return o?o.plainTextIndex+o.display.length:0}function xe(e,t){if(e instanceof RegExp)return e;{let n=Q(e);return new RegExp(`(?:^|\\s)(${n}([^${t?"":"\\s"}${n}]*))$`)}}function Te(e,t){return e instanceof Array?async function(n){let o=[];for(let r=0,u=e.length;r<u;++r){let f=e[r].display||e[r].id;Oe(f,n,t)>=0&&o.push(e[r]);}return o}:e}var Oe=(e,t,n)=>n?pe(e).indexOf(pe(t)):e.toLowerCase().indexOf(t.toLowerCase()),$e=e=>{let t=e;return a$1.forEach(n=>{t=t.replace(n.letters,n.base);}),t},pe=e=>$e(e).toLowerCase(),be=(e,t,n)=>e.replace("__id__",t).replace("__display__",n||t);function Fe(e){let t={x:0,y:0,width:0,height:0};if(!e)return t;let n=getComputedStyle(e);return t.width=e.clientWidth,t.width-=parseFloat(n.paddingLeft),t.width-=parseFloat(n.paddingRight),t.height=e.clientHeight,t.height-=parseFloat(n.paddingTop),t.height-=parseFloat(n.paddingBottom),t.x=e.offsetLeft,t.x+=parseFloat(n.paddingLeft),t.x+=parseFloat(n.borderLeft),t.y=e.offsetTop,t.y+=parseFloat(n.paddingTop),t.y+=parseFloat(n.borderTop),t}var _e=e=>{let{highlighterRef:t,cursorRef:n,selectionEnd:o,selectionStart:r,value:u,dataSources:f,multiline:c,highlightTextColor:i}=e,l=[];H(u,f,(h,p,x,S,T)=>{l.push(jsx(ge,{display:T,color:e.color,highlightTextColor:i},`${S}-${p}`));},(h,p,x)=>{if(c||(h=h.replaceAll(`
17
- `,"")),!(r&&r===o&&r>=x&&r<=x+h.length))l.push(jsx(A,{component:"span",visibility:i?"visible":"hidden",children:h},`${p}-${x}`));else {let T=r-x,R=h.substring(0,T),b=h.substring(T);R&&l.push(jsx(A,{component:"span",visibility:i?"visible":"hidden",children:R},`${p}-${x}-precursor`)),l.push(jsx(A,{ref:n,component:"span",visibility:"hidden"},"cursor")),b&&l.push(jsx(A,{component:"span",visibility:i?"visible":"hidden",children:b},`${p}-${x}-postcursor`));}},c);let d=Fe(e.inputRef);return jsx(Be,{container:()=>e.inputRef?.parentElement||null,children:jsxs(A,{ref:t,sx:{position:"absolute",top:`${d.y}px`,left:`${d.x}px`,width:`${d.width}px`,height:`${d.height}px`,whiteSpace:c?"pre-wrap":"pre",overflow:"hidden",overscrollBehavior:"none",zIndex:i?1:-1,pointerEvents:"none"},children:[l,jsx(A,{component:"span",visibility:"hidden",children:" "})]})})},ye=_e;var Ne=e=>{let{renderSuggestion:t,suggestion:n,focused:o,onClick:r,onMouseEnter:u}=e;if(t)return t(e);let f=c(n.id,n.display);return jsx(Ae,{role:"option","aria-selected":o,selected:o,onClick:r,onMouseEnter:u,children:f})},De=Ne;var je=e=>{let{value:t,dataSources:n,selectionStart:o,selectionEnd:r,cursorRef:u,onSelect:f,onMouseDown:c}=e,i=useRef(null),[l,g]=useState({}),[a$1,d]=useState(0),[h,p]=useState(!1),[x,S]=useState(!1);useEffect(()=>{let m=i.current;if(!h||!m||m.children.length===0)return;let D=m.scrollTop,{top:M,bottom:y}=m.children[a$1].getBoundingClientRect(),{top:s}=m.getBoundingClientRect();M=M-s+D,y=y-s+D,M<D?m.scrollTop=M:y>m.offsetHeight+D&&(m.scrollTop=y-m.offsetHeight),p(!1);},[h,i,a$1,p]);let T=useCallback(async(m,D,M,y,s,w)=>{try{let E=Te(m.data,m.ignoreAccents);S(!0);let P=await E(D);g(L=>({...L,[M]:{queryInfo:{childIndex:M,query:D,querySequenceStart:y,querySequenceEnd:s,plainTextValue:w},results:P}}));}catch(E){console.error(E);}finally{S(!1);}},[g]);useEffect(()=>{if(g({}),!o||o!==r)return;let m=k(t,n),D=I(m,n,o,"NULL");if(!D)return;let M=Se(m.substring(0,D),n),y=m.substring(M,o);n.forEach((s,w)=>{if(!s)return;let E=xe(s.trigger||a,s.allowSpaceInQuery),P=y.match(E);if(P){let L=M+y.indexOf(P[1],P.index);T(s,P[2],w,L,L+P[1].length,m);}});},[g,o,r,n,t,T]);let R=useCallback(()=>{g({}),d(0);},[g,d]),b=useCallback((m,D)=>{f(m,D),R();},[f,R]),B=useCallback(m=>{d(m);},[d]),N=useMemo(()=>Object.values(l).reduce((m,{results:D,queryInfo:M})=>[...m,...D.map((y,s)=>jsx(De,{id:y.id,query:M.query,index:s,suggestion:y,focused:s===a$1,onClick:()=>b(y,M),onMouseEnter:()=>B(s)},y.id))],[]),[l,b,B,a$1]);return o===null||o!==r||!x&&N.length===0?null:jsxs(Fragment,{children:[jsx(We,{suggestions:l,clearSuggestions:R,onSelect:b,focusIndex:a$1,setFocusIndex:d,setScrollFocusedIntoView:p,loading:x}),jsx(Je,{placement:"bottom-start",...e.slotProps?.popper,sx:{zIndex:2,...e.slotProps?.popper?.sx},open:!0,anchorEl:u.current,children:jsx(Ge,{elevation:8,onMouseDown:c,children:jsx(ze,{ref:i,sx:{width:"300px",maxHeight:"40vh",overflow:"auto"},children:N.length>0?N:x&&jsx(Xe,{justifyContent:"center",alignItems:"center",height:"40vh",children:jsx(Qe,{})})})})})]})},Me=je;var We=e=>{let{suggestions:t,clearSuggestions:n,focusIndex:o,setFocusIndex:r,setScrollFocusedIntoView:u,onSelect:f,loading:c}=e;return useEffect(()=>{let i=a=>{if(c)return;let d=he(t);r((d+o+a)%d),u(!0);},l=()=>{if(c)return;let{result:a,queryInfo:d}=Object.values(t).reduce((h,{results:p,queryInfo:x})=>[...h,...p.map(S=>({result:S,queryInfo:x}))],[])[o];f(a,d);},g=a=>{switch(a.key){case"Escape":{n();break}case"ArrowDown":{i(1);break}case"ArrowUp":{i(-1);break}case"Enter":case"Tab":{l();break}default:return}a.preventDefault(),a.stopPropagation();};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n,o,r,f,u,c]),null};var et=e=>{let[t,n]=useState(e.defaultValue||""),[o,r]=useState(null),u=useRef(null),f=useRef(null),c$1=useRef(!1),[i,l]=useState(null),[g,a]=useState(null),d=s=>{r(s),S&&(typeof S=="function"?S(s):S&&"current"in S&&typeof S!="function"&&(S.current=s));};useEffect(()=>{let s=o,w=()=>{!u.current||!s||(u.current.scrollLeft=s.scrollLeft,u.current.scrollTop=s.scrollTop);};return s?.addEventListener("scroll",w),()=>s?.removeEventListener("scroll",w)},[o,u]),useEffect(()=>{let s=o;!s||s.selectionStart===i&&s.selectionEnd===g||s.setSelectionRange(i,g);},[i,g,o]);let{value:h,dataSources:p,highlightColor:x,inputRef:S,highlightTextColor:T,...R}=e,b$1=h!==void 0?h:t,B=()=>{c$1.current||(l(null),a(null)),c$1.current=!1;},N=()=>{c$1.current=!0;},m=(s,{childIndex:w,querySequenceStart:E,querySequenceEnd:P,plainTextValue:L})=>{let V=p[w],{markup:F,displayTransform:U,appendSpaceOnAdd:q,onAdd:ne}=V,v=I(b$1,p,E,"START");if(!G(v))return;let oe=v+P-E,re=be(F||b,s.id,s.display),Y=(U||c)(s.id,s.display);q&&(re+=" ",Y+=" ");let se=E+Y.length;l(se),a(se);let ie=K(b$1,v,oe,re),Ee=J(ie,p),Pe=K(L,E,P,Y);(e.onChange||n)(ie,Pe,Ee),ne?.(s,v,oe);},D=s=>{let w=s.target.value,E=i;G(E)||(E=s.target.selectionStart);let P=g;G(P)||(P=s.target.selectionEnd);let L=fe(b$1,w,E,P,s.target.selectionEnd||0,p,e.multiline);w=k(L,p);let V=s.target.selectionStart,F=s.target.selectionEnd,U=me(b$1,p,s.target.selectionStart||0);if(U!==void 0&&F!==null&&F>U){let v=s.nativeEvent.data;V=U+(v?v.length:0),F=V;}l(V),a(F);let q=J(L,p);(e.onChange||n)(L,w,q);},M=s=>{l(s.target.selectionStart),a(s.target.selectionEnd),e.onSelect?.(s);},y={...R,value:k(b$1,p,e.multiline),onChange:D,onSelect:M,onBlur:B,InputProps:{sx:{overscrollBehavior:"none",color:T?"transparent":void 0,caretColor:T?s=>s.palette.text.primary:void 0}}};return jsxs(Fragment,{children:[jsx(ye,{highlighterRef:u,cursorRef:f,selectionStart:i,selectionEnd:g,value:b$1,dataSources:p,inputRef:o,multiline:y.multiline,color:x||e.color,highlightTextColor:T}),jsx(Ze,{inputRef:d,...y}),jsx(Me,{value:b$1,dataSources:p,selectionStart:i,selectionEnd:g,cursorRef:f,loading:!1,onSelect:m,onMouseDown:N,slotProps:e.slotProps?.suggestionsOverlay})]})},on=et;
16
+ var we=({display:e,color:t,backgroundColor:n,highlightTextColor:o})=>jsxs(A,{component:"span",sx:{position:"relative",color:o&&t?t:"transparent",...o&&n&&{bgcolor:n}},children:[e,!o&&n&&jsx(A,{component:"span",sx:{position:"absolute",left:"-1px",top:"-2px",bottom:0,right:"-1px",borderRadius:"3px",color:"transparent"}})]}),ue=we;function z(e){return typeof e=="number"}function Ce(e){let t=/^\/(.+)\/(\w+)?$/;return new RegExp(e.map(n=>{let[,o,r]=t.exec(n.toString())||[];return Q(!r,`RegExp flags are not supported. Change /${o}/${r} into /${o}/`),`(${o})`}).join("|"),"g")}function pe(e){let t=0;return e.indexOf("__id__")>=0&&t++,e.indexOf("__display__")>=0&&t++,t}function ce(e,t){Q(t==="id"||t==="display",`Second arg must be either "id" or "display", got: "${t}"`);let n=e.indexOf("__display__"),o=e.indexOf("__id__");return Q(n>=0||o>=0,`The markup '${e}' does not contain at least one of the placeholders '__id__' or '__display__'`),n>=0&&o>=0?t==="id"&&o<=n||t==="display"&&n<=o?0:1:0}function H(e,t,n,o,r){let u=Ce(t.map(a=>a.regex?ve(a.regex,a.markup||b):ke(a.markup||b))),d=2,c$1=t.map(({markup:a})=>{let f=d;return d+=pe(a||b)+1,f}),i,l=0,g=0;for(;(i=u.exec(e))!==null;){let a=c$1.find(k=>!!i?.[k]);if(a===void 0)continue;let f=c$1.indexOf(a),{markup:x,displayTransform:p}=t[f],m=a+ce(x||b,"id"),M=a+ce(x||b,"display"),D=i[m],T=p?p(D,i[M]):c(D,i[M],r),R=e.substring(l,i.index);o?.(R,l,g),g+=R.length,n(i[0],i.index,g,D,T,f,l),g+=T.length,l=u.lastIndex;}l<e.length&&o?.(e.substring(l),l,g);}function $(e,t,n){let o="";return H(e,t,(r,u,d,c,i)=>{o+=i;},r=>{o+=r;},n),o}var ve=(e,t)=>{let n=(new RegExp(e.toString()+"|").exec("")?.length||0)-1,o=pe(t);return Q(n===o,`Number of capturing groups in RegExp ${e.toString()} (${n}) does not match the number of placeholders in the markup '${t}' (${o})`),e},ke=e=>{let t=K(e),n=e[e.indexOf("__display__")+11],o=e[e.indexOf("__id__")+6];return new RegExp(t.replace("__display__",`([^${K(n||"")}]+?)`).replace("__id__",`([^${K(o||"")}]+?)`))},K=e=>e.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&");function de(e,t,n,o,r,u,d){let c=$(e,u,d),i=c.length-t.length;n===null&&(n=r+i),o===null&&(o=n),n===o&&o===r&&c.length===t.length&&(n=n-1);let l=t.slice(n,r),g=Math.min(n,r),a=o;n===r&&(a=Math.max(o,n+i));let f=L(e,u,g,"START"),x=L(e,u,a,"END"),p=L(e,u,g,"NULL"),m=L(e,u,a,"NULL"),M=p===null||m===null,D=V(e,f||0,x||0,l);if(!M){let T=$(D,u,d);if(T!==t){for(g=0;t[g]===T[g];)g++;l=t.slice(g,r),a=c.lastIndexOf(t.substring(r)),f=L(e,u,g,"START"),x=L(e,u,a,"END"),D=V(e,f||0,x||0,l);}}return D}function L(e,t,n,o="START"){if(typeof n!="number")return n;let r;return H(e,t,(c,i,l,g,a)=>{r===void 0&&l+a.length>n&&(o==="NULL"?r=null:r=i+(o==="END"?c.length:0));},(c,i,l)=>{r===void 0&&l+c.length>=n&&(r=i+n-l);}),r===void 0?e.length:r}function V(e,t,n,o){return e.substring(0,t)+o+e.substring(n)}function fe(e,t,n){let o;return H(e,t,(u,d,c,i,l)=>{c<=n&&c+l.length>n&&(o=c);}),o}function G(e,t){let n=[];return H(e,t,(o,r,u,d,c,i)=>{n.push({id:d,display:c,dataSourceIndex:i,index:r,plainTextIndex:u});}),n}function me(e){return Object.values(e).reduce((t,{results:n})=>t+n.length,0)}function he(e,t){let n=G(e,t),o=n[n.length-1];return o?o.plainTextIndex+o.display.length:0}function Se(e,t){if(e instanceof RegExp)return e;{let n=K(e);return new RegExp(`(?:^|\\s)(${n}([^${t?"":"\\s"}${n}]*))$`)}}function xe(e,t){return e instanceof Array?async function(n){let o=[];for(let r=0,u=e.length;r<u;++r){let d=e[r].display||e[r].id;Oe(d,n,t)>=0&&o.push(e[r]);}return o}:e}var Oe=(e,t,n)=>n?ge(e).indexOf(ge(t)):e.toLowerCase().indexOf(t.toLowerCase()),$e=e=>{let t=e;return a$1.forEach(n=>{t=t.replace(n.letters,n.base);}),t},ge=e=>$e(e).toLowerCase(),Te=(e,t,n)=>e.replace("__id__",t).replace("__display__",n||t);function Fe(e){let t={x:0,y:0,width:0,height:0};if(!e)return t;let n=getComputedStyle(e);return t.width=e.clientWidth,t.width-=parseFloat(n.paddingLeft),t.width-=parseFloat(n.paddingRight),t.height=e.clientHeight,t.height-=parseFloat(n.paddingTop),t.height-=parseFloat(n.paddingBottom),t.x=e.offsetLeft,t.x+=parseFloat(n.paddingLeft),t.x+=parseFloat(n.borderLeft),t.y=e.offsetTop,t.y+=parseFloat(n.paddingTop),t.y+=parseFloat(n.borderTop),t}var _e=e=>{let{highlighterRef:t,cursorRef:n,selectionEnd:o,selectionStart:r,value:u,dataSources:d,multiline:c,highlightTextColor:i}=e,l=[];H(u,d,(x,p,m,M,D,T)=>{let R=d[T];l.push(jsx(ue,{display:D,color:R?.color,backgroundColor:R?.backgroundColor,highlightTextColor:i},`${M}-${p}`));},(x,p,m)=>{if(c||(x=x.replaceAll(`
17
+ `,"")),!(r&&r===o&&r>=m&&r<=m+x.length))l.push(jsx(A,{component:"span",visibility:i?"visible":"hidden",children:x},`${p}-${m}`));else {let D=r-m,T=x.substring(0,D),R=x.substring(D);T&&l.push(jsx(A,{component:"span",visibility:i?"visible":"hidden",children:T},`${p}-${m}-precursor`)),l.push(jsx(A,{ref:n,component:"span",visibility:"hidden"},"cursor")),R&&l.push(jsx(A,{component:"span",visibility:i?"visible":"hidden",children:R},`${p}-${m}-postcursor`));}},c);let f=Fe(e.inputRef);return jsx(Be,{container:()=>e.inputRef?.parentElement||null,children:jsxs(A,{ref:t,sx:{position:"absolute",top:`${f.y}px`,left:`${f.x}px`,width:`${f.width}px`,height:`${f.height}px`,whiteSpace:c?"pre-wrap":"pre",overflow:"hidden",overscrollBehavior:"none",zIndex:i?1:-1,pointerEvents:"none"},children:[l,jsx(A,{component:"span",visibility:"hidden",children:" "})]})})},be=_e;var Ne=e=>{let{renderSuggestion:t,suggestion:n,focused:o,onClick:r,onMouseEnter:u}=e;if(t)return t(e);let d=c(n.id,n.display);return jsx(Ae,{role:"option","aria-selected":o,selected:o,onClick:r,onMouseEnter:u,children:d})},ye=Ne;var Xe=e=>{let{value:t,dataSources:n,selectionStart:o,selectionEnd:r,cursorRef:u,onSelect:d,onMouseDown:c}=e,i=useRef(null),[l,g]=useState({}),[a$1,f]=useState(0),[x,p]=useState(!1),[m,M]=useState(!1);useEffect(()=>{let h=i.current;if(!x||!h||h.children.length===0)return;let y=h.scrollTop,{top:s,bottom:S}=h.children[a$1].getBoundingClientRect(),{top:b}=h.getBoundingClientRect();s=s-b+y,S=S-b+y,s<y?h.scrollTop=s:S>h.offsetHeight+y&&(h.scrollTop=S-h.offsetHeight),p(!1);},[x,i,a$1,p]);let D=useCallback(async(h,y,s,S,b,P)=>{try{let w=xe(h.data,h.ignoreAccents);M(!0);let I=await w(y);g(E=>({...E,[s]:{queryInfo:{childIndex:s,query:y,querySequenceStart:S,querySequenceEnd:b,plainTextValue:P},results:I}}));}catch(w){console.error(w);}finally{M(!1);}},[]),T=useRef(n);useEffect(()=>{T.current=n;},[n]),useEffect(()=>{if(g({}),!o||o!==r)return;let h=T.current,y=$(t,h),s=L(y,h,o,"NULL");if(!s)return;let S=he(y.substring(0,s),h),b=y.substring(S,o);h.forEach((P,w)=>{if(!P)return;let I=Se(P.trigger||a,P.allowSpaceInQuery),E=b.match(I);if(E){let C=S+b.indexOf(E[1],E.index);D(P,E[2],w,C,C+E[1].length,y);}});},[o,r,t,D]);let R=useCallback(()=>{g({}),f(0);},[g,f]),k=useCallback((h,y)=>{d(h,y),R();},[d,R]),U=useCallback(h=>{f(h);},[f]),N=useMemo(()=>Object.values(l).reduce((h,{results:y,queryInfo:s})=>[...h,...y.map((S,b)=>jsx(ye,{id:S.id,query:s.query,index:b,suggestion:S,focused:b===a$1,onClick:()=>k(S,s),onMouseEnter:()=>U(b)},S.id))],[]),[l,k,U,a$1]);return o===null||o!==r||!m&&N.length===0?null:jsxs(Fragment,{children:[jsx(je,{suggestions:l,clearSuggestions:R,onSelect:k,focusIndex:a$1,setFocusIndex:f,setScrollFocusedIntoView:p,loading:m}),jsx(Ge,{placement:"bottom-start",...e.slotProps?.popper,sx:{zIndex:2,...e.slotProps?.popper?.sx},open:!0,anchorEl:u.current,children:jsx(ze,{elevation:8,onMouseDown:c,children:jsx(Qe,{ref:i,sx:{width:"300px",maxHeight:"40vh",overflow:"auto"},children:N.length>0?N:m&&jsx(Je,{justifyContent:"center",alignItems:"center",height:"40vh",children:jsx(Ke,{})})})})})]})},Me=Xe;var je=e=>{let{suggestions:t,clearSuggestions:n,focusIndex:o,setFocusIndex:r,setScrollFocusedIntoView:u,onSelect:d,loading:c}=e;return useEffect(()=>{let i=a=>{if(c)return;let f=me(t);r((f+o+a)%f),u(!0);},l=()=>{if(c)return;let{result:a,queryInfo:f}=Object.values(t).reduce((x,{results:p,queryInfo:m})=>[...x,...p.map(M=>({result:M,queryInfo:m}))],[])[o];d(a,f);},g=a=>{switch(a.key){case"Escape":{n();break}case"ArrowDown":{i(1);break}case"ArrowUp":{i(-1);break}case"Enter":case"Tab":{l();break}default:return}a.preventDefault(),a.stopPropagation();};return document.addEventListener("keydown",g),()=>document.removeEventListener("keydown",g)},[t,n,o,r,d,u,c]),null};var Ze=e=>{let[t,n]=useState(e.defaultValue||""),[o,r]=useState(null),u=useRef(null),d=useRef(null),c$1=useRef(!1),[i,l]=useState(null),[g,a]=useState(null),f=s=>{r(s),m&&(typeof m=="function"?m(s):m&&"current"in m&&typeof m!="function"&&(m.current=s));};useEffect(()=>{let s=o,S=()=>{!u.current||!s||(u.current.scrollLeft=s.scrollLeft,u.current.scrollTop=s.scrollTop);};return s?.addEventListener("scroll",S),()=>s?.removeEventListener("scroll",S)},[o,u]),useEffect(()=>{let s=o;!s||s.selectionStart===i&&s.selectionEnd===g||s.setSelectionRange(i,g);},[i,g,o]);let{value:x,dataSources:p,inputRef:m,highlightTextColor:M,...D}=e,T=x!==void 0?x:t,R=()=>{c$1.current||(l(null),a(null)),c$1.current=!1;},k=()=>{c$1.current=!0;},U=(s,{childIndex:S,querySequenceStart:b$1,querySequenceEnd:P,plainTextValue:w})=>{let I=p[S],{markup:E,displayTransform:C,appendSpaceOnAdd:q,onAdd:te}=I,O=L(T,p,b$1,"START");if(!z(O))return;let ne=O+P-b$1,oe=Te(E||b,s.id,s.display),Y=(C||c)(s.id,s.display);q&&(oe+=" ",Y+=" ");let re=b$1+Y.length;l(re),a(re);let se=V(T,O,ne,oe),Ee=G(se,p),Pe=V(w,b$1,P,Y);(e.onChange||n)(se,Pe,Ee),te?.(s,O,ne);},N=s=>{let S=s.target.value,b=i;z(b)||(b=s.target.selectionStart);let P=g;z(P)||(P=s.target.selectionEnd);let w=de(T,S,b,P,s.target.selectionEnd||0,p,e.multiline);S=$(w,p);let I=s.target.selectionStart,E=s.target.selectionEnd,C=fe(T,p,s.target.selectionStart||0);if(C!==void 0&&E!==null&&E>C){let O=s.nativeEvent.data;I=C+(O?O.length:0),E=I;}l(I),a(E);let q=G(w,p);(e.onChange||n)(w,S,q);},h=s=>{l(s.target.selectionStart),a(s.target.selectionEnd),e.onSelect?.(s);},y={...D,value:$(T,p,e.multiline),onChange:N,onSelect:h,onBlur:R,InputProps:{sx:{overscrollBehavior:"none",color:M?void 0:"transparent",caretColor:M?void 0:s=>s.palette.text.primary}}};return jsxs(Fragment,{children:[jsx(be,{highlighterRef:u,cursorRef:d,selectionStart:i,selectionEnd:g,value:T,dataSources:p,inputRef:o,multiline:y.multiline,highlightTextColor:M}),jsx(Ye,{inputRef:f,...y}),jsx(Me,{value:T,dataSources:p,selectionStart:i,selectionEnd:g,cursorRef:d,loading:!1,onSelect:U,onMouseDown:k,slotProps:e.slotProps?.suggestionsOverlay})]})},nn=Ze;
18
18
 
19
- export { on as default };
19
+ export { nn as default };
@@ -5,6 +5,6 @@ import '../../chunk-6MUF35YU.js';
5
5
  import { createContext, useState, useRef, useMemo, useEffect, useCallback, useContext } from 'react';
6
6
  import { jsx } from 'react/jsx-runtime';
7
7
 
8
- var Z=createContext(void 0),le=({children:d,originId:I,originType:C,bearerToken:S,vapidKey:V,serviceWorkerPath:G="/",serviceWorkerFile:H="service-worker.js",pollingInterval:k=1e3,apiAdapters:n,onMessageReceived:m,onError:r})=>{let[t,p]=useState(null),[x,h]=useState(0),[W,M]=useState(!1),[v,b]=useState(!1),[y,O]=useState(!1),[N,ee]=useState(!1),[A,te]=useState({subscriptions:[]}),[B,z]=useState(!1),[R]=useState(new Set),f=useRef(new Map),F=useMemo(()=>!t||B,[t,B]);useEffect(()=>{if(!v||!y||!t||!n.fetchMessages)return;let e=setInterval(async()=>{try{let c=(await n.fetchMessages(t))?.messages?.[0];if(c?.payload){let o=c.id;if(R.has(o))return;R.add(o),h(a=>a+1),m?.(c.payload);try{await n.updateMessageStatus(o,{status:"DELIVERED"});}catch(a$1){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao marcar mensagem como entregue:",data:a$1});}finally{let a=c.topic;f.current.get(a)?.stopPollingOnFirstMessage&&(f.current.delete(a),f.current.size>0||(b(!1),O(!1)));}}}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao buscar mensagens:",data:s});}},k);return ()=>clearInterval(e)},[v,y,t,k,n,m,R]);let P=useCallback(async(e,s)=>{try{let c=e?.toJSON().keys,o={origin_type:C,origin_id:I,...s&&e?{endpoint:e.endpoint,auth:c?.auth,p256dh:c?.p256dh}:{}},a=await n.registerClient(o);return p(a.id),M(!1),ee(s),s||O(!0),a.id}catch(c){return a({type:"ERROR",environment:["development","homologation"],message:"Erro ao registrar cliente:",data:c}),M(!0),r?.(c),null}},[n,I,C,r]);useEffect(()=>{let e=!0,s=null;async function c(){if(!("serviceWorker"in navigator)||!("PushManager"in window)){a({type:"WARN",environment:["development","homologation"],message:"Push notifications n\xE3o suportadas, criando cliente ativo com polling"});try{let o=await P(null,!1);e&&o&&(p(o),O(!0));}catch(o){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao registrar cliente ativo:",data:o}),r?.(o);}return}try{let o=await Notification.requestPermission(),a$2=null,g=!1;if(o==="granted")try{let w=await navigator.serviceWorker.register(`${G}${H}`);if(!e||(await navigator.serviceWorker.ready,!e))return;a$2=await w.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:a$1(V)}),s=async j=>{let K=j.data?.payload,Q=j.data?.id;if(K&&(h(T=>T+1),m?.(K)),Q)try{await n.updateMessageStatus(Q,{status:"DELIVERED"});}catch(T){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao atualizar status da mensagem:",data:T}),M(!0),r?.(T);}},navigator.serviceWorker.addEventListener("message",s),g=!0,a({type:"LOG",environment:["development","homologation"],message:"Permiss\xE3o concedida, criando cliente passivo (aguarda webpush)"});}catch(w){a({type:"WARN",environment:["development","homologation"],message:"Falha ao configurar push subscription, criando cliente ativo:",data:w}),g=!1;}else a({type:"WARN",environment:["development","homologation"],message:"Permiss\xE3o de notifica\xE7\xE3o negada, criando cliente ativo com polling"}),g=!1;let L=await P(a$2,g);e&&L&&(p(L),g||O(!0));}catch(o){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao inicializar notifica\xE7\xF5es:",data:o}),r?.(o);try{let a=await P(null,!1);e&&a&&(p(a),O(!0));}catch(a$1){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao criar cliente ativo como fallback:",data:a$1});}}}return S&&c(),()=>{e=!1,s&&"serviceWorker"in navigator&&navigator.serviceWorker.removeEventListener("message",s);}},[S,P,n,V,G,H,m,r]);let u=useCallback(async()=>{if(t){z(!0);try{let e=await n.listSubscriptions(t);te(e);}catch(e){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao listar inscri\xE7\xF5es:",data:e}),r?.(e);}finally{z(!1);}}},[t,n,r]);useEffect(()=>{t&&u();},[t]);let _=useCallback(async(e,s)=>{if(!t){a({type:"WARN",environment:["development","homologation"],message:"Cliente n\xE3o registrado"});return}try{s&&f.current.set(e,s),await n.subscribeTopic(t,e),await u(),!N&&(!v||!y)&&(b(!0),O(!0));}catch(c){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao inscrever no t\xF3pico:",data:c}),r?.(c);}},[t,n,u,r,v,y,N]),$=useCallback(async e=>{if(!t){a({type:"WARN",environment:["development","homologation"],message:"Cliente n\xE3o registrado"});return}try{f.current.delete(e),await n.unsubscribeTopic(t,e),await u();}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao desinscrever do t\xF3pico:",data:s}),r?.(s);}},[t,n,u,r]),q=useCallback(async e=>{if(!(!t||e.length===0))try{await n.subscribeTopicsBatch(t,e),await u(),N||(b(!0),O(!0));}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao inscrever em t\xF3picos:",data:s}),r?.(s);}},[t,n,u,r,N]),J=useCallback(async e=>{if(!(!t||e.length===0))try{await n.unsubscribeTopicsBatch(t,e),await u();}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao desinscrever de t\xF3picos:",data:s}),r?.(s);}},[t,n,u,r]),U=useCallback(()=>{h(0);},[]),se=useMemo(()=>({clientId:t,subscribedTopics:A,isLoading:F,newMessageCount:x,isRegisterError:W,subscribeToTopic:_,unsubscribeFromTopic:$,subscribeTopicsBatch:q,unsubscribeTopicsBatch:J,resetMessageCount:U}),[t,A,F,x,W,_,$,q,J,U]);return jsx(Z.Provider,{value:se,children:d})};function Oe(){let d=useContext(Z);if(!d)throw new Error("usePushNotifications precisa estar dentro de PushNotificationProvider");return d}
8
+ var Z=createContext(void 0),le=({children:d,originId:I,originType:C,bearerToken:S,vapidKey:V,serviceWorkerPath:G="/",serviceWorkerFile:H="service-worker.js",pollingInterval:k=1e3,apiAdapters:n,onMessageReceived:m,onError:r})=>{let[t,p]=useState(null),[x,h]=useState(0),[W,M]=useState(!1),[v,b]=useState(!1),[y,O]=useState(!1),[N,ee]=useState(!1),[A,te]=useState({subscriptions:[]}),[B,z]=useState(!1),[R]=useState(new Set),g=useRef(new Map),F=useMemo(()=>!t||B,[t,B]);useEffect(()=>{if(!v||!y||!t||!n.fetchMessages||g.current.size===0)return;let e=setInterval(async()=>{try{let c=(await n.fetchMessages(t))?.messages?.[0];if(c?.payload){let o=c.id;if(R.has(o))return;R.add(o),h(a=>a+1),m?.(c.payload);try{await n.updateMessageStatus(o,{status:"DELIVERED"});}catch(a$1){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao marcar mensagem como entregue:",data:a$1});}finally{let a=c.topic;g.current.get(a)?.stopPollingOnFirstMessage&&(g.current.delete(a),g.current.size>0||(b(!1),O(!1)));}}}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao buscar mensagens:",data:s});}},k);return ()=>clearInterval(e)},[v,y,t,k,n,m,R]);let P=useCallback(async(e,s)=>{try{let c=e?.toJSON().keys,o={origin_type:C,origin_id:I,...s&&e?{endpoint:e.endpoint,auth:c?.auth,p256dh:c?.p256dh}:{}},a=await n.registerClient(o);return p(a.id),M(!1),ee(s),s||O(!0),a.id}catch(c){return a({type:"ERROR",environment:["development","homologation"],message:"Erro ao registrar cliente:",data:c}),M(!0),r?.(c),null}},[n,I,C,r]);useEffect(()=>{let e=!0,s=null;async function c(){if(!("serviceWorker"in navigator)||!("PushManager"in window)){a({type:"WARN",environment:["development","homologation"],message:"Push notifications n\xE3o suportadas, criando cliente ativo com polling"});try{let o=await P(null,!1);e&&o&&(p(o),O(!0));}catch(o){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao registrar cliente ativo:",data:o}),r?.(o);}return}try{let o=await Notification.requestPermission(),a$2=null,f=!1;if(o==="granted")try{let w=await navigator.serviceWorker.register(`${G}${H}`);if(!e||(await navigator.serviceWorker.ready,!e))return;a$2=await w.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:a$1(V)}),s=async j=>{let K=j.data?.payload,Q=j.data?.id;if(K&&(h(T=>T+1),m?.(K)),Q)try{await n.updateMessageStatus(Q,{status:"DELIVERED"});}catch(T){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao atualizar status da mensagem:",data:T}),M(!0),r?.(T);}},navigator.serviceWorker.addEventListener("message",s),f=!0,a({type:"LOG",environment:["development","homologation"],message:"Permiss\xE3o concedida, criando cliente passivo (aguarda webpush)"});}catch(w){a({type:"WARN",environment:["development","homologation"],message:"Falha ao configurar push subscription, criando cliente ativo:",data:w}),f=!1;}else a({type:"WARN",environment:["development","homologation"],message:"Permiss\xE3o de notifica\xE7\xE3o negada, criando cliente ativo com polling"}),f=!1;let L=await P(a$2,f);e&&L&&(p(L),f||O(!0));}catch(o){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao inicializar notifica\xE7\xF5es:",data:o}),r?.(o);try{let a=await P(null,!1);e&&a&&(p(a),O(!0));}catch(a$1){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao criar cliente ativo como fallback:",data:a$1});}}}return S&&c(),()=>{e=!1,s&&"serviceWorker"in navigator&&navigator.serviceWorker.removeEventListener("message",s);}},[S,P,n,V,G,H,m,r]);let u=useCallback(async()=>{if(t){z(!0);try{let e=await n.listSubscriptions(t);te(e);}catch(e){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao listar inscri\xE7\xF5es:",data:e}),r?.(e);}finally{z(!1);}}},[t,n,r]);useEffect(()=>{t&&u();},[t]);let _=useCallback(async(e,s)=>{if(!t){a({type:"WARN",environment:["development","homologation"],message:"Cliente n\xE3o registrado"});return}try{s&&g.current.set(e,s),await n.subscribeTopic(t,e),await u(),!N&&(!v||!y)&&(b(!0),O(!0));}catch(c){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao inscrever no t\xF3pico:",data:c}),r?.(c);}},[t,n,u,r,v,y,N]),$=useCallback(async e=>{if(!t){a({type:"WARN",environment:["development","homologation"],message:"Cliente n\xE3o registrado"});return}try{g.current.delete(e),await n.unsubscribeTopic(t,e),await u();}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao desinscrever do t\xF3pico:",data:s}),r?.(s);}},[t,n,u,r]),q=useCallback(async e=>{if(!(!t||e.length===0))try{await n.subscribeTopicsBatch(t,e),await u(),N||(b(!0),O(!0));}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao inscrever em t\xF3picos:",data:s}),r?.(s);}},[t,n,u,r,N]),J=useCallback(async e=>{if(!(!t||e.length===0))try{await n.unsubscribeTopicsBatch(t,e),await u();}catch(s){a({type:"ERROR",environment:["development","homologation"],message:"Erro ao desinscrever de t\xF3picos:",data:s}),r?.(s);}},[t,n,u,r]),U=useCallback(()=>{h(0);},[]),se=useMemo(()=>({clientId:t,subscribedTopics:A,isLoading:F,newMessageCount:x,isRegisterError:W,subscribeToTopic:_,unsubscribeFromTopic:$,subscribeTopicsBatch:q,unsubscribeTopicsBatch:J,resetMessageCount:U}),[t,A,F,x,W,_,$,q,J,U]);return jsx(Z.Provider,{value:se,children:d})};function Oe(){let d=useContext(Z);if(!d)throw new Error("usePushNotifications precisa estar dentro de PushNotificationProvider");return d}
9
9
 
10
10
  export { le as PushNotificationProvider, Oe as usePushNotifications };
@@ -1,4 +1,6 @@
1
1
  import { PopperProps } from '@mui/material/Popper';
2
+ import { Theme } from '@mui/material/styles';
3
+ import { SystemProps } from '@mui/system';
2
4
 
3
5
  interface BaseSuggestionData {
4
6
  id: string;
@@ -18,6 +20,8 @@ interface SuggestionDataSource<T extends BaseSuggestionData> {
18
20
  appendSpaceOnAdd?: boolean;
19
21
  displayTransform?: (id: string, display?: string) => string;
20
22
  onAdd?: (suggestion: SuggestionData<T>, start: number, end: number) => void;
23
+ color?: SystemProps<Theme>['color'];
24
+ backgroundColor?: SystemProps<Theme>['bgcolor'];
21
25
  }
22
26
  interface SuggestionOverlaySlotProps {
23
27
  popper?: Omit<PopperProps, 'anchorEl' | 'open'>;
@@ -1 +1 @@
1
- export { c as DefaultDisplayTransform, b as DefaultMarkupTemplate, a as DefaultTrigger } from '../chunk-SPIMM5MW.js';
1
+ export { c as DefaultDisplayTransform, b as DefaultMarkupTemplate, a as DefaultTrigger } from '../chunk-4LP75UX2.js';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zydon/common",
3
- "version": "2.7.33",
3
+ "version": "2.7.35",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "module": "./dist/index.js",
@@ -1,3 +0,0 @@
1
- var r="@",a="@[__display__](__id__)";function s(e,t,n){return n?t?.replace(/ /g,"\xA0")||e.replace(/ /g,"\xA0"):t||e}
2
-
3
- export { r as a, a as b, s as c };