@zydon/common 2.7.33 → 2.7.34
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.
|
@@ -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-
|
|
2
|
+
import { b, c, a } from '../../chunk-4LP75UX2.js';
|
|
3
3
|
import { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
4
|
-
import
|
|
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
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
import
|
|
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:
|
|
17
|
-
`,"")),!(r&&r===o&&r>=
|
|
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 {
|
|
19
|
+
export { nn as default };
|
|
@@ -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-
|
|
1
|
+
export { c as DefaultDisplayTransform, b as DefaultMarkupTemplate, a as DefaultTrigger } from '../chunk-4LP75UX2.js';
|
package/package.json
CHANGED
package/dist/chunk-SPIMM5MW.js
DELETED