@zydon/common 2.7.35 → 2.7.36
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.
|
@@ -11,7 +11,6 @@ interface FieldMentionsBaseProps<T extends BaseSuggestionData> {
|
|
|
11
11
|
onChange?: (newValue: string, newPlainText: string, mentions: MentionData[]) => void;
|
|
12
12
|
dataSources: SuggestionDataSource<T>[];
|
|
13
13
|
inputRef?: React.Ref<HTMLInputElement | HTMLTextAreaElement>;
|
|
14
|
-
highlightTextColor?: boolean;
|
|
15
14
|
slotProps?: {
|
|
16
15
|
suggestionsOverlay?: SuggestionOverlaySlotProps;
|
|
17
16
|
};
|
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
import { a as a$1 } from '../../chunk-WIPXRHSG.js';
|
|
2
2
|
import { b, c, a } from '../../chunk-4LP75UX2.js';
|
|
3
3
|
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
4
|
-
import
|
|
4
|
+
import We from '@mui/material/TextField';
|
|
5
5
|
import A from '@mui/material/Box';
|
|
6
|
-
import
|
|
6
|
+
import $e from '@mui/material/Portal';
|
|
7
7
|
import { jsxs, Fragment, jsx } from 'react/jsx-runtime';
|
|
8
8
|
import Q from 'invariant';
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
9
|
+
import Ve from '@mui/material/CircularProgress';
|
|
10
|
+
import Ue from '@mui/material/List';
|
|
11
|
+
import Ke from '@mui/material/Paper';
|
|
12
|
+
import Qe from '@mui/material/Popper';
|
|
13
|
+
import ze from '@mui/material/Stack';
|
|
14
|
+
import _e from '@mui/material/ListItemButton';
|
|
15
15
|
|
|
16
|
-
var
|
|
17
|
-
`,"")),!(
|
|
16
|
+
var Pe=({display:e,color:t,backgroundColor:n})=>jsx(A,{component:"span",sx:{color:t||"inherit",bgcolor:n},children:e}),ae=Pe;function z(e){return typeof e=="number"}function Le(e){let t=/^\/(.+)\/(\w+)?$/;return new RegExp(e.map(n=>{let[,o,s]=t.exec(n.toString())||[];return Q(!s,`RegExp flags are not supported. Change /${o}/${s} into /${o}/`),`(${o})`}).join("|"),"g")}function ce(e){let t=0;return e.indexOf("__id__")>=0&&t++,e.indexOf("__display__")>=0&&t++,t}function le(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,s){let l=Le(t.map(i=>i.regex?Ie(i.regex,i.markup||b):ke(i.markup||b))),f=2,u=t.map(({markup:i})=>{let p=f;return f+=ce(i||b)+1,p}),a,g=0,c$1=0;for(;(a=l.exec(e))!==null;){let i=u.find(C=>!!a?.[C]);if(i===void 0)continue;let p=u.indexOf(i),{markup:T,displayTransform:d}=t[p],b$1=i+le(T||b,"id"),y=i+le(T||b,"display"),h=a[b$1],M=d?d(h,a[y]):c(h,a[y],s),E=e.substring(g,a.index);o?.(E,g,c$1),c$1+=E.length,n(a[0],a.index,c$1,h,M,p,g),c$1+=M.length,g=l.lastIndex;}g<e.length&&o?.(e.substring(g),g,c$1);}function $(e,t,n){let o="";return H(e,t,(s,l,f,u,a)=>{o+=a;},s=>{o+=s;},n),o}var Ie=(e,t)=>{let n=(new RegExp(e.toString()+"|").exec("")?.length||0)-1,o=ce(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 ge(e,t,n,o,s,l,f){let u=$(e,l,f),a=u.length-t.length;n===null&&(n=s+a),o===null&&(o=n),n===o&&o===s&&u.length===t.length&&(n=n-1);let g=t.slice(n,s),c=Math.min(n,s),i=o;n===s&&(i=Math.max(o,n+a));let p=I(e,l,c,"START"),T=I(e,l,i,"END"),d=I(e,l,c,"NULL"),b=I(e,l,i,"NULL"),y=d===null||b===null,h=V(e,p||0,T||0,g);if(!y){let M=$(h,l,f);if(M!==t){for(c=0;t[c]===M[c];)c++;g=t.slice(c,s),i=u.lastIndexOf(t.substring(s)),p=I(e,l,c,"START"),T=I(e,l,i,"END"),h=V(e,p||0,T||0,g);}}return h}function I(e,t,n,o="START"){if(typeof n!="number")return n;let s;return H(e,t,(u,a,g,c,i)=>{s===void 0&&g+i.length>n&&(o==="NULL"?s=null:s=a+(o==="END"?u.length:0));},(u,a,g)=>{s===void 0&&g+u.length>=n&&(s=a+n-g);}),s===void 0?e.length:s}function V(e,t,n,o){return e.substring(0,t)+o+e.substring(n)}function pe(e,t,n){let o;return H(e,t,(l,f,u,a,g)=>{u<=n&&u+g.length>n&&(o=u);}),o}function G(e,t){let n=[];return H(e,t,(o,s,l,f,u,a)=>{n.push({id:f,display:u,dataSourceIndex:a,index:s,plainTextIndex:l});}),n}function de(e){return Object.values(e).reduce((t,{results:n})=>t+n.length,0)}function fe(e,t){let n=G(e,t),o=n[n.length-1];return o?o.plainTextIndex+o.display.length:0}function me(e,t){if(e instanceof RegExp)return e;{let n=K(e);return new RegExp(`(?:^|\\s)(${n}([^${t?"":"\\s"}${n}]*))$`)}}function he(e,t){return e instanceof Array?async function(n){let o=[];for(let s=0,l=e.length;s<l;++s){let f=e[s].display||e[s].id;Ce(f,n,t)>=0&&o.push(e[s]);}return o}:e}var Ce=(e,t,n)=>n?ue(e).indexOf(ue(t)):e.toLowerCase().indexOf(t.toLowerCase()),Oe=e=>{let t=e;return a$1.forEach(n=>{t=t.replace(n.letters,n.base);}),t},ue=e=>Oe(e).toLowerCase(),Se=(e,t,n)=>e.replace("__id__",t).replace("__display__",n||t);function ve(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 Be=e=>{let{highlighterRef:t,cursorRef:n,selectionEnd:o,selectionStart:s,value:l,dataSources:f,multiline:u}=e,a=[];H(l,f,(p,T,d,b,y,h)=>{let M=f[h];a.push(jsx(ae,{display:y,color:M?.color,backgroundColor:M?.backgroundColor},`${b}-${T}`));},(p,T,d)=>{if(u||(p=p.replaceAll(`
|
|
17
|
+
`,"")),!(s&&s===o&&s>=d&&s<=d+p.length))a.push(jsx(A,{component:"span",sx:{color:y=>y.palette.text.primary},children:p},`${T}-${d}`));else {let y=s-d,h=p.substring(0,y),M=p.substring(y);h&&a.push(jsx(A,{component:"span",sx:{color:E=>E.palette.text.primary},children:h},`${T}-${d}-precursor`)),a.push(jsx(A,{ref:n,component:"span",visibility:"hidden"},"cursor")),M&&a.push(jsx(A,{component:"span",sx:{color:E=>E.palette.text.primary},children:M},`${T}-${d}-postcursor`));}},u);let i=ve(e.inputRef);return jsx($e,{container:()=>e.inputRef?.parentElement||null,children:jsxs(A,{ref:t,sx:{position:"absolute",top:`${i.y}px`,left:`${i.x}px`,width:`${i.width}px`,height:`${i.height}px`,whiteSpace:u?"pre-wrap":"pre",overflow:"hidden",overscrollBehavior:"none",zIndex:1,pointerEvents:"none"},children:[a,jsx(A,{component:"span",visibility:"hidden",children:" "})]})})},xe=Be;var He=e=>{let{renderSuggestion:t,suggestion:n,focused:o,onClick:s,onMouseEnter:l}=e;if(t)return t(e);let f=c(n.id,n.display);return jsx(_e,{role:"option","aria-selected":o,selected:o,onClick:s,onMouseEnter:l,children:f})},Te=He;var Ge=e=>{let{value:t,dataSources:n,selectionStart:o,selectionEnd:s,cursorRef:l,onSelect:f,onMouseDown:u}=e,a$1=useRef(null),[g,c]=useState({}),[i,p]=useState(0),[T,d]=useState(!1),[b,y]=useState(!1);useEffect(()=>{let m=a$1.current;if(!T||!m||m.children.length===0)return;let r=m.scrollTop,{top:x,bottom:S}=m.children[i].getBoundingClientRect(),{top:D}=m.getBoundingClientRect();x=x-D+r,S=S-D+r,x<r?m.scrollTop=x:S>m.offsetHeight+r&&(m.scrollTop=S-m.offsetHeight),d(!1);},[T,a$1,i,d]);let h=useCallback(async(m,r,x,S,D,P)=>{try{let w=he(m.data,m.ignoreAccents);y(!0);let L=await w(r);c(R=>({...R,[x]:{queryInfo:{childIndex:x,query:r,querySequenceStart:S,querySequenceEnd:D,plainTextValue:P},results:L}}));}catch(w){console.error(w);}finally{y(!1);}},[]),M=useRef(n);useEffect(()=>{M.current=n;},[n]),useEffect(()=>{if(c({}),!o||o!==s)return;let m=M.current,r=$(t,m),x=I(r,m,o,"NULL");if(!x)return;let S=fe(r.substring(0,x),m),D=r.substring(S,o);m.forEach((P,w)=>{if(!P)return;let L=me(P.trigger||a,P.allowSpaceInQuery),R=D.match(L);if(R){let F=S+D.indexOf(R[1],R.index);h(P,R[2],w,F,F+R[1].length,r);}});},[o,s,t,h]);let E=useCallback(()=>{c({}),p(0);},[c,p]),C=useCallback((m,r)=>{f(m,r),E();},[f,E]),U=useCallback(m=>{p(m);},[p]),N=useMemo(()=>Object.values(g).reduce((m,{results:r,queryInfo:x})=>[...m,...r.map((S,D)=>jsx(Te,{id:S.id,query:x.query,index:D,suggestion:S,focused:D===i,onClick:()=>C(S,x),onMouseEnter:()=>U(D)},S.id))],[]),[g,C,U,i]);return o===null||o!==s||!b&&N.length===0?null:jsxs(Fragment,{children:[jsx(Je,{suggestions:g,clearSuggestions:E,onSelect:C,focusIndex:i,setFocusIndex:p,setScrollFocusedIntoView:d,loading:b}),jsx(Qe,{placement:"bottom-start",...e.slotProps?.popper,sx:{zIndex:2,...e.slotProps?.popper?.sx},open:!0,anchorEl:l.current,children:jsx(Ke,{elevation:8,onMouseDown:u,children:jsx(Ue,{ref:a$1,sx:{width:"300px",maxHeight:"40vh",overflow:"auto"},children:N.length>0?N:b&&jsx(ze,{justifyContent:"center",alignItems:"center",height:"40vh",children:jsx(Ve,{})})})})})]})},ye=Ge;var Je=e=>{let{suggestions:t,clearSuggestions:n,focusIndex:o,setFocusIndex:s,setScrollFocusedIntoView:l,onSelect:f,loading:u}=e;return useEffect(()=>{let a=i=>{if(u)return;let p=de(t);s((p+o+i)%p),l(!0);},g=()=>{if(u)return;let{result:i,queryInfo:p}=Object.values(t).reduce((T,{results:d,queryInfo:b})=>[...T,...d.map(y=>({result:y,queryInfo:b}))],[])[o];f(i,p);},c=i=>{switch(i.key){case"Escape":{n();break}case"ArrowDown":{a(1);break}case"ArrowUp":{a(-1);break}case"Enter":case"Tab":{g();break}default:return}i.preventDefault(),i.stopPropagation();};return document.addEventListener("keydown",c),()=>document.removeEventListener("keydown",c)},[t,n,o,s,f,l,u]),null};var qe=e=>{let[t,n]=useState(e.defaultValue||""),[o,s]=useState(null),l=useRef(null),f=useRef(null),u=useRef(!1),[a,g]=useState(null),[c$1,i]=useState(null),p=r=>{s(r),b$1&&(typeof b$1=="function"?b$1(r):b$1&&"current"in b$1&&typeof b$1!="function"&&(b$1.current=r));};useEffect(()=>{let r=o,x=()=>{!l.current||!r||(l.current.scrollLeft=r.scrollLeft,l.current.scrollTop=r.scrollTop);};return r?.addEventListener("scroll",x),()=>r?.removeEventListener("scroll",x)},[o,l]),useEffect(()=>{let r=o;!r||r.selectionStart===a&&r.selectionEnd===c$1||r.setSelectionRange(a,c$1);},[a,c$1,o]);let{value:T,dataSources:d,inputRef:b$1,...y}=e,h=T!==void 0?T:t,M=()=>{u.current||(g(null),i(null)),u.current=!1;},E=()=>{u.current=!0;},C=(r,{childIndex:x,querySequenceStart:S,querySequenceEnd:D,plainTextValue:P})=>{let w=d[x],{markup:L,displayTransform:R,appendSpaceOnAdd:F,onAdd:ee}=w,O=I(h,d,S,"START");if(!z(O))return;let te=O+D-S,ne=Se(L||b,r.id,r.display),q=(R||c)(r.id,r.display);F&&(ne+=" ",q+=" ");let oe=S+q.length;g(oe),i(oe);let re=V(h,O,te,ne),Me=G(re,d),Re=V(P,S,D,q);(e.onChange||n)(re,Re,Me),ee?.(r,O,te);},U=r=>{let x=r.target.value,S=a;z(S)||(S=r.target.selectionStart);let D=c$1;z(D)||(D=r.target.selectionEnd);let P=ge(h,x,S,D,r.target.selectionEnd||0,d,e.multiline);x=$(P,d);let w=r.target.selectionStart,L=r.target.selectionEnd,R=pe(h,d,r.target.selectionStart||0);if(R!==void 0&&L!==null&&L>R){let O=r.nativeEvent.data;w=R+(O?O.length:0),L=w;}g(w),i(L);let F=G(P,d);(e.onChange||n)(P,x,F);},N=r=>{g(r.target.selectionStart),i(r.target.selectionEnd),e.onSelect?.(r);},m={...y,value:$(h,d,e.multiline),onChange:U,onSelect:N,onBlur:M,InputProps:{sx:{overscrollBehavior:"none",color:"transparent",caretColor:r=>r.palette.text.primary}}};return jsxs(Fragment,{children:[jsx(xe,{highlighterRef:l,cursorRef:f,selectionStart:a,selectionEnd:c$1,value:h,dataSources:d,inputRef:o,multiline:m.multiline}),jsx(We,{inputRef:p,...m}),jsx(ye,{value:h,dataSources:d,selectionStart:a,selectionEnd:c$1,cursorRef:f,loading:!1,onSelect:C,onMouseDown:E,slotProps:e.slotProps?.suggestionsOverlay})]})},en=qe;
|
|
18
18
|
|
|
19
|
-
export {
|
|
19
|
+
export { en as default };
|