@univerjs/sheets-formula-ui 0.9.0 → 0.9.1-nightly.202507051607
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/lib/cjs/index.js +2 -2
- package/lib/es/index.js +1 -1
- package/lib/index.css +1 -1
- package/lib/index.js +1 -1
- package/lib/umd/index.js +2 -2
- package/package.json +12 -12
- package/LICENSE +0 -176
package/lib/cjs/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
`,d=Math.max(i.length-2,0);e.setSelectionRanges([{startOffset:d,endOffset:d}])}else e.setSelectionRanges(c)}})};function br(e){var r,o;const n=e.get(l.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(o=(r=n.getBody())==null?void 0:r.dataStream)!=null?o:"",offset:0}:void 0}var ve=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e[e.EDIT_OTHER_SHEET_REFERENCE=3]="EDIT_OTHER_SHEET_REFERENCE",e))(ve||{});function Tr(e){var F;const{editorId:t,isFocus:n,disableOnClick:s,unitId:r,subUnitId:o}=e,c=a.useDependency(H.IRenderManagerService),i=a.useDependency(l.IUniverInstanceService),d=c.getRenderById(r),h=c.getRenderById(t),m=h==null?void 0:h.with(Q.DocSelectionRenderService),p=a.useDependency(bt.DocSelectionManagerService),f=a.useDependency(l.Injector),[g,u]=C.useState(0),_=a.useDependency(T.LexerTreeBuilder),v=C.useRef(!0),S=d==null?void 0:d.with(exports.RefSelectionsRenderService),I=Te(g),E=i.getUnit(r,l.UniverInstanceType.UNIVER_SHEET),y=E==null?void 0:E.getSheetBySheetId(o),R=a.useEvent(L=>{S&&S.setSkipLastEnabled(L===1||L===3),I.current=L,u(L)}),O=a.useEvent(()=>{var B,re;if(!E)return;const L=E.getActiveSheet(),U=m==null?void 0:m.getActiveTextRange(),k=U!=null&&U.collapsed?U.startOffset:-1,$=br(f);if(!$)return;const D=(B=$==null?void 0:$.dataStream)==null?void 0:B.slice(0,-2),N=((re=_.sequenceNodesBuilder(D))!=null?re:[]).map(z=>typeof z=="object"?z.nodeType===T.sequenceNodeType.REFERENCE?{...z,range:T.deserializeRangeWithSheetWithCache(z.token)}:{...z,range:void 0}:z),x=D[k-1],M=D[k],P=N.find(z=>typeof z=="object"&&z.nodeType===T.sequenceNodeType.REFERENCE&&k===z.endIndex+2),j=x&&T.matchRefDrawToken(x)&&(!M||T.isFormulaLexerToken(M)&&M!==T.matchToken.OPEN_BRACKET),V=!!P;if((D==null?void 0:D.substring(0,1))==="="&&(j||V))if(V){if(v.current)return;!P.range.sheetName&&L.getSheetId()===(y==null?void 0:y.getSheetId())||P.range.sheetName===L.getName()?R(2):R(3)}else v.current=!1,R(1);else R(0)});return C.useEffect(()=>{const L=p.textSelection$.pipe(Y.filter(U=>U.unitId===t)).subscribe(()=>{O()});return()=>L.unsubscribe()},[O,p.textSelection$,t]),C.useEffect(()=>{n||(R(0),v.current=!0)},[n,R]),C.useEffect(()=>{var U;if(!s)return;const L=(U=h==null?void 0:h.mainComponent)==null?void 0:U.onPointerDown$.subscribeEvent(()=>{R(0),v.current=!0});return()=>L==null?void 0:L.unsubscribe()},[s,(F=h==null?void 0:h.mainComponent)==null?void 0:F.onPointerDown$,R]),C.useEffect(()=>{if(!n)return;const L=E==null?void 0:E.activeSheet$.subscribe(()=>{O()});return()=>L==null?void 0:L.unsubscribe()},[O,n,E==null?void 0:E.activeSheet$]),{isSelecting:g,isSelectingRef:I}}const xr=()=>{const e=a.useDependency(T.LexerTreeBuilder);return C.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function Mr(e,t,n){const s=new l.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:s,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function Ht(e){var E,y,R;const{unitId:t,subUnitId:n,currentWorkbook:s,refSelections:r,editor:o,refSelectionsService:c,refSelectionsRenderService:i,sheetSkeletonManagerService:d,themeService:h,univerInstanceService:m}=e,p=s.getUnitId(),f=m.getUnit(t,l.UniverInstanceType.UNIVER_SHEET),g=f==null?void 0:f.getActiveSheet(),u=[];if(!f||!g){c.setSelections(u);return}const _=g.getSheetId(),v=O=>{var F;return(F=f==null?void 0:f.getSheetBySheetName(O))==null?void 0:F.getSheetId()};if(!((E=d==null?void 0:d.getWorksheetSkeleton(_))==null?void 0:E.skeleton))return;const I=[];for(let O=0,F=r.length;O<F;O++){const L=r[O],{themeColor:U,token:k,refIndex:$,endIndex:D}=L,N=T.deserializeRangeWithSheet(k),{unitId:x,sheetName:M,range:P}=N,j=v(M);if(!j&&M||p!==t&&x!==p||x&&x!==p||j&&j!==_||!j&&_!==n)continue;const V=A.setEndForRange(P,g.getRowCount(),g.getColumnCount());V.unitId=t,V.sheetId=_,u.push({range:V,primary:null,style:Mr(h,U,$.toString())}),I.push(D)}if(o){const O=(R=(y=o.getSelectionRanges())==null?void 0:y[0])==null?void 0:R.startOffset,F=I.findIndex(L=>L+2===O);F!==-1?i==null||i.setActiveSelectionIndex(F):i==null||i.resetActiveSelectionIndex()}return u}function Or(e,t){const n=a.useDependency(l.IUniverInstanceService),s=a.useDependency(l.ThemeService),r=a.useDependency(A.IRefSelectionsService),o=a.useDependency(H.IRenderManagerService),c=a.useObservable(C.useMemo(()=>n.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[n])),i=c?o.getRenderById(c.getUnitId()):null,d=i==null?void 0:i.with(exports.RefSelectionsRenderService),h=i==null?void 0:i.with(w.SheetSkeletonManagerService),m=a.useEvent((p,f)=>{const g=n.getCurrentUnitOfType(l.UniverInstanceType.UNIVER_SHEET);if(!g||d!=null&&d.selectionMoving)return;const u=Ht({unitId:e,subUnitId:t,currentWorkbook:g,refSelections:p,editor:f,refSelectionsService:r,refSelectionsRenderService:d,sheetSkeletonManagerService:h,themeService:s,univerInstanceService:n});u&&r.setSelections(u)});return C.useEffect(()=>()=>{d==null||d.resetActiveSelectionIndex()},[d]),m}function Kt(e=""){const t=a.useDependency(Ce.IDescriptionService),n=Nr(),s=a.useDependency(l.ICommandService),r=C.useMemo(()=>e.length,[e]);return a.useEvent((c,i,d=!0,h)=>{const m=c.getDocumentData(),p=c.getEditorId();if(!m)return[];const f=m.body;if(!f)return[];const g=f.dataStream.slice(0,f.dataStream.length-2),u={dataStream:"",...m.body};if(!g.startsWith(e))return[];if(i==null||i.length===0)return u.textRuns=[],s.syncExecuteCommand(Q.ReplaceTextRunsCommand.id,{unitId:p,body:l.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:_,refSelections:v}=Dr(t,n,i);r&&_.forEach(E=>{E.ed=E.ed+r,E.st=E.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const S=i.reduce((E,y)=>typeof y=="string"?`${E}${y}`:`${E}${y.token}`,"");u.dataStream=`${e}${S}\r
|
|
3
3
|
`;let I;if(d){I=c.getSelectionRanges();const E=u.dataStream.length-2+r;I.forEach(y=>{y.startOffset=Math.max(0,Math.min(y.startOffset,E)),y.endOffset=Math.max(0,Math.min(y.endOffset,E))})}return s.syncExecuteCommand(Q.ReplaceTextRunsCommand.id,{unitId:p,body:l.getBodySlice(u,0,u.dataStream.length-2),textRanges:h!=null?h:I}),v}})}function Nr(){const e=a.useDependency(l.ThemeService),t=e.getCurrentTheme();return C.useMemo(()=>{const s=[e.getColorFromTheme("loop-color.1"),e.getColorFromTheme("loop-color.2"),e.getColorFromTheme("loop-color.3"),e.getColorFromTheme("loop-color.4"),e.getColorFromTheme("loop-color.5"),e.getColorFromTheme("loop-color.6"),e.getColorFromTheme("loop-color.7"),e.getColorFromTheme("loop-color.8"),e.getColorFromTheme("loop-color.9"),e.getColorFromTheme("loop-color.10"),e.getColorFromTheme("loop-color.11"),e.getColorFromTheme("loop-color.12")].map(i=>e.isValidThemeColor(i)?e.getColorFromTheme(i):i),r=e.getColorFromTheme("blue.700"),o=e.getColorFromTheme("jiqing.800"),c=e.getColorFromTheme("black");return{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:c}},[t])}function Dr(e,t,n){const{formulaRefColors:s,numberColor:r,stringColor:o,plainTextColor:c}=t,i=[],d=[],h=new Map;let m=0;for(let p=0,f=n.length;p<f;p++){const g=n[p];if(typeof g=="string"){const E=i[i.length-1],y=E?E.ed:0,R=y+g.length;i.push({st:y,ed:R,ts:{cl:{rgb:c},fs:11}});continue}if(e.hasDefinedNameDescription(g.token.trim())){i.push({st:g.startIndex,ed:g.endIndex+1,ts:{cl:{rgb:c},fs:11}});continue}const{startIndex:u,endIndex:_,nodeType:v,token:S}=g;let I="";if(v===T.sequenceNodeType.REFERENCE){if(h.has(S))I=h.get(S);else{const E=m%s.length;I=s[E],h.set(S,I),m++}d.push({refIndex:p,themeColor:I,token:S,startIndex:g.startIndex,endIndex:g.endIndex,index:d.length})}else v===T.sequenceNodeType.NUMBER?I=r:(v===T.sequenceNodeType.STRING||v===T.sequenceNodeType.ARRAY)&&(I=o);I&&I.length>0?i.push({st:u,ed:_+1,ts:{cl:{rgb:I},fs:11}}):i.push({st:u,ed:_+1,ts:{cl:{rgb:c},fs:11}})}return{textRuns:i,refSelections:d}}const wr=(e,t,n,s)=>{const r=a.useDependency(l.ICommandService),o=a.useDependency(a.IShortcutService),c=C.useRef(t);c.current=t;const i=C.useRef(s);i.current=s,C.useEffect(()=>{if(!n||!e)return;const h=`sheet.formula-embedding-editor.${n.getEditorId()}`,m=new l.DisposableCollection,p=(u,_)=>{if(i.current){i.current(u,_);return}let v=l.Direction.LEFT;u===a.KeyCode.ARROW_DOWN?v=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?v=l.Direction.UP:u===a.KeyCode.ARROW_RIGHT&&(v=l.Direction.RIGHT),_===a.MetaKeys.SHIFT?r.executeCommand(Q.MoveSelectionOperation.id,{direction:v}):r.executeCommand(Q.MoveCursorOperation.id,{direction:v})},f=(u,_)=>{let v=l.Direction.DOWN;u===a.KeyCode.ARROW_DOWN?v=l.Direction.DOWN:u===a.KeyCode.ARROW_UP?v=l.Direction.UP:u===a.KeyCode.ARROW_LEFT?v=l.Direction.LEFT:u===a.KeyCode.ARROW_RIGHT&&(v=l.Direction.RIGHT),c.current?_===a.MetaKeys.CTRL_COMMAND?r.executeCommand(w.MoveSelectionCommand.id,{direction:v,jumpOver:w.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:c.current===ve.NEED_ADD||c.current===ve.EDIT_OTHER_SHEET_REFERENCE}):_===a.MetaKeys.SHIFT?r.executeCommand(w.ExpandSelectionCommand.id,{direction:v,extra:"formula-editor"}):_===(a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT)?r.executeCommand(w.ExpandSelectionCommand.id,{direction:v,jumpOver:w.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(w.MoveSelectionCommand.id,{direction:v,extra:"formula-editor",fromCurrentSelection:c.current===ve.NEED_ADD||c.current===ve.EDIT_OTHER_SHEET_REFERENCE}):p(u,_)};return m.add(r.registerCommand({id:h,type:l.CommandType.OPERATION,handler(u,_){const{keyCode:v,metaKey:S}=_;f(v,S)}})),[{keyCode:a.KeyCode.ARROW_DOWN},{keyCode:a.KeyCode.ARROW_LEFT},{keyCode:a.KeyCode.ARROW_RIGHT},{keyCode:a.KeyCode.ARROW_UP},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND},{keyCode:a.KeyCode.ARROW_DOWN,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_LEFT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_RIGHT,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT},{keyCode:a.KeyCode.ARROW_UP,metaKey:a.MetaKeys.CTRL_COMMAND|a.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:_})=>({id:h,binding:_?u|_:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:u,metaKey:_}})).forEach(u=>{m.add(o.registerShortcut(u))}),()=>{m.dispose()}},[r,n,e,o])},kr=(e,t,n,s=!0)=>{var f;const r=a.useDependency(H.IRenderManagerService),o=a.useDependency(l.IContextService),c=a.useDependency(a.IContextMenuService),i=a.useDependency(A.IRefSelectionsService),d=a.useDependency(l.IUniverInstanceService),h=a.useObservable(C.useMemo(()=>d.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[d])),m=r.getRenderById((f=h==null?void 0:h.getUnitId())!=null?f:""),p=m==null?void 0:m.with(exports.RefSelectionsRenderService);C.useLayoutEffect(()=>{if(e)return o.setContextValue(l.EDITOR_ACTIVATED,!0),()=>{o.setContextValue(l.EDITOR_ACTIVATED,!1),i.clear()}},[o,e,i]),C.useLayoutEffect(()=>{if(e&&t){const g=p==null?void 0:p.enableSelectionChanging();return o.setContextValue(A.REF_SELECTIONS_ENABLED,!0),()=>{o.setContextValue(A.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[o,e,p,t]),C.useEffect(()=>{if(e)return o.setContextValue(l.EDITOR_ACTIVATED,!0),s&&c.disable(),()=>{o.setContextValue(l.EDITOR_ACTIVATED,!1),s&&c.enable()}},[c,o,e,s]),C.useEffect(()=>{e&&(p==null||p.setSkipLastEnabled(!1))},[e,p])},Ar=(e,t,n)=>{const s=a.useDependency(l.IUniverInstanceService),r=a.useDependency(A.SheetsSelectionsService);return C.useCallback(()=>{if(e){const c=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],i=s.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),d=i==null?void 0:i.getActiveSheet();(i==null?void 0:i.getUnitId())!==t&&s.setCurrentUnitForType(t),d&&d.getSheetId()===n&&r.setSelections(c)}},[e,r,n,t,s])},Fr=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),it=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),He=(e,t=!1,n="",s=!1)=>!t&&!s?e.map(r=>T.serializeRange(r.range)):e.map(r=>s?T.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?T.serializeRangeWithSheet(r.sheetName,r.range):T.serializeRange(r.range)),Pr=e=>{var m,p,f;const{editor:t,lexerTreeBuilder:n}=e,s=t==null?void 0:t.getSelectionRanges();if((s==null?void 0:s.length)!==1)return;const o=s[0].startOffset-1,c=((p=(m=t==null?void 0:t.getDocumentData().body)==null?void 0:m.dataStream)!=null?p:`\r
|
|
4
4
|
`).slice(0,-2),i=(f=n.sequenceNodesBuilder(c.slice(1)))!=null?f:[],d=lt(i,o,!1),h=Vt(i,d);return{nodeIndex:d,updatingRefIndex:h,sequenceNodes:i,offset:o}},Lr=()=>{},Ur=(e,t,n,s,r,o,c,i,d,h=Lr)=>{var $;const m=a.useDependency(H.IRenderManagerService),p=a.useDependency(l.IUniverInstanceService),f=a.useDependency(l.ICommandService),g=a.useDependency(bt.DocSelectionManagerService),u=a.useDependency(l.ThemeService),_=a.useDependency(T.LexerTreeBuilder),v=p.getUnit(s),S=a.useEvent((D,N)=>{var x,M,P;return(P=(M=(x=p.getUnit(D))==null?void 0:x.getSheetBySheetId(N))==null?void 0:M.getName())!=null?P:""}),I=C.useMemo(()=>S(s,r),[S,r,s]),E=a.useObservable(v==null?void 0:v.activeSheet$),y=Te({activeSheet:E,sheetName:I}),R=a.useObservable(C.useMemo(()=>p.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET),[p])),O=m.getRenderById(($=R==null?void 0:R.getUnitId())!=null?$:""),F=O==null?void 0:O.with(exports.RefSelectionsRenderService),L=O==null?void 0:O.with(w.SheetSkeletonManagerService),U=a.useDependency(A.IRefSelectionsService),k=a.useEvent((D,N)=>{var B,re,z,he,xe,ee,Le,Me,Ue;const x=Pr({editor:d,lexerTreeBuilder:_});if(!x)return;const{nodeIndex:M,updatingRefIndex:P,sequenceNodes:j,offset:V}=x;if(n.current===ve.NEED_ADD)if(V!==0){if(M===-1&&j.length)return;const K=D[D.length-1],J=j.splice(M+1),ae=(B=K.sheetId)!=null?B:r,ue={range:K,unitId:(re=K.unitId)!=null?re:R.getUnitId(),sheetName:S((z=K.unitId)!=null?z:R.getUnitId(),ae)},se=ae!==r,X=(R==null?void 0:R.getUnitId())!==s,de=He([ue],c&&(se||X),I,X);j.push({token:de[0],nodeType:T.sequenceNodeType.REFERENCE});const De=[...j,...J],ge=it(De);h(ge,Fr(j),N)}else{const K=D[D.length-1],J=(he=K.sheetId)!=null?he:r,ae={range:K,unitId:(xe=K.unitId)!=null?xe:R.getUnitId(),sheetName:S((ee=K.unitId)!=null?ee:R.getUnitId(),J)},ue=J!==r,se=(R==null?void 0:R.getUnitId())!==s,X=He([ae],c&&(ue||se),I,se);j.unshift({token:X[0],nodeType:T.sequenceNodeType.REFERENCE});const de=it(j);h(de,X[0].length,N)}else if(n.current===ve.EDIT_OTHER_SHEET_REFERENCE){const K=D.pop();if(!K)return;const J=j[M];if(typeof J=="object"&&J.nodeType===T.sequenceNodeType.REFERENCE){const ae=J.token;J.token=I===(E==null?void 0:E.getName())?T.serializeRange(K):T.serializeRangeWithSheet(E.getName(),K);const ue=V+(J.token.length-ae.length);h(T.generateStringWithSequence(j),ue,N)}}else{const K=[...D];if(P!==-1){const G=K.pop();G&&K.splice(P,0,G)}let J=0;const ae=j.map(G=>{var oe,me,Oe,_e;if(typeof G=="string")return G;if(G.nodeType===T.sequenceNodeType.REFERENCE){const le=T.deserializeRangeWithSheet(G.token);if(le.sheetName||(le.sheetName=I),c&&((oe=y.current.activeSheet)==null?void 0:oe.getName())!==le.sheetName)return G.token;const te=K[J];if(J++,!te)return"";const we=(me=te.sheetId)!=null?me:r,tt={range:te,unitId:(Oe=te.unitId)!=null?Oe:R.getUnitId(),sheetName:S((_e=te.unitId)!=null?_e:R.getUnitId(),we)},$e=(R==null?void 0:R.getUnitId())!==s;return He([tt],c&&(we!==r||$e),I,$e)[0]}return G.token});let ue="",se;ae.forEach((G,oe)=>{ue+=G,oe===M&&(se=ue.length)});const X=[];for(let G=J;G<=D.length-1;G++){const oe=D[G],me=(Le=oe.sheetId)!=null?Le:r,Oe={range:oe,unitId:(Me=oe.unitId)!=null?Me:R.getUnitId(),sheetName:S((Ue=oe.unitId)!=null?Ue:R.getUnitId(),me)},_e=(R==null?void 0:R.getUnitId())!==s,te=He([Oe],c&&(me!==r||_e),I,_e);X.push(te[0])}const de=j[j.length-1],De=de&&(typeof de=="string"?!1:de.nodeType===T.sequenceNodeType.REFERENCE),ge=`${ue}${X.length&&De?",":""}${X.join(",")}`;h(ge,!X.length&&se?se:ge.length,N)}});C.useEffect(()=>{if(F&&e){let D=!0;const N=(M,P)=>{if(D){D=!1;return}k(M.map(j=>j.rangeWithCoord),P)},x=new l.DisposableCollection;return x.add(F.selectionMoving$.subscribe(M=>{N(M,!1)})),x.add(F.selectionMoveEnd$.subscribe(M=>{N(M,!0)})),()=>{x.dispose()}}},[e,k,F]),C.useEffect(()=>{if(t&&F&&d){const D=new l.DisposableCollection,N=()=>{D.dispose(),F.getSelectionControls().forEach((P,j)=>{D.add(P.selectionScaling$.subscribe(V=>{const B=F.getSelectionDataWithStyle().map(z=>z.rangeWithCoord),re=B[j];V.sheetId=re.sheetId,V.unitId=re.unitId,B[j]=V,k(B,!1)})),D.add(P.selectionMoving$.subscribe(V=>{const B=F.getSelectionDataWithStyle().map(z=>z.rangeWithCoord),re=B[j];V.sheetId=re.sheetId,V.unitId=re.unitId,B[j]=V,k(B,!0)}))})},x=Y.merge(d.input$,U.selectionSet$,F.selectionMoveEnd$).pipe(Jt.debounceTime(50)).subscribe(()=>{N()});return()=>{x.unsubscribe(),D.dispose()}}},[d,t,k,F,U.selectionSet$]),F==null||F.getSelectionDataWithStyle(),C.useEffect(()=>{if(i){const D=f.onCommandExecuted(N=>{var M;if(N.id!==A.SetSelectionsOperation.id)return;const x=N.params;if(x.extra==="formula-editor"&&x.selections.length){const P=x.selections[x.selections.length-1];if(P){const j=n.current===ve.NEED_ADD,V=((M=F==null?void 0:F.getSelectionDataWithStyle())!=null?M:[]).map(B=>B.rangeWithCoord);j?V.push(P.range):V[V.length-1]=P.range,k(V,!0)}}});return()=>{D.dispose()}}},[f,d,n,_,i,k,F]),C.useEffect(()=>{if(!d)return;const D=g.textSelection$.subscribe(N=>{N.unitId===d.getEditorId()&&Ht({unitId:s,subUnitId:r,refSelections:o.current,editor:d,refSelectionsService:U,refSelectionsRenderService:F,sheetSkeletonManagerService:L,themeService:u,univerInstanceService:p,currentWorkbook:R})});return()=>D.unsubscribe()},[g.textSelection$,d,o,F,U,L,r,u,s,p])},$r=(e,t,n,s,r,o)=>{const c=a.useDependency(l.ICommandService),i=a.useDependency(Q.IEditorService),h=a.useDependency(H.IRenderManagerService).getRenderById(t),m=a.useDependency(l.IUniverInstanceService),p=h==null?void 0:h.with(exports.RefSelectionsRenderService);C.useEffect(()=>{if(e&&p)if(n){const f=()=>{const _=p.getSelectionControls().length;for(let v=1;v<=_;v++)p.clearLastSelection();return setTimeout(()=>{o()},30)},g=c.onCommandExecuted(_=>{_.id===A.SetWorksheetActiveOperation.id&&f()}),u=m.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{f()});return()=>{g.dispose(),u.unsubscribe()}}else{const f=c.beforeCommandExecuted(g=>{if(g.id===A.SetWorksheetActiveOperation.id){s(!1),r(),o();const u=i.getEditor(l.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{f.dispose()}}},[e,p])},jr=(e,t,n)=>{const s=a.useDependency(T.LexerTreeBuilder),r=C.useRef(!0);C.useEffect(()=>{if(e){const o=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(o)}}},[e]),C.useEffect(()=>{if(!r.current&&t){const o=s.checkIfAddBracket(n);t(o===0&&n.startsWith(T.operatorToken.EQUALS),`${n}`)}},[n,t])},Wr=(e,t=[],n)=>{const s=a.useDependency(Ce.IDescriptionService),[r,o]=C.useState([]),[c,i]=C.useState(""),d=C.useRef(-1),h=Te({nodes:t}),m=()=>{o([]),i(""),d.current=-1};return C.useEffect(()=>{if(n&&e){const f=n.input$.pipe(Y.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const u=h.current.nodes,_=g[0];if(_.collapsed){const v=lt(u,_.startOffset-1,!1);d.current=v;const S=u[v];if(S&&typeof S!="string"&&S.nodeType===T.sequenceNodeType.FUNCTION){d.current=v;const I=S.token,E=s.getSearchListByNameFirstLetter(I);o(E),i(I);return}}}d.current=-1,i(""),o(u=>u!=null&&u.length?[]:u)});return()=>{f.unsubscribe()}}},[n,e]),C.useEffect(()=>{e||m()},[e]),{searchList:r,searchText:c,handlerFormulaReplace:f=>{const g=[...h.current.nodes];if(d.current!==-1){const u=g.splice(d.current+1),_=g.pop()||"";let v=(typeof _=="string"?_.length:_.token.length)-f.length;return g.push(f),u[0]!==T.matchToken.OPEN_BRACKET&&(g.push(T.matchToken.OPEN_BRACKET),v--),{text:it([...g,...u]),offset:v}}},reset:m}},Vr=()=>{},Br=C.forwardRef(Hr);function Hr(e,t){const{isFocus:n,sequenceNodes:s,onSelect:r,editor:o,onClose:c=Vr}=e,i=o.getEditorId(),d=a.useDependency(a.IShortcutService),h=a.useDependency(l.ICommandService),{searchList:m,searchText:p,handlerFormulaReplace:f,reset:g}=Wr(n,s,o),u=C.useMemo(()=>!!m.length,[m]),_=C.useRef(void 0),[v,S]=C.useState(0),I=C.useRef(!1),[E]=Bt(i,u,[p,m]),y=Te({searchList:m,active:v}),R=k=>{const $=f(k);$&&(g(),r($))};function O(k){I.current&&S(k)}function F(){I.current&&S(-1)}C.useEffect(()=>{if(!m.length)return;const k=`sheet.formula-embedding-editor.search_function.${i}`,$=new l.DisposableCollection,D=N=>{const{searchList:x,active:M}=y.current;switch(N){case a.KeyCode.ARROW_UP:{S(P=>{const j=Math.max(0,P-1);return L(j),j});break}case a.KeyCode.ARROW_DOWN:{S(P=>{const j=Math.min(x.length-1,P+1);return L(j),j});break}case a.KeyCode.TAB:case a.KeyCode.ENTER:{const P=x[M];R(P.name);break}case a.KeyCode.ESC:{g(),c();break}}};return $.add(h.registerCommand({id:k,type:l.CommandType.OPERATION,handler(N,x){const{keyCode:M}=x;D(M)}})),[a.KeyCode.ARROW_UP,a.KeyCode.ARROW_DOWN,a.KeyCode.ENTER,a.KeyCode.ESC,a.KeyCode.TAB].map(N=>({id:k,binding:N,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:H.DeviceInputEventType.Keyboard,keyCode:N}})).forEach(N=>{$.add(d.registerShortcut(N))}),()=>{$.dispose()}},[m]);function L(k){const $=_.current;if(!$)return;const D=$.children[k];if(!D)return;const x=$.getBoundingClientRect().top,M=$.offsetHeight,P=D.getBoundingClientRect(),j=P.top,V=P.height;if(j>=0&&j>x&&j-x+V<=M)return;const B=D.offsetTop-(M-V)/2;$.scrollTo({top:B,behavior:"smooth"})}const U=C.useMemo(()=>{let k="";return()=>{clearTimeout(k),I.current=!0,k=setTimeout(()=>{I.current=!1},300)}},[]);return m.length>0&&u&&b.jsx(a.RectPopup,{portal:!0,anchorRect$:E,direction:"vertical",children:b.jsx("ul",{ref:k=>{_.current=k,t&&(t.current=k)},"data-u-comp":"sheets-formula-editor",className:W.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",W.borderClassName,W.scrollbarClassName),children:m.map((k,$)=>b.jsxs("li",{className:W.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":v===$}),onMouseEnter:()=>O($),onMouseLeave:F,onMouseMove:U,onClick:()=>{R(k.name),o&&o.focus()},children:[b.jsxs("span",{className:"univer-text-xs",children:[b.jsx("span",{className:"univer-text-red-500",children:k.name.substring(0,p.length)}),b.jsx("span",{children:k.name.slice(p.length)})]}),b.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:k.desc})]},k.name))})})}const Kr=e=>e.startsWith(T.operatorToken.EQUALS)?e.slice(1):"",yt=()=>{},qt=C.forwardRef((e,t)=>{var ft,gt;const{errorText:n,initValue:s,unitId:r,subUnitId:o,isFocus:c=!0,isSupportAcrossSheet:i=!1,onFocus:d=yt,onBlur:h=yt,onChange:m,onVerify:p,className:f,editorId:g,moveCursor:u=!0,onFormulaSelectingChange:_,keyboardEventConfig:v,onMoveInEditor:S,resetSelectionOnBlur:I=!0,autoScrollbar:E=!0,isSingle:y=!0,disableSelectionOnClick:R=!1,autofocus:O=!0,disableContextMenu:F,style:L}=e,U=a.useDependency(Q.IEditorService),k=C.useRef(null),$=a.useEvent(m);C.useImperativeHandle(t,()=>({isClickOutSide:Z=>k.current?!k.current.contains(Z.target):!1}));const D=a.useEvent(_),N=C.useRef(null),x=C.useRef(void 0),M=x.current,[P,j]=C.useState(c),V=C.useRef(null),B=C.useMemo(()=>g!=null?g:l.createInternalEditorID(`${w.EMBEDDING_FORMULA_EDITOR}-${l.generateRandomId(4)}`),[]),re=C.useMemo(()=>n!==void 0,[n]),z=a.useDependency(l.IUniverInstanceService),he=z.getUnit(B);a.useObservable(he==null?void 0:he.change$);const xe=xr(),ee=l.BuildTextUtils.transform.getPlainText((gt=(ft=he==null?void 0:he.getBody())==null?void 0:ft.dataStream)!=null?gt:""),Le=Te(ee),Me=C.useMemo(()=>Kr(ee),[ee]),Ue=C.useMemo(()=>xe(Me),[Me,xe]),{isSelecting:K,isSelectingRef:J}=Tr({unitId:r,subUnitId:o,editorId:B,isFocus:P,disableOnClick:R}),ae=C.useRef(""),se=a.useDependency(H.IRenderManagerService).getRenderById(B),X=se==null?void 0:se.with(Q.DocSelectionRenderService),de=X==null?void 0:X.isFocusing,De=C.useMemo(()=>z.getCurrentTypeOfUnit$(l.UniverInstanceType.UNIVER_DOC),[z]),ge=a.useObservable(De),G=(ge==null?void 0:ge.getUnitId())===B,oe=C.useRef([]),me=K;a.useUpdateEffect(()=>{$(ee)},[ee,$]);const Oe=Kt("="),_e=Or(r,o),le=a.useEvent((Z,ne=!0,pe,fe)=>{if(!x.current)return;ae.current=Z;const je=Z[0]==="="?Z.slice(1):"",Se=xe(je),zt=Se.reduce((Re,Ve)=>typeof Ve=="object"?`${Re}${Ve.token}`:`${Re}${Ve}`,""),We=Oe(x.current,zt===je?Se:[],ne,fe);if(oe.current=We,pe){const Re=fe!=null?fe:M==null?void 0:M.getSelectionRanges();if((Re==null?void 0:Re.length)!==1)return;const Gt=Re[0].startOffset-1,Zt=lt(Se,Gt,!1),mt=Vt(Se,Zt);if(mt>=0){const pt=We.splice(mt,1)[0];pt&&We.push(pt)}_e(P?We:[],x.current)}});C.useEffect(()=>{P&&le(ee,!1,!0)},[P]),C.useEffect(()=>{if(P){if(ae.current===ee)return;le(ee,!1,!0)}},[ee]),jr(P,p,ee);const te=Er(M),we=Ar(P,r,o);C.useEffect(()=>{var Z;D(K,(Z=X==null?void 0:X.isFocusing)!=null?Z:!0)},[D,K]),Q.useKeyboardEvent(P,v,M),C.useLayoutEffect(()=>{let Z;if(V.current){Z=U.register({autofocus:O,editorUnitId:B,initialSnapshot:{id:B,body:{dataStream:`${s}\r
|
|
5
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},V.current);const ne=U.getEditor(B);x.current=ne,le(s,!1,!0)}return()=>{Z==null||Z.dispose()}},[]),C.useLayoutEffect(()=>{c?(j(c),te()):(I&&(M==null||M.blur(),we()),j(c))},[c,M,te,we,I]);const{checkScrollBar:tt}=Q.useResize(M,y,E);kr(P,!!(K&&G),r,F),wr(!!(P&&de&&u),me,M,S);const $e=a.useEvent((Z,ne,pe)=>{if(!de)return;const fe=ne!==-1?[{startOffset:ne+1,endOffset:ne+1,collapsed:!0}]:void 0;le(`=${Z}`,!0,pe,fe),pe&&(te(),ne!==-1&&setTimeout(()=>{const je={startOffset:ne+1,endOffset:ne+1},Se=M==null?void 0:M.render.with(Q.DocBackScrollRenderController);Se==null||Se.scrollToRange({...je,collapsed:!0})},50),tt())});Ur(P&&!!(K&&G),P,J,r,o,oe,i,!!me,M,$e),$r(P&&!!(K&&G),r,i,j,h,()=>{le(Le.current,!1,!0)});const dt=Z=>{if(Z){const ne=M==null?void 0:M.getSelectionRanges();if(ne&&ne.length===1){const pe=ne[0];if(pe.collapsed){const fe=Z.offset;setTimeout(()=>{M==null||M.setSelectionRanges([{startOffset:pe.startOffset-fe,endOffset:pe.endOffset-fe}])},30)}}te(),le(`=${Z.text}`)}},ht=()=>{j(!0),d(),te()};return b.jsxs("div",{className:f,children:[b.jsx("div",{className:W.clsx(`
|
|
5
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},V.current);const ne=U.getEditor(B);x.current=ne,le(s,!1,!0)}return()=>{Z==null||Z.dispose()}},[]),C.useLayoutEffect(()=>{c?(j(c),te()):(I&&(M==null||M.blur(),we()),j(c))},[c,M,te,we,I]);const{checkScrollBar:tt}=Q.useResize(M,y,E);kr(P,!!(K&&G),r,F),wr(!!(P&&de&&u),me,M,S);const $e=a.useEvent((Z,ne,pe)=>{if(!de)return;const fe=ne!==-1?[{startOffset:ne+1,endOffset:ne+1,collapsed:!0}]:void 0;le(`=${Z}`,!0,pe,fe),pe&&(te(),ne!==-1&&setTimeout(()=>{const je={startOffset:ne+1,endOffset:ne+1},Se=M==null?void 0:M.render.with(Q.DocBackScrollRenderController);Se==null||Se.scrollToRange({...je,collapsed:!0})},50),tt())});Ur(P&&!!(K&&G),P,J,r,o,oe,i,!!me,M,$e),$r(P&&!!(K&&G),r,i,j,h,()=>{le(Le.current,!1,!0)});const dt=Z=>{if(Z){const ne=M==null?void 0:M.getSelectionRanges();if(ne&&ne.length===1){const pe=ne[0];if(pe.collapsed){const fe=Z.offset;setTimeout(()=>{M==null||M.setSelectionRanges([{startOffset:pe.startOffset-fe,endOffset:pe.endOffset-fe}])},30)}}te(),le(`=${Z.text}`)}},ht=()=>{j(!0),d(),te()};return b.jsxs("div",{className:f,children:[b.jsx("div",{ref:k,className:W.clsx(`
|
|
6
6
|
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
7
7
|
univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1
|
|
8
|
-
`,{"univer-ring-primary-500":P,"univer-ring-red-500":re}),ref:k,children:b.jsx("div",{ref:V,className:"univer-relative univer-h-full univer-w-full",onMouseUp:ht})}),n!==void 0?b.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,M&&Me!==""?b.jsx(yr,{editor:M,isFocus:P,formulaText:ee,onClose:()=>te()}):null,M?b.jsx(Br,{isFocus:P,sequenceNodes:Ue,onSelect:dt,ref:N,editor:M}):null]})});function qr(e,t,n,s){const r=a.useDependency(T.LexerTreeBuilder),o=Kt(""),c=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[i,d]=C.useState([]),h=a.useDependency(w.IMarkSelectionService),m=C.useRef(""),p=a.useDependency(l.IUniverInstanceService);return C.useEffect(()=>{if(!e)return;const f=e.getDocumentDataModel().getPlainText();if(m.current===f)return;m.current=f;const g=r.sequenceNodesBuilder(f);d(g!=null?g:[])},[c,e,r]),C.useEffect(()=>{var u,_;if(!e)return;if(!t){const v=e.getDocumentData();e.setDocumentData({...v,body:{...v.body,dataStream:(_=(u=v.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const f=o(e,i,!1),g=new l.DisposableCollection;return f.forEach(v=>{const S=T.deserializeRangeWithSheet(v.token),I=p.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),E=I==null?void 0:I.getActiveSheet();if(!S.sheetName&&s!==(E==null?void 0:E.getSheetId())||S.sheetName&&(E==null?void 0:E.getName())!==S.sheetName)return;const y=new l.ColorKit(v.themeColor).toRgb(),R=h.addShape({range:S.range,style:{stroke:v.themeColor,fill:`rgba(${y.r}, ${y.g}, ${y.b}, 0.1)`,strokeDash:12},primary:null});R&&g.add(()=>h.removeShape(R))}),()=>{g.dispose()}},[e,t,o,h,i]),{sequenceNodes:i}}function Yr(e){const t=a.useDependency(A.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:s,subUnitId:r,onChange:o}=e,i=a.useDependency(l.IUniverInstanceService).getUnit(s,l.UniverInstanceType.UNIVER_SHEET),d=a.useEvent(o),h=a.useEvent((m,p)=>{const f=i==null?void 0:i.getActiveSheet();if(!f||!n&&f.getSheetId()!==r||!(m!=null&&m.length))return;const g=m.map(u=>({range:u.range,unitId:s,sheetName:f.getSheetId()===r?"":f.getName()}));d(g,p)});C.useEffect(()=>{const m=new l.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(p=>{h(p,!0)})),m.add(t.selectionMoving$.subscribe(p=>{h(p,!1)})),m.add(t.selectionMoveEnd$.subscribe(p=>{h(p,!1)})),()=>{m.dispose()}},[h,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Et=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),zr=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function Gr(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:c,onConfirm:i,onClose:d,onShowBySelection:h}=e,m=a.useDependency(l.LocaleService),p=a.useDependency(T.LexerTreeBuilder),[f,g]=C.useState([]),[u,_]=C.useState(0),v=C.useRef(null);C.useEffect(()=>{if(t&&n.length){const y=n.map(R=>R.sheetName?T.serializeRangeWithSheet(R.sheetName,R.range):T.serializeRange(R.range));g(y),_(y.length-1)}else g([""]),_(0)},[t]);const S=(y,R)=>{const O=[...f];O[y]=R,g(O)},I=()=>{g([...f,""]),_(f.length)},E=y=>{f.splice(y,1),g([...f])};return Yr({unitId:s,subUnitId:r,supportAcrossSheet:c,onChange:(y,R)=>{if(!t&&h!=null&&h(y))return;const O=new Set(f),F=y.map(k=>k.sheetName?T.serializeRangeWithSheet(k.sheetName,k.range):T.serializeRange(k.range)),L=F.filter(k=>!O.has(k));if(!L.length)return;const U=[...f];if(F.length>1){R||U.splice(u,1),U.push(...L);const k=U.slice(0,o);g(k),_(k.length-1),requestAnimationFrame(()=>{var $;($=v.current)==null||$.scrollTo({top:v.current.scrollHeight})})}else{U.splice(u,1,...L);const k=U.slice(0,o);g(k),_(u+L.length-1)}}}),b.jsx(W.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:b.jsxs("footer",{className:"univer-flex univer-gap-2",children:[b.jsx(W.Button,{onClick:d,children:m.t("rangeSelector.cancel")}),b.jsx(W.Button,{variant:"primary",onClick:()=>{i(f.filter(y=>{const R=p.sequenceNodesBuilder(y);return R&&R.length===1&&typeof R[0]!="string"&&R[0].nodeType===T.sequenceNodeType.REFERENCE}).map(y=>T.deserializeRangeWithSheet(y)).map(y=>({...y,range:zr(y.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:d,children:b.jsxs("div",{ref:v,className:W.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",W.scrollbarClassName),children:[f.map((y,R)=>b.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[b.jsx(W.Input,{className:W.clsx("univer-w-full",{"univer-border-primary-600":u===R}),placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>_(R),value:y,onChange:O=>S(R,O)}),f.length>1&&b.jsx(Ut,{className:"univer-cursor-pointer",onClick:()=>E(R)})]},R)),f.length<o&&b.jsx("div",{children:b.jsxs(W.Button,{variant:"link",onClick:I,children:[b.jsx($t,{}),b.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function Zr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Xr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function ut(e){const[t,n]=C.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:c,maxRangeCount:i,supportAcrossSheet:d,autoFocus:h,onChange:m,onRangeSelectorDialogVisibleChange:p,onClickOutside:f,onFocusChange:g,forceShowDialogWhenSelectionChanged:u,hideEditor:_,resetRange:v}=e,[S,I]=C.useState(h!=null?h:!1),[E,y]=C.useState(!1),[R,O]=C.useState([]),F=a.useDependency(l.LocaleService),L=a.useDependency(Q.IEditorService),{sequenceNodes:U}=qr(t,S,o,c),k=Te(U),$=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),N=a.useEvent(()=>{var x;D(),O(Zr((x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")),y(!0)});return C.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>Et(k.current),showDialog:x=>{D(),O(x),y(!0)},hideDialog:()=>{O([]),y(!1)},getValue:()=>{var x;return(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:""}})},[D,t,L,r,k]),C.useEffect(()=>{var x;s==null||s(Et(U),(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")},[U]),C.useEffect(()=>{p==null||p(E)},[E]),C.useEffect(()=>{if(E&&v)return()=>{const x={unitId:o,subUnitId:c,selections:v};$.executeCommand(A.SetSelectionsOperation.id,x)}},[E]),b.jsxs(b.Fragment,{children:[_?null:b.jsx(Q.RichTextEditor,{isSingle:!0,...e,onFocusChange:(x,M)=>{I(x),g==null||g(x,M)},editorRef:n,onClickOutside:()=>{I(!1),D(),f==null||f()},icon:b.jsx(W.Tooltip,{title:F.t("rangeSelector.buttonTooltip"),placement:"bottom",children:b.jsx(Wt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:N})})}),b.jsx(Gr,{initialValue:R,unitId:o,subUnitId:c,visible:E,maxRangeCount:i,onConfirm:x=>{const M=Xr(x),P=l.RichTextBuilder.newEmptyData();P.body.dataStream=M,t==null||t.replaceText(M,!1),m==null||m(P,M),y(!1),O([]),requestAnimationFrame(()=>{D()})},onClose:()=>{y(!1),O([])},supportAcrossSheet:d,onShowBySelection:x=>S||u?(O(x),y(!0),!1):!0})]})}const Qr=()=>{var s,r;const e=a.useDependency(at),t=a.useObservable(e.currentSelector$),n=C.useRef(null);return C.useEffect(()=>{var o,c;if(t)return(c=n.current)==null||c.showDialog((o=t.initialValue)!=null?o:[]),()=>{var i;(i=n.current)==null||i.hideDialog()}},[t]),b.jsx(ut,{unitId:(s=t==null?void 0:t.unitId)!=null?s:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(o,c)=>{var i;t==null||t.callback((i=c==null?void 0:c.split(",").map(d=>T.deserializeRangeWithSheet(d)))!=null?i:[])}})};var Jr=Object.defineProperty,es=Object.getOwnPropertyDescriptor,ts=(e,t,n)=>t in e?Jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ns=(e,t,n,s)=>{for(var r=s>1?void 0:s?es(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Ke=(e,t)=>(n,s)=>t(n,s,e),Yt=(e,t,n)=>ts(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=Ct,n,s,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=r,this._uiPartsService=o;const{menu:c,...i}=l.merge(Ct,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(hn,i,{merge:!0})}onStarting(){l.registerDependencies(this._injector,[[Qe,{useClass:st}],[at],[Ze],[qe],[Ye],[ze],[Ge],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[ot]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Ze],[Ye],[Ge]])}onSteady(){this._injector.get(qe),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(a.ComponentManager);this.disposeWithMe(t.register(w.RANGE_SELECTOR_COMPONENT_KEY,ut)),this.disposeWithMe(t.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,qt)),this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(Qr,this._injector)))}};Yt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Mt);Yt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=ns([l.DependentOn(T.UniverFormulaEnginePlugin,Ce.UniverSheetsFormulaPlugin),Ke(1,l.Inject(l.Injector)),Ke(2,H.IRenderManagerService),Ke(3,l.IConfigService),Ke(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Tt;exports.FormulaEditor=qt;exports.GlobalRangeSelectorService=at;exports.HelpFunctionOperation=xt;exports.InsertFunctionOperation=ce;exports.MoreFunctionsOperation=Je;exports.RangeSelector=ut;exports.ReferenceAbsoluteOperation=ct;exports.SearchFunctionOperation=Nt;exports.SelectEditorFormulaOperation=Ee;exports.SheetOnlyPasteFormulaCommand=Xe;
|
|
8
|
+
`,{"univer-ring-primary-500":P,"univer-ring-red-500":re}),children:b.jsx("div",{ref:V,className:"univer-relative univer-h-full univer-w-full",onMouseUp:ht})}),n!==void 0?b.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,M&&Me!==""?b.jsx(yr,{editor:M,isFocus:P,formulaText:ee,onClose:()=>te()}):null,M?b.jsx(Br,{isFocus:P,sequenceNodes:Ue,onSelect:dt,ref:N,editor:M}):null]})});function qr(e,t,n,s){const r=a.useDependency(T.LexerTreeBuilder),o=Kt(""),c=a.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[i,d]=C.useState([]),h=a.useDependency(w.IMarkSelectionService),m=C.useRef(""),p=a.useDependency(l.IUniverInstanceService);return C.useEffect(()=>{if(!e)return;const f=e.getDocumentDataModel().getPlainText();if(m.current===f)return;m.current=f;const g=r.sequenceNodesBuilder(f);d(g!=null?g:[])},[c,e,r]),C.useEffect(()=>{var u,_;if(!e)return;if(!t){const v=e.getDocumentData();e.setDocumentData({...v,body:{...v.body,dataStream:(_=(u=v.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const f=o(e,i,!1),g=new l.DisposableCollection;return f.forEach(v=>{const S=T.deserializeRangeWithSheet(v.token),I=p.getCurrentUnitForType(l.UniverInstanceType.UNIVER_SHEET),E=I==null?void 0:I.getActiveSheet();if(!S.sheetName&&s!==(E==null?void 0:E.getSheetId())||S.sheetName&&(E==null?void 0:E.getName())!==S.sheetName)return;const y=new l.ColorKit(v.themeColor).toRgb(),R=h.addShape({range:S.range,style:{stroke:v.themeColor,fill:`rgba(${y.r}, ${y.g}, ${y.b}, 0.1)`,strokeDash:12},primary:null});R&&g.add(()=>h.removeShape(R))}),()=>{g.dispose()}},[e,t,o,h,i]),{sequenceNodes:i}}function Yr(e){const t=a.useDependency(A.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:s,subUnitId:r,onChange:o}=e,i=a.useDependency(l.IUniverInstanceService).getUnit(s,l.UniverInstanceType.UNIVER_SHEET),d=a.useEvent(o),h=a.useEvent((m,p)=>{const f=i==null?void 0:i.getActiveSheet();if(!f||!n&&f.getSheetId()!==r||!(m!=null&&m.length))return;const g=m.map(u=>({range:u.range,unitId:s,sheetName:f.getSheetId()===r?"":f.getName()}));d(g,p)});C.useEffect(()=>{const m=new l.DisposableCollection;return m.add(t.selectionMoveStart$.subscribe(p=>{h(p,!0)})),m.add(t.selectionMoving$.subscribe(p=>{h(p,!1)})),m.add(t.selectionMoveEnd$.subscribe(p=>{h(p,!1)})),()=>{m.dispose()}},[h,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Et=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),zr=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function Gr(e){const{visible:t,initialValue:n,unitId:s,subUnitId:r,maxRangeCount:o=1/0,supportAcrossSheet:c,onConfirm:i,onClose:d,onShowBySelection:h}=e,m=a.useDependency(l.LocaleService),p=a.useDependency(T.LexerTreeBuilder),[f,g]=C.useState([]),[u,_]=C.useState(0),v=C.useRef(null);C.useEffect(()=>{if(t&&n.length){const y=n.map(R=>R.sheetName?T.serializeRangeWithSheet(R.sheetName,R.range):T.serializeRange(R.range));g(y),_(y.length-1)}else g([""]),_(0)},[t]);const S=(y,R)=>{const O=[...f];O[y]=R,g(O)},I=()=>{g([...f,""]),_(f.length)},E=y=>{f.splice(y,1),g([...f])};return Yr({unitId:s,subUnitId:r,supportAcrossSheet:c,onChange:(y,R)=>{if(!t&&h!=null&&h(y))return;const O=new Set(f),F=y.map(k=>k.sheetName?T.serializeRangeWithSheet(k.sheetName,k.range):T.serializeRange(k.range)),L=F.filter(k=>!O.has(k));if(!L.length)return;const U=[...f];if(F.length>1){R||U.splice(u,1),U.push(...L);const k=U.slice(0,o);g(k),_(k.length-1),requestAnimationFrame(()=>{var $;($=v.current)==null||$.scrollTo({top:v.current.scrollHeight})})}else{U.splice(u,1,...L);const k=U.slice(0,o);g(k),_(u+L.length-1)}}}),b.jsx(W.Dialog,{width:"328px",open:t,title:m.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:b.jsxs("footer",{className:"univer-flex univer-gap-2",children:[b.jsx(W.Button,{onClick:d,children:m.t("rangeSelector.cancel")}),b.jsx(W.Button,{variant:"primary",onClick:()=>{i(f.filter(y=>{const R=p.sequenceNodesBuilder(y);return R&&R.length===1&&typeof R[0]!="string"&&R[0].nodeType===T.sequenceNodeType.REFERENCE}).map(y=>T.deserializeRangeWithSheet(y)).map(y=>({...y,range:zr(y.range)})))},children:m.t("rangeSelector.confirm")})]}),onClose:d,children:b.jsxs("div",{ref:v,className:W.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",W.scrollbarClassName),children:[f.map((y,R)=>b.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[b.jsx(W.Input,{className:W.clsx("univer-w-full",{"univer-border-primary-600":u===R}),placeholder:m.t("rangeSelector.placeHolder"),onFocus:()=>_(R),value:y,onChange:O=>S(R,O)}),f.length>1&&b.jsx(Ut,{className:"univer-cursor-pointer",onClick:()=>E(R)})]},R)),f.length<o&&b.jsx("div",{children:b.jsxs(W.Button,{variant:"link",onClick:I,children:[b.jsx($t,{}),b.jsx("span",{children:m.t("rangeSelector.addAnotherRange")})]})})]})})}function Zr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Xr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function ut(e){const[t,n]=C.useState(null),{onVerify:s,selectorRef:r,unitId:o,subUnitId:c,maxRangeCount:i,supportAcrossSheet:d,autoFocus:h,onChange:m,onRangeSelectorDialogVisibleChange:p,onClickOutside:f,onFocusChange:g,forceShowDialogWhenSelectionChanged:u,hideEditor:_,resetRange:v}=e,[S,I]=C.useState(h!=null?h:!1),[E,y]=C.useState(!1),[R,O]=C.useState([]),F=a.useDependency(l.LocaleService),L=a.useDependency(Q.IEditorService),{sequenceNodes:U}=qr(t,S,o,c),k=Te(U),$=a.useDependency(l.ICommandService),D=a.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),L.blur()}),N=a.useEvent(()=>{var x;D(),O(Zr((x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")),y(!0)});return C.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){L.focus(t.getEditorId())},blur:D,verify:()=>Et(k.current),showDialog:x=>{D(),O(x),y(!0)},hideDialog:()=>{O([]),y(!1)},getValue:()=>{var x;return(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:""}})},[D,t,L,r,k]),C.useEffect(()=>{var x;s==null||s(Et(U),(x=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?x:"")},[U]),C.useEffect(()=>{p==null||p(E)},[E]),C.useEffect(()=>{if(E&&v)return()=>{const x={unitId:o,subUnitId:c,selections:v};$.executeCommand(A.SetSelectionsOperation.id,x)}},[E]),b.jsxs(b.Fragment,{children:[_?null:b.jsx(Q.RichTextEditor,{isSingle:!0,...e,onFocusChange:(x,M)=>{I(x),g==null||g(x,M)},editorRef:n,onClickOutside:()=>{I(!1),D(),f==null||f()},icon:b.jsx(W.Tooltip,{title:F.t("rangeSelector.buttonTooltip"),placement:"bottom",children:b.jsx(Wt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:N})})}),b.jsx(Gr,{initialValue:R,unitId:o,subUnitId:c,visible:E,maxRangeCount:i,onConfirm:x=>{const M=Xr(x),P=l.RichTextBuilder.newEmptyData();P.body.dataStream=M,t==null||t.replaceText(M,!1),m==null||m(P,M),y(!1),O([]),requestAnimationFrame(()=>{D()})},onClose:()=>{y(!1),O([])},supportAcrossSheet:d,onShowBySelection:x=>S||u?(O(x),y(!0),!1):!0})]})}const Qr=()=>{var s,r;const e=a.useDependency(at),t=a.useObservable(e.currentSelector$),n=C.useRef(null);return C.useEffect(()=>{var o,c;if(t)return(c=n.current)==null||c.showDialog((o=t.initialValue)!=null?o:[]),()=>{var i;(i=n.current)==null||i.hideDialog()}},[t]),b.jsx(ut,{unitId:(s=t==null?void 0:t.unitId)!=null?s:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(o,c)=>{var i;t==null||t.callback((i=c==null?void 0:c.split(",").map(d=>T.deserializeRangeWithSheet(d)))!=null?i:[])}})};var Jr=Object.defineProperty,es=Object.getOwnPropertyDescriptor,ts=(e,t,n)=>t in e?Jr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,ns=(e,t,n,s)=>{for(var r=s>1?void 0:s?es(t,n):t,o=e.length-1,c;o>=0;o--)(c=e[o])&&(r=c(r)||r);return r},Ke=(e,t)=>(n,s)=>t(n,s,e),Yt=(e,t,n)=>ts(e,typeof t!="symbol"?t+"":t,n);exports.UniverSheetsFormulaUIPlugin=class extends l.Plugin{constructor(t=Ct,n,s,r,o){super(),this._config=t,this._injector=n,this._renderManagerService=s,this._configService=r,this._uiPartsService=o;const{menu:c,...i}=l.merge(Ct,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(hn,i,{merge:!0})}onStarting(){l.registerDependencies(this._injector,[[Qe,{useClass:st}],[at],[Ze],[qe],[Ye],[ze],[Ge],[exports.FormulaReorderController]]),this._initUIPart()}onReady(){[[exports.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[ot]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(l.UniverInstanceType.UNIVER_SHEET,t))}),l.touchDependencies(this._injector,[[Ze],[Ye],[Ge]])}onSteady(){this._injector.get(qe),this._injector.get(exports.FormulaReorderController)}_initUIPart(){const t=this._injector.get(a.ComponentManager);this.disposeWithMe(t.register(w.RANGE_SELECTOR_COMPONENT_KEY,ut)),this.disposeWithMe(t.register(w.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,qt)),this.disposeWithMe(this._uiPartsService.registerComponent(a.BuiltInUIPart.GLOBAL,()=>a.connectInjector(Qr,this._injector)))}};Yt(exports.UniverSheetsFormulaUIPlugin,"pluginName",Mt);Yt(exports.UniverSheetsFormulaUIPlugin,"type",l.UniverInstanceType.UNIVER_SHEET);exports.UniverSheetsFormulaUIPlugin=ns([l.DependentOn(T.UniverFormulaEnginePlugin,Ce.UniverSheetsFormulaPlugin),Ke(1,l.Inject(l.Injector)),Ke(2,H.IRenderManagerService),Ke(3,l.IConfigService),Ke(4,a.IUIPartsService)],exports.UniverSheetsFormulaUIPlugin);exports.FORMULA_PROMPT_ACTIVATED=Tt;exports.FormulaEditor=qt;exports.GlobalRangeSelectorService=at;exports.HelpFunctionOperation=xt;exports.InsertFunctionOperation=ce;exports.MoreFunctionsOperation=Je;exports.RangeSelector=ut;exports.ReferenceAbsoluteOperation=ct;exports.SearchFunctionOperation=Nt;exports.SelectEditorFormulaOperation=Ee;exports.SheetOnlyPasteFormulaCommand=Xe;
|
package/lib/es/index.js
CHANGED
|
@@ -3183,6 +3183,7 @@ const pc = (e) => e.startsWith(sr.EQUALS) ? e.slice(1) : "", Zn = () => {
|
|
|
3183
3183
|
/* @__PURE__ */ x(
|
|
3184
3184
|
"div",
|
|
3185
3185
|
{
|
|
3186
|
+
ref: T,
|
|
3186
3187
|
className: ne(
|
|
3187
3188
|
`
|
|
3188
3189
|
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
@@ -3193,7 +3194,6 @@ const pc = (e) => e.startsWith(sr.EQUALS) ? e.slice(1) : "", Zn = () => {
|
|
|
3193
3194
|
"univer-ring-red-500": ce
|
|
3194
3195
|
}
|
|
3195
3196
|
),
|
|
3196
|
-
ref: T,
|
|
3197
3197
|
children: /* @__PURE__ */ x(
|
|
3198
3198
|
"div",
|
|
3199
3199
|
{
|
package/lib/index.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.univer-absolute{position:absolute}.univer-relative{position:relative}.univer-left-1\.5{left:.375rem}.univer-top-1\/2{top:50%}.univer-z-\[15\]{z-index:15}.univer-m-0{margin:0}.-univer-mx-6{margin-left:-1.5rem;margin-right:-1.5rem}.univer-mx-0{margin-left:0;margin-right:0}.univer-my-1{margin-top:.25rem;margin-bottom:.25rem}.univer-my-2{margin-top:.5rem;margin-bottom:.5rem}.univer-mb-2{margin-bottom:.5rem}.univer-mb-5{margin-bottom:1.25rem}.univer-ml-2{margin-left:.5rem}.univer-ml-4{margin-left:1rem}.univer-mr-0{margin-right:0}.univer-mt-0{margin-top:0}.univer-mt-1{margin-top:.25rem}.univer-mt-2{margin-top:.5rem}.univer-mt-3{margin-top:.75rem}.univer-box-border{box-sizing:border-box}.univer-block{display:block}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-h-6{height:1.5rem}.univer-h-\[18px\]{height:18px}.univer-h-\[364px\]{height:364px}.univer-h-full{height:100%}.univer-max-h-60{max-height:15rem}.univer-max-h-72{max-height:18rem}.univer-max-h-\[350px\]{max-height:350px}.univer-max-h-\[400px\]{max-height:400px}.univer-w-6{width:1.5rem}.univer-w-\[250px\]{width:250px}.univer-w-full{width:100%}.univer-flex-1{flex:1 1 0%}.-univer-translate-y-1\/2{--tw-translate-y: -50%;transform:translate(var(--tw-translate-x),-50%) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y));transform:translate(var(--tw-translate-x),var(--tw-translate-y)) rotate(var(--tw-rotate)) skew(var(--tw-skew-x)) skewY(var(--tw-skew-y)) scaleX(var(--tw-scale-x)) scaleY(var(--tw-scale-y))}.univer-cursor-pointer{cursor:pointer}.univer-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.univer-list-none{list-style-type:none}.univer-flex-col{flex-direction:column}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-justify-around{justify-content:space-around}.univer-gap-2{gap:.5rem}.univer-gap-4{gap:1rem}.univer-overflow-visible{overflow:visible}.univer-overflow-y-auto{overflow-y:auto}.univer-whitespace-nowrap{white-space:nowrap}.univer-whitespace-pre-wrap{white-space:pre-wrap}.univer-break-words{word-wrap:break-word}.univer-break-all{word-break:break-all}.univer-rounded{border-radius:.25rem}.univer-rounded-lg{border-radius:.5rem}.univer-rounded-none{border-radius:0}.univer-rounded-l{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}.univer-border{border-width:1px}.univer-border-r-0{border-right-width:0px}.univer-border-gray-600{border-color:var(--univer-gray-600)}.univer-border-primary-600{border-color:var(--univer-primary-600)}.\!univer-bg-gray-600{background-color:var(--univer-gray-600)!important}.univer-bg-gray-200{background-color:var(--univer-gray-200)}.univer-bg-primary-600{background-color:var(--univer-primary-600)}.univer-bg-transparent{background-color:transparent}.univer-bg-white{background-color:var(--univer-white)}.univer-p-0{padding:0}.univer-p-0\.5{padding:.125rem}.univer-p-2{padding:.5rem}.univer-p-3{padding:.75rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-px-4{padding-left:1rem;padding-right:1rem}.univer-px-6{padding-left:1.5rem;padding-right:1.5rem}.univer-px-7{padding-left:1.75rem;padding-right:1.75rem}.univer-py-1{padding-top:.25rem;padding-bottom:.25rem}.univer-py-2{padding-top:.5rem;padding-bottom:.5rem}.univer-py-3{padding-top:.75rem;padding-bottom:.75rem}.univer-pb-3{padding-bottom:.75rem}.univer-pt-0{padding-top:0}.univer-text-base{font-size:1rem;line-height:1.5rem}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-font-bold{font-weight:700}.univer-font-medium{font-weight:500}.univer-leading-5{line-height:1.25rem}.univer-leading-\[13px\]{line-height:13px}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-600{color:var(--univer-gray-600)}.univer-text-gray-900{color:var(--univer-gray-900)}.univer-text-primary-500{color:var(--univer-primary-500)}.univer-text-primary-600{color:var(--univer-primary-600)}.univer-text-red-500{color:var(--univer-red-500)}.univer-text-white{color:var(--univer-white)}.univer-shadow-md{--tw-shadow: 0px 1px 6px -2px rgba(30, 40, 77, .08), 0px 2px 6px -1px rgba(30, 40, 77, .1);--tw-shadow-colored: 0px 1px 6px -2px var(--tw-shadow-color), 0px 2px 6px -1px var(--tw-shadow-color);box-shadow:0 0 #0000,0 0 #0000,0 1px 6px -2px #1e284d14,0 2px 6px -1px #1e284d1a;box-shadow:var(--tw-ring-offset-shadow, 0 0 rgba(0,0,0,0)),var(--tw-ring-shadow, 0 0 rgba(0,0,0,0)),var(--tw-shadow)}.univer-outline-none{outline:2px solid transparent;outline-offset:2px}.univer-ring-1{--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(1px + var(--tw-ring-offset-width)) var(--tw-ring-color);box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),0 0 #0000;box-shadow:var(--tw-ring-offset-shadow),var(--tw-ring-shadow),var(--tw-shadow, 0 0 rgba(0,0,0,0))}.univer-ring-primary-500{--tw-ring-color: var(--univer-primary-500) }.univer-ring-red-500{--tw-ring-color: var(--univer-red-500) }.univer-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-bg-gray-200:hover{background-color:var(--univer-gray-200)}.hover\:univer-bg-gray-300:hover{background-color:var(--univer-gray-300)}.dark\:\!univer-bg-gray-600:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-600)!important}.dark\:\!univer-bg-gray-900:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-900)!important}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:\!univer-text-gray-300:where(.univer-dark,.univer-dark *){color:var(--univer-gray-300)!important}.dark\:\!univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)!important}.dark\:hover\:\!univer-bg-gray-600:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-600)!important}
|
|
1
|
+
.univer-absolute{position:absolute}.univer-relative{position:relative}.univer-left-1\.5{left:.375rem}.univer-top-1\/2{top:50%}.univer-z-\[15\]{z-index:15}.univer-m-0{margin:0}.-univer-mx-6{margin-left:-1.5rem;margin-right:-1.5rem}.univer-mx-0{margin-left:0;margin-right:0}.univer-my-1{margin-top:.25rem;margin-bottom:.25rem}.univer-my-2{margin-top:.5rem;margin-bottom:.5rem}.univer-mb-2{margin-bottom:.5rem}.univer-mb-5{margin-bottom:1.25rem}.univer-ml-2{margin-left:.5rem}.univer-ml-4{margin-left:1rem}.univer-mr-0{margin-right:0}.univer-mt-0{margin-top:0}.univer-mt-1{margin-top:.25rem}.univer-mt-2{margin-top:.5rem}.univer-mt-3{margin-top:.75rem}.univer-box-border{box-sizing:border-box}.univer-block{display:block}.univer-flex{display:flex}.univer-inline-flex{display:inline-flex}.univer-h-6{height:1.5rem}.univer-h-\[18px\]{height:18px}.univer-h-\[364px\]{height:364px}.univer-h-full{height:100%}.univer-max-h-60{max-height:15rem}.univer-max-h-72{max-height:18rem}.univer-max-h-\[350px\]{max-height:350px}.univer-max-h-\[400px\]{max-height:400px}.univer-w-6{width:1.5rem}.univer-w-\[250px\]{width:250px}.univer-w-full{width:100%}.univer-flex-1{flex:1 1 0%}.-univer-translate-y-1\/2{--univer-tw-translate-y: -50%;transform:translate(var(--univer-tw-translate-x),-50%) rotate(var(--univer-tw-rotate)) skew(var(--univer-tw-skew-x)) skewY(var(--univer-tw-skew-y)) scaleX(var(--univer-tw-scale-x)) scaleY(var(--univer-tw-scale-y));transform:translate(var(--univer-tw-translate-x),var(--univer-tw-translate-y)) rotate(var(--univer-tw-rotate)) skew(var(--univer-tw-skew-x)) skewY(var(--univer-tw-skew-y)) scaleX(var(--univer-tw-scale-x)) scaleY(var(--univer-tw-scale-y))}.univer-cursor-pointer{cursor:pointer}.univer-select-none{-webkit-user-select:none;-moz-user-select:none;user-select:none}.univer-list-none{list-style-type:none}.univer-flex-col{flex-direction:column}.univer-items-center{align-items:center}.univer-justify-end{justify-content:flex-end}.univer-justify-center{justify-content:center}.univer-justify-between{justify-content:space-between}.univer-justify-around{justify-content:space-around}.univer-gap-2{gap:.5rem}.univer-gap-4{gap:1rem}.univer-overflow-visible{overflow:visible}.univer-overflow-y-auto{overflow-y:auto}.univer-whitespace-nowrap{white-space:nowrap}.univer-whitespace-pre-wrap{white-space:pre-wrap}.univer-break-words{word-wrap:break-word}.univer-break-all{word-break:break-all}.univer-rounded{border-radius:.25rem}.univer-rounded-lg{border-radius:.5rem}.univer-rounded-none{border-radius:0}.univer-rounded-l{border-top-left-radius:.25rem;border-bottom-left-radius:.25rem}.univer-border{border-width:1px}.univer-border-r-0{border-right-width:0px}.univer-border-gray-600{border-color:var(--univer-gray-600)}.univer-border-primary-600{border-color:var(--univer-primary-600)}.\!univer-bg-gray-600{background-color:var(--univer-gray-600)!important}.univer-bg-gray-200{background-color:var(--univer-gray-200)}.univer-bg-primary-600{background-color:var(--univer-primary-600)}.univer-bg-transparent{background-color:transparent}.univer-bg-white{background-color:var(--univer-white)}.univer-p-0{padding:0}.univer-p-0\.5{padding:.125rem}.univer-p-2{padding:.5rem}.univer-p-3{padding:.75rem}.univer-px-2{padding-left:.5rem;padding-right:.5rem}.univer-px-4{padding-left:1rem;padding-right:1rem}.univer-px-6{padding-left:1.5rem;padding-right:1.5rem}.univer-px-7{padding-left:1.75rem;padding-right:1.75rem}.univer-py-1{padding-top:.25rem;padding-bottom:.25rem}.univer-py-2{padding-top:.5rem;padding-bottom:.5rem}.univer-py-3{padding-top:.75rem;padding-bottom:.75rem}.univer-pb-3{padding-bottom:.75rem}.univer-pt-0{padding-top:0}.univer-text-base{font-size:1rem;line-height:1.5rem}.univer-text-sm{font-size:.875rem;line-height:1.25rem}.univer-text-xs{font-size:.75rem;line-height:1rem}.univer-font-bold{font-weight:700}.univer-font-medium{font-weight:500}.univer-leading-5{line-height:1.25rem}.univer-leading-\[13px\]{line-height:13px}.univer-text-gray-400{color:var(--univer-gray-400)}.univer-text-gray-500{color:var(--univer-gray-500)}.univer-text-gray-600{color:var(--univer-gray-600)}.univer-text-gray-900{color:var(--univer-gray-900)}.univer-text-primary-500{color:var(--univer-primary-500)}.univer-text-primary-600{color:var(--univer-primary-600)}.univer-text-red-500{color:var(--univer-red-500)}.univer-text-white{color:var(--univer-white)}.univer-shadow-md{--univer-tw-shadow: 0px 1px 6px -2px rgba(30, 40, 77, .08), 0px 2px 6px -1px rgba(30, 40, 77, .1);--univer-tw-shadow-colored: 0px 1px 6px -2px var(--univer-tw-shadow-color), 0px 2px 6px -1px var(--univer-tw-shadow-color);box-shadow:0 0 #0000,0 0 #0000,0 1px 6px -2px #1e284d14,0 2px 6px -1px #1e284d1a;box-shadow:var(--univer-tw-ring-offset-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-ring-shadow, 0 0 rgba(0,0,0,0)),var(--univer-tw-shadow)}.univer-outline-none{outline:2px solid transparent;outline-offset:2px}.univer-ring-1{--univer-tw-ring-offset-shadow: var(--univer-tw-ring-inset) 0 0 0 var(--univer-tw-ring-offset-width) var(--univer-tw-ring-offset-color);--univer-tw-ring-shadow: var(--univer-tw-ring-inset) 0 0 0 calc(1px + var(--univer-tw-ring-offset-width)) var(--univer-tw-ring-color);box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),0 0 #0000;box-shadow:var(--univer-tw-ring-offset-shadow),var(--univer-tw-ring-shadow),var(--univer-tw-shadow, 0 0 rgba(0,0,0,0))}.univer-ring-primary-500{--univer-tw-ring-color: var(--univer-primary-500) }.univer-ring-red-500{--univer-tw-ring-color: var(--univer-red-500) }.univer-transition-colors{transition-property:color,background-color,border-color,text-decoration-color,fill,stroke;transition-timing-function:cubic-bezier(.4,0,.2,1);transition-duration:.15s}.hover\:univer-bg-gray-200:hover{background-color:var(--univer-gray-200)}.hover\:univer-bg-gray-300:hover{background-color:var(--univer-gray-300)}.dark\:\!univer-bg-gray-600:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-600)!important}.dark\:\!univer-bg-gray-900:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-900)!important}.dark\:\!univer-text-gray-200:where(.univer-dark,.univer-dark *){color:var(--univer-gray-200)!important}.dark\:\!univer-text-gray-300:where(.univer-dark,.univer-dark *){color:var(--univer-gray-300)!important}.dark\:\!univer-text-white:where(.univer-dark,.univer-dark *){color:var(--univer-white)!important}.dark\:hover\:\!univer-bg-gray-600:hover:where(.univer-dark,.univer-dark *){background-color:var(--univer-gray-600)!important}
|
package/lib/index.js
CHANGED
|
@@ -3183,6 +3183,7 @@ const pc = (e) => e.startsWith(sr.EQUALS) ? e.slice(1) : "", Zn = () => {
|
|
|
3183
3183
|
/* @__PURE__ */ x(
|
|
3184
3184
|
"div",
|
|
3185
3185
|
{
|
|
3186
|
+
ref: T,
|
|
3186
3187
|
className: ne(
|
|
3187
3188
|
`
|
|
3188
3189
|
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
@@ -3193,7 +3194,6 @@ const pc = (e) => e.startsWith(sr.EQUALS) ? e.slice(1) : "", Zn = () => {
|
|
|
3193
3194
|
"univer-ring-red-500": ce
|
|
3194
3195
|
}
|
|
3195
3196
|
),
|
|
3196
|
-
ref: T,
|
|
3197
3197
|
children: /* @__PURE__ */ x(
|
|
3198
3198
|
"div",
|
|
3199
3199
|
{
|
package/lib/umd/index.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
`,d=Math.max(i.length-2,0);e.setSelectionRanges([{startOffset:d,endOffset:d}])}else e.setSelectionRanges(c)}})};function Ir(e){var r,s;const n=e.get(a.IUniverInstanceService).getCurrentUniverDocInstance();return n!=null&&n.getBody()?{dataStream:(s=(r=n.getBody())==null?void 0:r.dataStream)!=null?s:"",offset:0}:void 0}var Se=(e=>(e[e.NOT_SELECT=0]="NOT_SELECT",e[e.NEED_ADD=1]="NEED_ADD",e[e.CAN_EDIT=2]="CAN_EDIT",e[e.EDIT_OTHER_SHEET_REFERENCE=3]="EDIT_OTHER_SHEET_REFERENCE",e))(Se||{});function yr(e){var P;const{editorId:t,isFocus:n,disableOnClick:o,unitId:r,subUnitId:s}=e,c=l.useDependency(K.IRenderManagerService),i=l.useDependency(a.IUniverInstanceService),d=c.getRenderById(r),f=c.getRenderById(t),v=f==null?void 0:f.with(Q.DocSelectionRenderService),S=l.useDependency(ft.DocSelectionManagerService),h=l.useDependency(a.Injector),[g,u]=m.useState(0),_=l.useDependency(T.LexerTreeBuilder),C=m.useRef(!0),p=d==null?void 0:d.with(F.RefSelectionsRenderService),y=be(g),b=i.getUnit(r,a.UniverInstanceType.UNIVER_SHEET),E=b==null?void 0:b.getSheetBySheetId(s),I=l.useEvent($=>{p&&p.setSkipLastEnabled($===1||$===3),y.current=$,u($)}),N=l.useEvent(()=>{var j,oe;if(!b)return;const $=b.getActiveSheet(),W=v==null?void 0:v.getActiveTextRange(),k=W!=null&&W.collapsed?W.startOffset:-1,V=Ir(h);if(!V)return;const w=(j=V==null?void 0:V.dataStream)==null?void 0:j.slice(0,-2),x=((oe=_.sequenceNodesBuilder(w))!=null?oe:[]).map(G=>typeof G=="object"?G.nodeType===T.sequenceNodeType.REFERENCE?{...G,range:T.deserializeRangeWithSheetWithCache(G.token)}:{...G,range:void 0}:G),M=w[k-1],O=w[k],L=x.find(G=>typeof G=="object"&&G.nodeType===T.sequenceNodeType.REFERENCE&&k===G.endIndex+2),U=M&&T.matchRefDrawToken(M)&&(!O||T.isFormulaLexerToken(O)&&O!==T.matchToken.OPEN_BRACKET),H=!!L;if((w==null?void 0:w.substring(0,1))==="="&&(U||H))if(H){if(C.current)return;!L.range.sheetName&&$.getSheetId()===(E==null?void 0:E.getSheetId())||L.range.sheetName===$.getName()?I(2):I(3)}else C.current=!1,I(1);else I(0)});return m.useEffect(()=>{const $=S.textSelection$.pipe(Y.filter(W=>W.unitId===t)).subscribe(()=>{N()});return()=>$.unsubscribe()},[N,S.textSelection$,t]),m.useEffect(()=>{n||(I(0),C.current=!0)},[n,I]),m.useEffect(()=>{var W;if(!o)return;const $=(W=f==null?void 0:f.mainComponent)==null?void 0:W.onPointerDown$.subscribeEvent(()=>{I(0),C.current=!0});return()=>$==null?void 0:$.unsubscribe()},[o,(P=f==null?void 0:f.mainComponent)==null?void 0:P.onPointerDown$,I]),m.useEffect(()=>{if(!n)return;const $=b==null?void 0:b.activeSheet$.subscribe(()=>{N()});return()=>$==null?void 0:$.unsubscribe()},[N,n,b==null?void 0:b.activeSheet$]),{isSelecting:g,isSelectingRef:y}}const Er=()=>{const e=l.useDependency(T.LexerTreeBuilder);return m.useCallback(n=>e.sequenceNodesBuilder(n)||[],[e])};function Rr(e,t,n){const o=new a.ColorKit(t).setAlpha(.05).toRgbString();return{id:n,strokeWidth:1,stroke:t,fill:o,widgets:{tl:!0,tc:!0,tr:!0,ml:!0,mr:!0,bl:!0,bc:!0,br:!0},widgetSize:6,widgetStrokeWidth:1,widgetStroke:e.getColorFromTheme("white")}}function $t(e){var b,E,I;const{unitId:t,subUnitId:n,currentWorkbook:o,refSelections:r,editor:s,refSelectionsService:c,refSelectionsRenderService:i,sheetSkeletonManagerService:d,themeService:f,univerInstanceService:v}=e,S=o.getUnitId(),h=v.getUnit(t,a.UniverInstanceType.UNIVER_SHEET),g=h==null?void 0:h.getActiveSheet(),u=[];if(!h||!g){c.setSelections(u);return}const _=g.getSheetId(),C=N=>{var P;return(P=h==null?void 0:h.getSheetBySheetName(N))==null?void 0:P.getSheetId()};if(!((b=d==null?void 0:d.getWorksheetSkeleton(_))==null?void 0:b.skeleton))return;const y=[];for(let N=0,P=r.length;N<P;N++){const $=r[N],{themeColor:W,token:k,refIndex:V,endIndex:w}=$,x=T.deserializeRangeWithSheet(k),{unitId:M,sheetName:O,range:L}=x,U=C(O);if(!U&&O||S!==t&&M!==S||M&&M!==S||U&&U!==_||!U&&_!==n)continue;const H=A.setEndForRange(L,g.getRowCount(),g.getColumnCount());H.unitId=t,H.sheetId=_,u.push({range:H,primary:null,style:Rr(f,W,V.toString())}),y.push(w)}if(s){const N=(I=(E=s.getSelectionRanges())==null?void 0:E[0])==null?void 0:I.startOffset,P=y.findIndex($=>$+2===N);P!==-1?i==null||i.setActiveSelectionIndex(P):i==null||i.resetActiveSelectionIndex()}return u}function br(e,t){const n=l.useDependency(a.IUniverInstanceService),o=l.useDependency(a.ThemeService),r=l.useDependency(A.IRefSelectionsService),s=l.useDependency(K.IRenderManagerService),c=l.useObservable(m.useMemo(()=>n.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[n])),i=c?s.getRenderById(c.getUnitId()):null,d=i==null?void 0:i.with(F.RefSelectionsRenderService),f=i==null?void 0:i.with(D.SheetSkeletonManagerService),v=l.useEvent((S,h)=>{const g=n.getCurrentUnitOfType(a.UniverInstanceType.UNIVER_SHEET);if(!g||d!=null&&d.selectionMoving)return;const u=$t({unitId:e,subUnitId:t,currentWorkbook:g,refSelections:S,editor:h,refSelectionsService:r,refSelectionsRenderService:d,sheetSkeletonManagerService:f,themeService:o,univerInstanceService:n});u&&r.setSelections(u)});return m.useEffect(()=>()=>{d==null||d.resetActiveSelectionIndex()},[d]),v}function Ft(e=""){const t=l.useDependency(ve.IDescriptionService),n=Tr(),o=l.useDependency(a.ICommandService),r=m.useMemo(()=>e.length,[e]);return l.useEvent((c,i,d=!0,f)=>{const v=c.getDocumentData(),S=c.getEditorId();if(!v)return[];const h=v.body;if(!h)return[];const g=h.dataStream.slice(0,h.dataStream.length-2),u={dataStream:"",...v.body};if(!g.startsWith(e))return[];if(i==null||i.length===0)return u.textRuns=[],o.syncExecuteCommand(Q.ReplaceTextRunsCommand.id,{unitId:S,body:a.getBodySlice(u,0,u.dataStream.length-2)}),[];{const{textRuns:_,refSelections:C}=Mr(t,n,i);r&&_.forEach(b=>{b.ed=b.ed+r,b.st=b.st+r}),u.textRuns=[{st:0,ed:1,ts:{fs:11}},..._];const p=i.reduce((b,E)=>typeof E=="string"?`${b}${E}`:`${b}${E.token}`,"");u.dataStream=`${e}${p}\r
|
|
3
3
|
`;let y;if(d){y=c.getSelectionRanges();const b=u.dataStream.length-2+r;y.forEach(E=>{E.startOffset=Math.max(0,Math.min(E.startOffset,b)),E.endOffset=Math.max(0,Math.min(E.endOffset,b))})}return o.syncExecuteCommand(Q.ReplaceTextRunsCommand.id,{unitId:S,body:a.getBodySlice(u,0,u.dataStream.length-2),textRanges:f!=null?f:y}),C}})}function Tr(){const e=l.useDependency(a.ThemeService),t=e.getCurrentTheme();return m.useMemo(()=>{const o=[e.getColorFromTheme("loop-color.1"),e.getColorFromTheme("loop-color.2"),e.getColorFromTheme("loop-color.3"),e.getColorFromTheme("loop-color.4"),e.getColorFromTheme("loop-color.5"),e.getColorFromTheme("loop-color.6"),e.getColorFromTheme("loop-color.7"),e.getColorFromTheme("loop-color.8"),e.getColorFromTheme("loop-color.9"),e.getColorFromTheme("loop-color.10"),e.getColorFromTheme("loop-color.11"),e.getColorFromTheme("loop-color.12")].map(i=>e.isValidThemeColor(i)?e.getColorFromTheme(i):i),r=e.getColorFromTheme("blue.700"),s=e.getColorFromTheme("jiqing.800"),c=e.getColorFromTheme("black");return{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:c}},[t])}function Mr(e,t,n){const{formulaRefColors:o,numberColor:r,stringColor:s,plainTextColor:c}=t,i=[],d=[],f=new Map;let v=0;for(let S=0,h=n.length;S<h;S++){const g=n[S];if(typeof g=="string"){const b=i[i.length-1],E=b?b.ed:0,I=E+g.length;i.push({st:E,ed:I,ts:{cl:{rgb:c},fs:11}});continue}if(e.hasDefinedNameDescription(g.token.trim())){i.push({st:g.startIndex,ed:g.endIndex+1,ts:{cl:{rgb:c},fs:11}});continue}const{startIndex:u,endIndex:_,nodeType:C,token:p}=g;let y="";if(C===T.sequenceNodeType.REFERENCE){if(f.has(p))y=f.get(p);else{const b=v%o.length;y=o[b],f.set(p,y),v++}d.push({refIndex:S,themeColor:y,token:p,startIndex:g.startIndex,endIndex:g.endIndex,index:d.length})}else C===T.sequenceNodeType.NUMBER?y=r:(C===T.sequenceNodeType.STRING||C===T.sequenceNodeType.ARRAY)&&(y=s);y&&y.length>0?i.push({st:u,ed:_+1,ts:{cl:{rgb:y},fs:11}}):i.push({st:u,ed:_+1,ts:{cl:{rgb:c},fs:11}})}return{textRuns:i,refSelections:d}}const Or=(e,t,n,o)=>{const r=l.useDependency(a.ICommandService),s=l.useDependency(l.IShortcutService),c=m.useRef(t);c.current=t;const i=m.useRef(o);i.current=o,m.useEffect(()=>{if(!n||!e)return;const f=`sheet.formula-embedding-editor.${n.getEditorId()}`,v=new a.DisposableCollection,S=(u,_)=>{if(i.current){i.current(u,_);return}let C=a.Direction.LEFT;u===l.KeyCode.ARROW_DOWN?C=a.Direction.DOWN:u===l.KeyCode.ARROW_UP?C=a.Direction.UP:u===l.KeyCode.ARROW_RIGHT&&(C=a.Direction.RIGHT),_===l.MetaKeys.SHIFT?r.executeCommand(Q.MoveSelectionOperation.id,{direction:C}):r.executeCommand(Q.MoveCursorOperation.id,{direction:C})},h=(u,_)=>{let C=a.Direction.DOWN;u===l.KeyCode.ARROW_DOWN?C=a.Direction.DOWN:u===l.KeyCode.ARROW_UP?C=a.Direction.UP:u===l.KeyCode.ARROW_LEFT?C=a.Direction.LEFT:u===l.KeyCode.ARROW_RIGHT&&(C=a.Direction.RIGHT),c.current?_===l.MetaKeys.CTRL_COMMAND?r.executeCommand(D.MoveSelectionCommand.id,{direction:C,jumpOver:D.JumpOver.moveGap,extra:"formula-editor",fromCurrentSelection:c.current===Se.NEED_ADD||c.current===Se.EDIT_OTHER_SHEET_REFERENCE}):_===l.MetaKeys.SHIFT?r.executeCommand(D.ExpandSelectionCommand.id,{direction:C,extra:"formula-editor"}):_===(l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT)?r.executeCommand(D.ExpandSelectionCommand.id,{direction:C,jumpOver:D.JumpOver.moveGap,extra:"formula-editor"}):r.executeCommand(D.MoveSelectionCommand.id,{direction:C,extra:"formula-editor",fromCurrentSelection:c.current===Se.NEED_ADD||c.current===Se.EDIT_OTHER_SHEET_REFERENCE}):S(u,_)};return v.add(r.registerCommand({id:f,type:a.CommandType.OPERATION,handler(u,_){const{keyCode:C,metaKey:p}=_;h(C,p)}})),[{keyCode:l.KeyCode.ARROW_DOWN},{keyCode:l.KeyCode.ARROW_LEFT},{keyCode:l.KeyCode.ARROW_RIGHT},{keyCode:l.KeyCode.ARROW_UP},{keyCode:l.KeyCode.ARROW_DOWN,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_LEFT,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_RIGHT,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_UP,metaKey:l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_DOWN,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_LEFT,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_RIGHT,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_UP,metaKey:l.MetaKeys.CTRL_COMMAND},{keyCode:l.KeyCode.ARROW_DOWN,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_LEFT,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_RIGHT,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT},{keyCode:l.KeyCode.ARROW_UP,metaKey:l.MetaKeys.CTRL_COMMAND|l.MetaKeys.SHIFT}].map(({keyCode:u,metaKey:_})=>({id:f,binding:_?u|_:u,preconditions:()=>!0,priority:900,staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keyCode:u,metaKey:_}})).forEach(u=>{v.add(s.registerShortcut(u))}),()=>{v.dispose()}},[r,n,e,s])},Nr=(e,t,n,o=!0)=>{var h;const r=l.useDependency(K.IRenderManagerService),s=l.useDependency(a.IContextService),c=l.useDependency(l.IContextMenuService),i=l.useDependency(A.IRefSelectionsService),d=l.useDependency(a.IUniverInstanceService),f=l.useObservable(m.useMemo(()=>d.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[d])),v=r.getRenderById((h=f==null?void 0:f.getUnitId())!=null?h:""),S=v==null?void 0:v.with(F.RefSelectionsRenderService);m.useLayoutEffect(()=>{if(e)return s.setContextValue(a.EDITOR_ACTIVATED,!0),()=>{s.setContextValue(a.EDITOR_ACTIVATED,!1),i.clear()}},[s,e,i]),m.useLayoutEffect(()=>{if(e&&t){const g=S==null?void 0:S.enableSelectionChanging();return s.setContextValue(A.REF_SELECTIONS_ENABLED,!0),()=>{s.setContextValue(A.REF_SELECTIONS_ENABLED,!1),g==null||g.dispose()}}},[s,e,S,t]),m.useEffect(()=>{if(e)return s.setContextValue(a.EDITOR_ACTIVATED,!0),o&&c.disable(),()=>{s.setContextValue(a.EDITOR_ACTIVATED,!1),o&&c.enable()}},[c,s,e,o]),m.useEffect(()=>{e&&(S==null||S.setSkipLastEnabled(!1))},[e,S])},Dr=(e,t,n)=>{const o=l.useDependency(a.IUniverInstanceService),r=l.useDependency(A.SheetsSelectionsService);return m.useCallback(()=>{if(e){const c=[...r.getWorkbookSelections(t).getSelectionsOfWorksheet(n)],i=o.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),d=i==null?void 0:i.getActiveSheet();(i==null?void 0:i.getUnitId())!==t&&o.setCurrentUnitForType(t),d&&d.getSheetId()===n&&r.setSelections(c)}},[e,r,n,t,o])},xr=e=>e.reduce((t,n)=>typeof n=="string"?t+n.length:t+n.token.length,0),lt=e=>e.map(t=>typeof t=="string"?t:t.token).join(""),ze=(e,t=!1,n="",o=!1)=>!t&&!o?e.map(r=>T.serializeRange(r.range)):e.map(r=>o?T.serializeRangeToRefString(r):r.sheetName!==""&&r.sheetName!==n?T.serializeRangeWithSheet(r.sheetName,r.range):T.serializeRange(r.range)),wr=e=>{var v,S,h;const{editor:t,lexerTreeBuilder:n}=e,o=t==null?void 0:t.getSelectionRanges();if((o==null?void 0:o.length)!==1)return;const s=o[0].startOffset-1,c=((S=(v=t==null?void 0:t.getDocumentData().body)==null?void 0:v.dataStream)!=null?S:`\r
|
|
4
4
|
`).slice(0,-2),i=(h=n.sequenceNodesBuilder(c.slice(1)))!=null?h:[],d=ct(i,s,!1),f=At(i,d);return{nodeIndex:d,updatingRefIndex:f,sequenceNodes:i,offset:s}},kr=()=>{},Ar=(e,t,n,o,r,s,c,i,d,f=kr)=>{var V;const v=l.useDependency(K.IRenderManagerService),S=l.useDependency(a.IUniverInstanceService),h=l.useDependency(a.ICommandService),g=l.useDependency(ft.DocSelectionManagerService),u=l.useDependency(a.ThemeService),_=l.useDependency(T.LexerTreeBuilder),C=S.getUnit(o),p=l.useEvent((w,x)=>{var M,O,L;return(L=(O=(M=S.getUnit(w))==null?void 0:M.getSheetBySheetId(x))==null?void 0:O.getName())!=null?L:""}),y=m.useMemo(()=>p(o,r),[p,r,o]),b=l.useObservable(C==null?void 0:C.activeSheet$),E=be({activeSheet:b,sheetName:y}),I=l.useObservable(m.useMemo(()=>S.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET),[S])),N=v.getRenderById((V=I==null?void 0:I.getUnitId())!=null?V:""),P=N==null?void 0:N.with(F.RefSelectionsRenderService),$=N==null?void 0:N.with(D.SheetSkeletonManagerService),W=l.useDependency(A.IRefSelectionsService),k=l.useEvent((w,x)=>{var j,oe,G,he,Ne,te,Ze,De,Xe;const M=wr({editor:d,lexerTreeBuilder:_});if(!M)return;const{nodeIndex:O,updatingRefIndex:L,sequenceNodes:U,offset:H}=M;if(n.current===Se.NEED_ADD)if(H!==0){if(O===-1&&U.length)return;const q=w[w.length-1],ee=U.splice(O+1),le=(j=q.sheetId)!=null?j:r,de={range:q,unitId:(oe=q.unitId)!=null?oe:I.getUnitId(),sheetName:p((G=q.unitId)!=null?G:I.getUnitId(),le)},ce=le!==r,J=(I==null?void 0:I.getUnitId())!==o,fe=ze([de],c&&(ce||J),y,J);U.push({token:fe[0],nodeType:T.sequenceNodeType.REFERENCE});const Le=[...U,...ee],pe=lt(Le);f(pe,xr(U),x)}else{const q=w[w.length-1],ee=(he=q.sheetId)!=null?he:r,le={range:q,unitId:(Ne=q.unitId)!=null?Ne:I.getUnitId(),sheetName:p((te=q.unitId)!=null?te:I.getUnitId(),ee)},de=ee!==r,ce=(I==null?void 0:I.getUnitId())!==o,J=ze([le],c&&(de||ce),y,ce);U.unshift({token:J[0],nodeType:T.sequenceNodeType.REFERENCE});const fe=lt(U);f(fe,J[0].length,x)}else if(n.current===Se.EDIT_OTHER_SHEET_REFERENCE){const q=w.pop();if(!q)return;const ee=U[O];if(typeof ee=="object"&&ee.nodeType===T.sequenceNodeType.REFERENCE){const le=ee.token;ee.token=y===(b==null?void 0:b.getName())?T.serializeRange(q):T.serializeRangeWithSheet(b.getName(),q);const de=H+(ee.token.length-le.length);f(T.generateStringWithSequence(U),de,x)}}else{const q=[...w];if(L!==-1){const Z=q.pop();Z&&q.splice(L,0,Z)}let ee=0;const le=U.map(Z=>{var ae,me,xe,Te;if(typeof Z=="string")return Z;if(Z.nodeType===T.sequenceNodeType.REFERENCE){const ue=T.deserializeRangeWithSheet(Z.token);if(ue.sheetName||(ue.sheetName=y),c&&((ae=E.current.activeSheet)==null?void 0:ae.getName())!==ue.sheetName)return Z.token;const ne=q[ee];if(ee++,!ne)return"";const $e=(me=ne.sheetId)!=null?me:r,dt={range:ne,unitId:(xe=ne.unitId)!=null?xe:I.getUnitId(),sheetName:p((Te=ne.unitId)!=null?Te:I.getUnitId(),$e)},Qe=(I==null?void 0:I.getUnitId())!==o;return ze([dt],c&&($e!==r||Qe),y,Qe)[0]}return Z.token});let de="",ce;le.forEach((Z,ae)=>{de+=Z,ae===O&&(ce=de.length)});const J=[];for(let Z=ee;Z<=w.length-1;Z++){const ae=w[Z],me=(Ze=ae.sheetId)!=null?Ze:r,xe={range:ae,unitId:(De=ae.unitId)!=null?De:I.getUnitId(),sheetName:p((Xe=ae.unitId)!=null?Xe:I.getUnitId(),me)},Te=(I==null?void 0:I.getUnitId())!==o,ne=ze([xe],c&&(me!==r||Te),y,Te);J.push(ne[0])}const fe=U[U.length-1],Le=fe&&(typeof fe=="string"?!1:fe.nodeType===T.sequenceNodeType.REFERENCE),pe=`${de}${J.length&&Le?",":""}${J.join(",")}`;f(pe,!J.length&&ce?ce:pe.length,x)}});m.useEffect(()=>{if(P&&e){let w=!0;const x=(O,L)=>{if(w){w=!1;return}k(O.map(U=>U.rangeWithCoord),L)},M=new a.DisposableCollection;return M.add(P.selectionMoving$.subscribe(O=>{x(O,!1)})),M.add(P.selectionMoveEnd$.subscribe(O=>{x(O,!0)})),()=>{M.dispose()}}},[e,k,P]),m.useEffect(()=>{if(t&&P&&d){const w=new a.DisposableCollection,x=()=>{w.dispose(),P.getSelectionControls().forEach((L,U)=>{w.add(L.selectionScaling$.subscribe(H=>{const j=P.getSelectionDataWithStyle().map(G=>G.rangeWithCoord),oe=j[U];H.sheetId=oe.sheetId,H.unitId=oe.unitId,j[U]=H,k(j,!1)})),w.add(L.selectionMoving$.subscribe(H=>{const j=P.getSelectionDataWithStyle().map(G=>G.rangeWithCoord),oe=j[U];H.sheetId=oe.sheetId,H.unitId=oe.unitId,j[U]=H,k(j,!0)}))})},M=Y.merge(d.input$,W.selectionSet$,P.selectionMoveEnd$).pipe(Gt.debounceTime(50)).subscribe(()=>{x()});return()=>{M.unsubscribe(),w.dispose()}}},[d,t,k,P,W.selectionSet$]),P==null||P.getSelectionDataWithStyle(),m.useEffect(()=>{if(i){const w=h.onCommandExecuted(x=>{var O;if(x.id!==A.SetSelectionsOperation.id)return;const M=x.params;if(M.extra==="formula-editor"&&M.selections.length){const L=M.selections[M.selections.length-1];if(L){const U=n.current===Se.NEED_ADD,H=((O=P==null?void 0:P.getSelectionDataWithStyle())!=null?O:[]).map(j=>j.rangeWithCoord);U?H.push(L.range):H[H.length-1]=L.range,k(H,!0)}}});return()=>{w.dispose()}}},[h,d,n,_,i,k,P]),m.useEffect(()=>{if(!d)return;const w=g.textSelection$.subscribe(x=>{x.unitId===d.getEditorId()&&$t({unitId:o,subUnitId:r,refSelections:s.current,editor:d,refSelectionsService:W,refSelectionsRenderService:P,sheetSkeletonManagerService:$,themeService:u,univerInstanceService:S,currentWorkbook:I})});return()=>w.unsubscribe()},[g.textSelection$,d,s,P,W,$,r,u,o,S])},Pr=(e,t,n,o,r,s)=>{const c=l.useDependency(a.ICommandService),i=l.useDependency(Q.IEditorService),f=l.useDependency(K.IRenderManagerService).getRenderById(t),v=l.useDependency(a.IUniverInstanceService),S=f==null?void 0:f.with(F.RefSelectionsRenderService);m.useEffect(()=>{if(e&&S)if(n){const h=()=>{const _=S.getSelectionControls().length;for(let C=1;C<=_;C++)S.clearLastSelection();return setTimeout(()=>{s()},30)},g=c.onCommandExecuted(_=>{_.id===A.SetWorksheetActiveOperation.id&&h()}),u=v.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_SHEET).subscribe(_=>{h()});return()=>{g.dispose(),u.unsubscribe()}}else{const h=c.beforeCommandExecuted(g=>{if(g.id===A.SetWorksheetActiveOperation.id){o(!1),r(),s();const u=i.getEditor(a.DOCS_NORMAL_EDITOR_UNIT_ID_KEY);u==null||u.focus()}});return()=>{h.dispose()}}},[e,S])},Lr=(e,t,n)=>{const o=l.useDependency(T.LexerTreeBuilder),r=m.useRef(!0);m.useEffect(()=>{if(e){const s=setTimeout(()=>{r.current=!1},500);return()=>{clearTimeout(s)}}},[e]),m.useEffect(()=>{if(!r.current&&t){const s=o.checkIfAddBracket(n);t(s===0&&n.startsWith(T.operatorToken.EQUALS),`${n}`)}},[n,t])},$r=(e,t=[],n)=>{const o=l.useDependency(ve.IDescriptionService),[r,s]=m.useState([]),[c,i]=m.useState(""),d=m.useRef(-1),f=be({nodes:t}),v=()=>{s([]),i(""),d.current=-1};return m.useEffect(()=>{if(n&&e){const h=n.input$.pipe(Y.debounceTime(300)).subscribe(()=>{const g=n.getSelectionRanges();if(g.length===1){const u=f.current.nodes,_=g[0];if(_.collapsed){const C=ct(u,_.startOffset-1,!1);d.current=C;const p=u[C];if(p&&typeof p!="string"&&p.nodeType===T.sequenceNodeType.FUNCTION){d.current=C;const y=p.token,b=o.getSearchListByNameFirstLetter(y);s(b),i(y);return}}}d.current=-1,i(""),s(u=>u!=null&&u.length?[]:u)});return()=>{h.unsubscribe()}}},[n,e]),m.useEffect(()=>{e||v()},[e]),{searchList:r,searchText:c,handlerFormulaReplace:h=>{const g=[...f.current.nodes];if(d.current!==-1){const u=g.splice(d.current+1),_=g.pop()||"";let C=(typeof _=="string"?_.length:_.token.length)-h.length;return g.push(h),u[0]!==T.matchToken.OPEN_BRACKET&&(g.push(T.matchToken.OPEN_BRACKET),C--),{text:lt([...g,...u]),offset:C}}},reset:v}},Fr=()=>{},Wr=m.forwardRef(Vr);function Vr(e,t){const{isFocus:n,sequenceNodes:o,onSelect:r,editor:s,onClose:c=Fr}=e,i=s.getEditorId(),d=l.useDependency(l.IShortcutService),f=l.useDependency(a.ICommandService),{searchList:v,searchText:S,handlerFormulaReplace:h,reset:g}=$r(n,o,s),u=m.useMemo(()=>!!v.length,[v]),_=m.useRef(void 0),[C,p]=m.useState(0),y=m.useRef(!1),[b]=Pt(i,u,[S,v]),E=be({searchList:v,active:C}),I=k=>{const V=h(k);V&&(g(),r(V))};function N(k){y.current&&p(k)}function P(){y.current&&p(-1)}m.useEffect(()=>{if(!v.length)return;const k=`sheet.formula-embedding-editor.search_function.${i}`,V=new a.DisposableCollection,w=x=>{const{searchList:M,active:O}=E.current;switch(x){case l.KeyCode.ARROW_UP:{p(L=>{const U=Math.max(0,L-1);return $(U),U});break}case l.KeyCode.ARROW_DOWN:{p(L=>{const U=Math.min(M.length-1,L+1);return $(U),U});break}case l.KeyCode.TAB:case l.KeyCode.ENTER:{const L=M[O];I(L.name);break}case l.KeyCode.ESC:{g(),c();break}}};return V.add(f.registerCommand({id:k,type:a.CommandType.OPERATION,handler(x,M){const{keyCode:O}=M;w(O)}})),[l.KeyCode.ARROW_UP,l.KeyCode.ARROW_DOWN,l.KeyCode.ENTER,l.KeyCode.ESC,l.KeyCode.TAB].map(x=>({id:k,binding:x,preconditions:()=>!0,priority:1e3,staticParameters:{eventType:K.DeviceInputEventType.Keyboard,keyCode:x}})).forEach(x=>{V.add(d.registerShortcut(x))}),()=>{V.dispose()}},[v]);function $(k){const V=_.current;if(!V)return;const w=V.children[k];if(!w)return;const M=V.getBoundingClientRect().top,O=V.offsetHeight,L=w.getBoundingClientRect(),U=L.top,H=L.height;if(U>=0&&U>M&&U-M+H<=O)return;const j=w.offsetTop-(O-H)/2;V.scrollTo({top:j,behavior:"smooth"})}const W=m.useMemo(()=>{let k="";return()=>{clearTimeout(k),y.current=!0,k=setTimeout(()=>{y.current=!1},300)}},[]);return v.length>0&&u&&R.jsx(l.RectPopup,{portal:!0,anchorRect$:b,direction:"vertical",children:R.jsx("ul",{ref:k=>{_.current=k,t&&(t.current=k)},"data-u-comp":"sheets-formula-editor",className:B.clsx("univer-m-0 univer-box-border univer-max-h-[400px] univer-w-[250px] univer-list-none univer-overflow-y-auto univer-rounded-lg univer-bg-white univer-p-2 univer-leading-5 univer-shadow-md univer-outline-none dark:!univer-bg-gray-900",B.borderClassName,B.scrollbarClassName),children:v.map((k,V)=>R.jsxs("li",{className:B.clsx("univer-box-border univer-cursor-pointer univer-rounded univer-px-2 univer-py-1 univer-text-gray-900 univer-transition-colors dark:!univer-text-white",{"univer-bg-gray-200 dark:!univer-bg-gray-600":C===V}),onMouseEnter:()=>N(V),onMouseLeave:P,onMouseMove:W,onClick:()=>{I(k.name),s&&s.focus()},children:[R.jsxs("span",{className:"univer-text-xs",children:[R.jsx("span",{className:"univer-text-red-500",children:k.name.substring(0,S.length)}),R.jsx("span",{children:k.name.slice(S.length)})]}),R.jsx("span",{className:"univer-block univer-text-xs univer-text-gray-400",children:k.desc})]},k.name))})})}const Ur=e=>e.startsWith(T.operatorToken.EQUALS)?e.slice(1):"",Wt=()=>{},Vt=m.forwardRef((e,t)=>{var jt,qt;const{errorText:n,initValue:o,unitId:r,subUnitId:s,isFocus:c=!0,isSupportAcrossSheet:i=!1,onFocus:d=Wt,onBlur:f=Wt,onChange:v,onVerify:S,className:h,editorId:g,moveCursor:u=!0,onFormulaSelectingChange:_,keyboardEventConfig:C,onMoveInEditor:p,resetSelectionOnBlur:y=!0,autoScrollbar:b=!0,isSingle:E=!0,disableSelectionOnClick:I=!1,autofocus:N=!0,disableContextMenu:P,style:$}=e,W=l.useDependency(Q.IEditorService),k=m.useRef(null),V=l.useEvent(v);m.useImperativeHandle(t,()=>({isClickOutSide:X=>k.current?!k.current.contains(X.target):!1}));const w=l.useEvent(_),x=m.useRef(null),M=m.useRef(void 0),O=M.current,[L,U]=m.useState(c),H=m.useRef(null),j=m.useMemo(()=>g!=null?g:a.createInternalEditorID(`${D.EMBEDDING_FORMULA_EDITOR}-${a.generateRandomId(4)}`),[]),oe=m.useMemo(()=>n!==void 0,[n]),G=l.useDependency(a.IUniverInstanceService),he=G.getUnit(j);l.useObservable(he==null?void 0:he.change$);const Ne=Er(),te=a.BuildTextUtils.transform.getPlainText((qt=(jt=he==null?void 0:he.getBody())==null?void 0:jt.dataStream)!=null?qt:""),Ze=be(te),De=m.useMemo(()=>Ur(te),[te]),Xe=m.useMemo(()=>Ne(De),[De,Ne]),{isSelecting:q,isSelectingRef:ee}=yr({unitId:r,subUnitId:s,editorId:j,isFocus:L,disableOnClick:I}),le=m.useRef(""),ce=l.useDependency(K.IRenderManagerService).getRenderById(j),J=ce==null?void 0:ce.with(Q.DocSelectionRenderService),fe=J==null?void 0:J.isFocusing,Le=m.useMemo(()=>G.getCurrentTypeOfUnit$(a.UniverInstanceType.UNIVER_DOC),[G]),pe=l.useObservable(Le),Z=(pe==null?void 0:pe.getUnitId())===j,ae=m.useRef([]),me=q;l.useUpdateEffect(()=>{V(te)},[te,V]);const xe=Ft("="),Te=br(r,s),ue=l.useEvent((X,re=!0,Ce,ge)=>{if(!M.current)return;le.current=X;const Je=X[0]==="="?X.slice(1):"",_e=Ne(Je),Jr=_e.reduce((Me,tt)=>typeof tt=="object"?`${Me}${tt.token}`:`${Me}${tt}`,""),et=xe(M.current,Jr===Je?_e:[],re,ge);if(ae.current=et,Ce){const Me=ge!=null?ge:O==null?void 0:O.getSelectionRanges();if((Me==null?void 0:Me.length)!==1)return;const eo=Me[0].startOffset-1,to=ct(_e,eo,!1),Yt=At(_e,to);if(Yt>=0){const zt=et.splice(Yt,1)[0];zt&&et.push(zt)}Te(L?et:[],M.current)}});m.useEffect(()=>{L&&ue(te,!1,!0)},[L]),m.useEffect(()=>{if(L){if(le.current===te)return;ue(te,!1,!0)}},[te]),Lr(L,S,te);const ne=_r(O),$e=Dr(L,r,s);m.useEffect(()=>{var X;w(q,(X=J==null?void 0:J.isFocusing)!=null?X:!0)},[w,q]),Q.useKeyboardEvent(L,C,O),m.useLayoutEffect(()=>{let X;if(H.current){X=W.register({autofocus:N,editorUnitId:j,initialSnapshot:{id:j,body:{dataStream:`${o}\r
|
|
5
|
-
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},H.current);const re=W.getEditor(j);M.current=re,ue(o,!1,!0)}return()=>{X==null||X.dispose()}},[]),m.useLayoutEffect(()=>{c?(U(c),ne()):(y&&(O==null||O.blur(),$e()),U(c))},[c,O,ne,$e,y]);const{checkScrollBar:dt}=Q.useResize(O,E,b);Nr(L,!!(q&&Z),r,P),Or(!!(L&&fe&&u),me,O,p);const Qe=l.useEvent((X,re,Ce)=>{if(!fe)return;const ge=re!==-1?[{startOffset:re+1,endOffset:re+1,collapsed:!0}]:void 0;ue(`=${X}`,!0,Ce,ge),Ce&&(ne(),re!==-1&&setTimeout(()=>{const Je={startOffset:re+1,endOffset:re+1},_e=O==null?void 0:O.render.with(Q.DocBackScrollRenderController);_e==null||_e.scrollToRange({...Je,collapsed:!0})},50),dt())});Ar(L&&!!(q&&Z),L,ee,r,s,ae,i,!!me,O,Qe),Pr(L&&!!(q&&Z),r,i,U,f,()=>{ue(Ze.current,!1,!0)});const Ht=X=>{if(X){const re=O==null?void 0:O.getSelectionRanges();if(re&&re.length===1){const Ce=re[0];if(Ce.collapsed){const ge=X.offset;setTimeout(()=>{O==null||O.setSelectionRanges([{startOffset:Ce.startOffset-ge,endOffset:Ce.endOffset-ge}])},30)}}ne(),ue(`=${X.text}`)}},Kt=()=>{U(!0),d(),ne()};return R.jsxs("div",{className:h,children:[R.jsx("div",{className:B.clsx(`
|
|
5
|
+
`,textRuns:[],customBlocks:[],customDecorations:[],customRanges:[]},documentStyle:{}}},H.current);const re=W.getEditor(j);M.current=re,ue(o,!1,!0)}return()=>{X==null||X.dispose()}},[]),m.useLayoutEffect(()=>{c?(U(c),ne()):(y&&(O==null||O.blur(),$e()),U(c))},[c,O,ne,$e,y]);const{checkScrollBar:dt}=Q.useResize(O,E,b);Nr(L,!!(q&&Z),r,P),Or(!!(L&&fe&&u),me,O,p);const Qe=l.useEvent((X,re,Ce)=>{if(!fe)return;const ge=re!==-1?[{startOffset:re+1,endOffset:re+1,collapsed:!0}]:void 0;ue(`=${X}`,!0,Ce,ge),Ce&&(ne(),re!==-1&&setTimeout(()=>{const Je={startOffset:re+1,endOffset:re+1},_e=O==null?void 0:O.render.with(Q.DocBackScrollRenderController);_e==null||_e.scrollToRange({...Je,collapsed:!0})},50),dt())});Ar(L&&!!(q&&Z),L,ee,r,s,ae,i,!!me,O,Qe),Pr(L&&!!(q&&Z),r,i,U,f,()=>{ue(Ze.current,!1,!0)});const Ht=X=>{if(X){const re=O==null?void 0:O.getSelectionRanges();if(re&&re.length===1){const Ce=re[0];if(Ce.collapsed){const ge=X.offset;setTimeout(()=>{O==null||O.setSelectionRanges([{startOffset:Ce.startOffset-ge,endOffset:Ce.endOffset-ge}])},30)}}ne(),ue(`=${X.text}`)}},Kt=()=>{U(!0),d(),ne()};return R.jsxs("div",{className:h,children:[R.jsx("div",{ref:k,className:B.clsx(`
|
|
6
6
|
univer-relative univer-box-border univer-flex univer-h-full univer-w-full univer-items-center
|
|
7
7
|
univer-justify-around univer-gap-2 univer-rounded-none univer-p-0 univer-ring-1
|
|
8
|
-
`,{"univer-ring-primary-500":L,"univer-ring-red-500":oe}),ref:k,children:R.jsx("div",{ref:H,className:"univer-relative univer-h-full univer-w-full",onMouseUp:Kt})}),n!==void 0?R.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,O&&De!==""?R.jsx(Cr,{editor:O,isFocus:L,formulaText:te,onClose:()=>ne()}):null,O?R.jsx(Wr,{isFocus:L,sequenceNodes:Xe,onSelect:Ht,ref:x,editor:O}):null]})});function Br(e,t,n,o){const r=l.useDependency(T.LexerTreeBuilder),s=Ft(""),c=l.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[i,d]=m.useState([]),f=l.useDependency(D.IMarkSelectionService),v=m.useRef(""),S=l.useDependency(a.IUniverInstanceService);return m.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(v.current===h)return;v.current=h;const g=r.sequenceNodesBuilder(h);d(g!=null?g:[])},[c,e,r]),m.useEffect(()=>{var u,_;if(!e)return;if(!t){const C=e.getDocumentData();e.setDocumentData({...C,body:{...C.body,dataStream:(_=(u=C.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const h=s(e,i,!1),g=new a.DisposableCollection;return h.forEach(C=>{const p=T.deserializeRangeWithSheet(C.token),y=S.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),b=y==null?void 0:y.getActiveSheet();if(!p.sheetName&&o!==(b==null?void 0:b.getSheetId())||p.sheetName&&(b==null?void 0:b.getName())!==p.sheetName)return;const E=new a.ColorKit(C.themeColor).toRgb(),I=f.addShape({range:p.range,style:{stroke:C.themeColor,fill:`rgba(${E.r}, ${E.g}, ${E.b}, 0.1)`,strokeDash:12},primary:null});I&&g.add(()=>f.removeShape(I))}),()=>{g.dispose()}},[e,t,s,f,i]),{sequenceNodes:i}}function Hr(e){const t=l.useDependency(A.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:o,subUnitId:r,onChange:s}=e,i=l.useDependency(a.IUniverInstanceService).getUnit(o,a.UniverInstanceType.UNIVER_SHEET),d=l.useEvent(s),f=l.useEvent((v,S)=>{const h=i==null?void 0:i.getActiveSheet();if(!h||!n&&h.getSheetId()!==r||!(v!=null&&v.length))return;const g=v.map(u=>({range:u.range,unitId:o,sheetName:h.getSheetId()===r?"":h.getName()}));d(g,S)});m.useEffect(()=>{const v=new a.DisposableCollection;return v.add(t.selectionMoveStart$.subscribe(S=>{f(S,!0)})),v.add(t.selectionMoving$.subscribe(S=>{f(S,!1)})),v.add(t.selectionMoveEnd$.subscribe(S=>{f(S,!1)})),()=>{v.dispose()}},[f,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Ut=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),Kr=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function jr(e){const{visible:t,initialValue:n,unitId:o,subUnitId:r,maxRangeCount:s=1/0,supportAcrossSheet:c,onConfirm:i,onClose:d,onShowBySelection:f}=e,v=l.useDependency(a.LocaleService),S=l.useDependency(T.LexerTreeBuilder),[h,g]=m.useState([]),[u,_]=m.useState(0),C=m.useRef(null);m.useEffect(()=>{if(t&&n.length){const E=n.map(I=>I.sheetName?T.serializeRangeWithSheet(I.sheetName,I.range):T.serializeRange(I.range));g(E),_(E.length-1)}else g([""]),_(0)},[t]);const p=(E,I)=>{const N=[...h];N[E]=I,g(N)},y=()=>{g([...h,""]),_(h.length)},b=E=>{h.splice(E,1),g([...h])};return Hr({unitId:o,subUnitId:r,supportAcrossSheet:c,onChange:(E,I)=>{if(!t&&f!=null&&f(E))return;const N=new Set(h),P=E.map(k=>k.sheetName?T.serializeRangeWithSheet(k.sheetName,k.range):T.serializeRange(k.range)),$=P.filter(k=>!N.has(k));if(!$.length)return;const W=[...h];if(P.length>1){I||W.splice(u,1),W.push(...$);const k=W.slice(0,s);g(k),_(k.length-1),requestAnimationFrame(()=>{var V;(V=C.current)==null||V.scrollTo({top:C.current.scrollHeight})})}else{W.splice(u,1,...$);const k=W.slice(0,s);g(k),_(u+$.length-1)}}}),R.jsx(B.Dialog,{width:"328px",open:t,title:v.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:R.jsxs("footer",{className:"univer-flex univer-gap-2",children:[R.jsx(B.Button,{onClick:d,children:v.t("rangeSelector.cancel")}),R.jsx(B.Button,{variant:"primary",onClick:()=>{i(h.filter(E=>{const I=S.sequenceNodesBuilder(E);return I&&I.length===1&&typeof I[0]!="string"&&I[0].nodeType===T.sequenceNodeType.REFERENCE}).map(E=>T.deserializeRangeWithSheet(E)).map(E=>({...E,range:Kr(E.range)})))},children:v.t("rangeSelector.confirm")})]}),onClose:d,children:R.jsxs("div",{ref:C,className:B.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",B.scrollbarClassName),children:[h.map((E,I)=>R.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[R.jsx(B.Input,{className:B.clsx("univer-w-full",{"univer-border-primary-600":u===I}),placeholder:v.t("rangeSelector.placeHolder"),onFocus:()=>_(I),value:E,onChange:N=>p(I,N)}),h.length>1&&R.jsx(Dt,{className:"univer-cursor-pointer",onClick:()=>b(I)})]},I)),h.length<s&&R.jsx("div",{children:R.jsxs(B.Button,{variant:"link",onClick:y,children:[R.jsx(xt,{}),R.jsx("span",{children:v.t("rangeSelector.addAnotherRange")})]})})]})})}function qr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Yr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function ut(e){const[t,n]=m.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:c,maxRangeCount:i,supportAcrossSheet:d,autoFocus:f,onChange:v,onRangeSelectorDialogVisibleChange:S,onClickOutside:h,onFocusChange:g,forceShowDialogWhenSelectionChanged:u,hideEditor:_,resetRange:C}=e,[p,y]=m.useState(f!=null?f:!1),[b,E]=m.useState(!1),[I,N]=m.useState([]),P=l.useDependency(a.LocaleService),$=l.useDependency(Q.IEditorService),{sequenceNodes:W}=Br(t,p,s,c),k=be(W),V=l.useDependency(a.ICommandService),w=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),$.blur()}),x=l.useEvent(()=>{var M;w(),N(qr((M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")),E(!0)});return m.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){$.focus(t.getEditorId())},blur:w,verify:()=>Ut(k.current),showDialog:M=>{w(),N(M),E(!0)},hideDialog:()=>{N([]),E(!1)},getValue:()=>{var M;return(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:""}})},[w,t,$,r,k]),m.useEffect(()=>{var M;o==null||o(Ut(W),(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")},[W]),m.useEffect(()=>{S==null||S(b)},[b]),m.useEffect(()=>{if(b&&C)return()=>{const M={unitId:s,subUnitId:c,selections:C};V.executeCommand(A.SetSelectionsOperation.id,M)}},[b]),R.jsxs(R.Fragment,{children:[_?null:R.jsx(Q.RichTextEditor,{isSingle:!0,...e,onFocusChange:(M,O)=>{y(M),g==null||g(M,O)},editorRef:n,onClickOutside:()=>{y(!1),w(),h==null||h()},icon:R.jsx(B.Tooltip,{title:P.t("rangeSelector.buttonTooltip"),placement:"bottom",children:R.jsx(kt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:x})})}),R.jsx(jr,{initialValue:I,unitId:s,subUnitId:c,visible:b,maxRangeCount:i,onConfirm:M=>{const O=Yr(M),L=a.RichTextBuilder.newEmptyData();L.body.dataStream=O,t==null||t.replaceText(O,!1),v==null||v(L,O),E(!1),N([]),requestAnimationFrame(()=>{w()})},onClose:()=>{E(!1),N([])},supportAcrossSheet:d,onShowBySelection:M=>p||u?(N(M),E(!0),!1):!0})]})}const zr=()=>{var o,r;const e=l.useDependency(it),t=l.useObservable(e.currentSelector$),n=m.useRef(null);return m.useEffect(()=>{var s,c;if(t)return(c=n.current)==null||c.showDialog((s=t.initialValue)!=null?s:[]),()=>{var i;(i=n.current)==null||i.hideDialog()}},[t]),R.jsx(ut,{unitId:(o=t==null?void 0:t.unitId)!=null?o:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(s,c)=>{var i;t==null||t.callback((i=c==null?void 0:c.split(",").map(d=>T.deserializeRangeWithSheet(d)))!=null?i:[])}})};var Gr=Object.defineProperty,Zr=Object.getOwnPropertyDescriptor,Xr=(e,t,n)=>t in e?Gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qr=(e,t,n,o)=>{for(var r=o>1?void 0:o?Zr(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},Ge=(e,t)=>(n,o)=>t(n,o,e),Bt=(e,t,n)=>Xr(e,typeof t!="symbol"?t+"":t,n);F.UniverSheetsFormulaUIPlugin=class extends a.Plugin{constructor(t=_t,n,o,r,s){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r,this._uiPartsService=s;const{menu:c,...i}=a.merge(_t,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(an,i,{merge:!0})}onStarting(){a.registerDependencies(this._injector,[[We,{useClass:nt}],[it],[Ye],[Be],[He],[Ke],[je],[F.FormulaReorderController]]),this._initUIPart()}onReady(){[[F.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[st]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))}),a.touchDependencies(this._injector,[[Ye],[He],[je]])}onSteady(){this._injector.get(Be),this._injector.get(F.FormulaReorderController)}_initUIPart(){const t=this._injector.get(l.ComponentManager);this.disposeWithMe(t.register(D.RANGE_SELECTOR_COMPONENT_KEY,ut)),this.disposeWithMe(t.register(D.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Vt)),this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(zr,this._injector)))}},Bt(F.UniverSheetsFormulaUIPlugin,"pluginName",pt),Bt(F.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),F.UniverSheetsFormulaUIPlugin=Qr([a.DependentOn(T.UniverFormulaEnginePlugin,ve.UniverSheetsFormulaPlugin),Ge(1,a.Inject(a.Injector)),Ge(2,K.IRenderManagerService),Ge(3,a.IConfigService),Ge(4,l.IUIPartsService)],F.UniverSheetsFormulaUIPlugin),F.FORMULA_PROMPT_ACTIVATED=ht,F.FormulaEditor=Vt,F.GlobalRangeSelectorService=it,F.HelpFunctionOperation=gt,F.InsertFunctionOperation=se,F.MoreFunctionsOperation=Ve,F.RangeSelector=ut,F.ReferenceAbsoluteOperation=rt,F.SearchFunctionOperation=Ct,F.SelectEditorFormulaOperation=Ie,F.SheetOnlyPasteFormulaCommand=Fe,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|
|
8
|
+
`,{"univer-ring-primary-500":L,"univer-ring-red-500":oe}),children:R.jsx("div",{ref:H,className:"univer-relative univer-h-full univer-w-full",onMouseUp:Kt})}),n!==void 0?R.jsx("div",{className:"univer-my-1 univer-text-xs univer-text-red-500",children:n}):null,O&&De!==""?R.jsx(Cr,{editor:O,isFocus:L,formulaText:te,onClose:()=>ne()}):null,O?R.jsx(Wr,{isFocus:L,sequenceNodes:Xe,onSelect:Ht,ref:x,editor:O}):null]})});function Br(e,t,n,o){const r=l.useDependency(T.LexerTreeBuilder),s=Ft(""),c=l.useObservable(e==null?void 0:e.getDocumentDataModel().change$),[i,d]=m.useState([]),f=l.useDependency(D.IMarkSelectionService),v=m.useRef(""),S=l.useDependency(a.IUniverInstanceService);return m.useEffect(()=>{if(!e)return;const h=e.getDocumentDataModel().getPlainText();if(v.current===h)return;v.current=h;const g=r.sequenceNodesBuilder(h);d(g!=null?g:[])},[c,e,r]),m.useEffect(()=>{var u,_;if(!e)return;if(!t){const C=e.getDocumentData();e.setDocumentData({...C,body:{...C.body,dataStream:(_=(u=C.body)==null?void 0:u.dataStream)!=null?_:"",textRuns:[]}});return}const h=s(e,i,!1),g=new a.DisposableCollection;return h.forEach(C=>{const p=T.deserializeRangeWithSheet(C.token),y=S.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET),b=y==null?void 0:y.getActiveSheet();if(!p.sheetName&&o!==(b==null?void 0:b.getSheetId())||p.sheetName&&(b==null?void 0:b.getName())!==p.sheetName)return;const E=new a.ColorKit(C.themeColor).toRgb(),I=f.addShape({range:p.range,style:{stroke:C.themeColor,fill:`rgba(${E.r}, ${E.g}, ${E.b}, 0.1)`,strokeDash:12},primary:null});I&&g.add(()=>f.removeShape(I))}),()=>{g.dispose()}},[e,t,s,f,i]),{sequenceNodes:i}}function Hr(e){const t=l.useDependency(A.SheetsSelectionsService),{supportAcrossSheet:n=!1,unitId:o,subUnitId:r,onChange:s}=e,i=l.useDependency(a.IUniverInstanceService).getUnit(o,a.UniverInstanceType.UNIVER_SHEET),d=l.useEvent(s),f=l.useEvent((v,S)=>{const h=i==null?void 0:i.getActiveSheet();if(!h||!n&&h.getSheetId()!==r||!(v!=null&&v.length))return;const g=v.map(u=>({range:u.range,unitId:o,sheetName:h.getSheetId()===r?"":h.getName()}));d(g,S)});m.useEffect(()=>{const v=new a.DisposableCollection;return v.add(t.selectionMoveStart$.subscribe(S=>{f(S,!0)})),v.add(t.selectionMoving$.subscribe(S=>{f(S,!1)})),v.add(t.selectionMoveEnd$.subscribe(S=>{f(S,!1)})),()=>{v.dispose()}},[f,t.selectionMoveEnd$,t.selectionMoveStart$,t.selectionMoving$])}const Ut=e=>!e.some(n=>{if(typeof n=="string"){if(n!==T.matchToken.COMMA)return!0}else if(n.nodeType!==T.sequenceNodeType.REFERENCE)return!0;return!1}),Kr=e=>{if(e.endColumn<e.startColumn){const t=e.endColumn;e.endColumn=e.startColumn,e.startColumn=t}if(e.endRow<e.startRow){const t=e.endRow;e.endRow=e.startRow,e.startRow=t}return e};function jr(e){const{visible:t,initialValue:n,unitId:o,subUnitId:r,maxRangeCount:s=1/0,supportAcrossSheet:c,onConfirm:i,onClose:d,onShowBySelection:f}=e,v=l.useDependency(a.LocaleService),S=l.useDependency(T.LexerTreeBuilder),[h,g]=m.useState([]),[u,_]=m.useState(0),C=m.useRef(null);m.useEffect(()=>{if(t&&n.length){const E=n.map(I=>I.sheetName?T.serializeRangeWithSheet(I.sheetName,I.range):T.serializeRange(I.range));g(E),_(E.length-1)}else g([""]),_(0)},[t]);const p=(E,I)=>{const N=[...h];N[E]=I,g(N)},y=()=>{g([...h,""]),_(h.length)},b=E=>{h.splice(E,1),g([...h])};return Hr({unitId:o,subUnitId:r,supportAcrossSheet:c,onChange:(E,I)=>{if(!t&&f!=null&&f(E))return;const N=new Set(h),P=E.map(k=>k.sheetName?T.serializeRangeWithSheet(k.sheetName,k.range):T.serializeRange(k.range)),$=P.filter(k=>!N.has(k));if(!$.length)return;const W=[...h];if(P.length>1){I||W.splice(u,1),W.push(...$);const k=W.slice(0,s);g(k),_(k.length-1),requestAnimationFrame(()=>{var V;(V=C.current)==null||V.scrollTo({top:C.current.scrollHeight})})}else{W.splice(u,1,...$);const k=W.slice(0,s);g(k),_(u+$.length-1)}}}),R.jsx(B.Dialog,{width:"328px",open:t,title:v.t("rangeSelector.title"),draggable:!0,mask:!1,maskClosable:!1,footer:R.jsxs("footer",{className:"univer-flex univer-gap-2",children:[R.jsx(B.Button,{onClick:d,children:v.t("rangeSelector.cancel")}),R.jsx(B.Button,{variant:"primary",onClick:()=>{i(h.filter(E=>{const I=S.sequenceNodesBuilder(E);return I&&I.length===1&&typeof I[0]!="string"&&I[0].nodeType===T.sequenceNodeType.REFERENCE}).map(E=>T.deserializeRangeWithSheet(E)).map(E=>({...E,range:Kr(E.range)})))},children:v.t("rangeSelector.confirm")})]}),onClose:d,children:R.jsxs("div",{ref:C,className:B.clsx("-univer-mx-6 univer-max-h-60 univer-overflow-y-auto univer-px-6",B.scrollbarClassName),children:[h.map((E,I)=>R.jsxs("div",{className:"univer-mb-2 univer-flex univer-items-center univer-gap-4",children:[R.jsx(B.Input,{className:B.clsx("univer-w-full",{"univer-border-primary-600":u===I}),placeholder:v.t("rangeSelector.placeHolder"),onFocus:()=>_(I),value:E,onChange:N=>p(I,N)}),h.length>1&&R.jsx(Dt,{className:"univer-cursor-pointer",onClick:()=>b(I)})]},I)),h.length<s&&R.jsx("div",{children:R.jsxs(B.Button,{variant:"link",onClick:y,children:[R.jsx(xt,{}),R.jsx("span",{children:v.t("rangeSelector.addAnotherRange")})]})})]})})}function qr(e){return e.split(T.matchToken.COMMA).filter(t=>!!t).map(t=>T.deserializeRangeWithSheet(t))}function Yr(e){return e.map(t=>t.sheetName?T.serializeRangeWithSheet(t.sheetName,t.range):T.serializeRange(t.range)).join(T.matchToken.COMMA)}function ut(e){const[t,n]=m.useState(null),{onVerify:o,selectorRef:r,unitId:s,subUnitId:c,maxRangeCount:i,supportAcrossSheet:d,autoFocus:f,onChange:v,onRangeSelectorDialogVisibleChange:S,onClickOutside:h,onFocusChange:g,forceShowDialogWhenSelectionChanged:u,hideEditor:_,resetRange:C}=e,[p,y]=m.useState(f!=null?f:!1),[b,E]=m.useState(!1),[I,N]=m.useState([]),P=l.useDependency(a.LocaleService),$=l.useDependency(Q.IEditorService),{sequenceNodes:W}=Br(t,p,s,c),k=be(W),V=l.useDependency(a.ICommandService),w=l.useEvent(()=>{t==null||t.setSelectionRanges([]),t==null||t.blur(),$.blur()}),x=l.useEvent(()=>{var M;w(),N(qr((M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")),E(!0)});return m.useEffect(()=>{r&&(r.current={get editor(){return t},focus(){$.focus(t.getEditorId())},blur:w,verify:()=>Ut(k.current),showDialog:M=>{w(),N(M),E(!0)},hideDialog:()=>{N([]),E(!1)},getValue:()=>{var M;return(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:""}})},[w,t,$,r,k]),m.useEffect(()=>{var M;o==null||o(Ut(W),(M=t==null?void 0:t.getDocumentDataModel().getPlainText())!=null?M:"")},[W]),m.useEffect(()=>{S==null||S(b)},[b]),m.useEffect(()=>{if(b&&C)return()=>{const M={unitId:s,subUnitId:c,selections:C};V.executeCommand(A.SetSelectionsOperation.id,M)}},[b]),R.jsxs(R.Fragment,{children:[_?null:R.jsx(Q.RichTextEditor,{isSingle:!0,...e,onFocusChange:(M,O)=>{y(M),g==null||g(M,O)},editorRef:n,onClickOutside:()=>{y(!1),w(),h==null||h()},icon:R.jsx(B.Tooltip,{title:P.t("rangeSelector.buttonTooltip"),placement:"bottom",children:R.jsx(kt,{className:"univer-cursor-pointer dark:!univer-text-gray-300",onClick:x})})}),R.jsx(jr,{initialValue:I,unitId:s,subUnitId:c,visible:b,maxRangeCount:i,onConfirm:M=>{const O=Yr(M),L=a.RichTextBuilder.newEmptyData();L.body.dataStream=O,t==null||t.replaceText(O,!1),v==null||v(L,O),E(!1),N([]),requestAnimationFrame(()=>{w()})},onClose:()=>{E(!1),N([])},supportAcrossSheet:d,onShowBySelection:M=>p||u?(N(M),E(!0),!1):!0})]})}const zr=()=>{var o,r;const e=l.useDependency(it),t=l.useObservable(e.currentSelector$),n=m.useRef(null);return m.useEffect(()=>{var s,c;if(t)return(c=n.current)==null||c.showDialog((s=t.initialValue)!=null?s:[]),()=>{var i;(i=n.current)==null||i.hideDialog()}},[t]),R.jsx(ut,{unitId:(o=t==null?void 0:t.unitId)!=null?o:"",subUnitId:(r=t==null?void 0:t.subUnitId)!=null?r:"",hideEditor:!0,selectorRef:n,onChange:(s,c)=>{var i;t==null||t.callback((i=c==null?void 0:c.split(",").map(d=>T.deserializeRangeWithSheet(d)))!=null?i:[])}})};var Gr=Object.defineProperty,Zr=Object.getOwnPropertyDescriptor,Xr=(e,t,n)=>t in e?Gr(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Qr=(e,t,n,o)=>{for(var r=o>1?void 0:o?Zr(t,n):t,s=e.length-1,c;s>=0;s--)(c=e[s])&&(r=c(r)||r);return r},Ge=(e,t)=>(n,o)=>t(n,o,e),Bt=(e,t,n)=>Xr(e,typeof t!="symbol"?t+"":t,n);F.UniverSheetsFormulaUIPlugin=class extends a.Plugin{constructor(t=_t,n,o,r,s){super(),this._config=t,this._injector=n,this._renderManagerService=o,this._configService=r,this._uiPartsService=s;const{menu:c,...i}=a.merge(_t,this._config);c&&this._configService.setConfig("menu",c,{merge:!0}),this._configService.setConfig(an,i,{merge:!0})}onStarting(){a.registerDependencies(this._injector,[[We,{useClass:nt}],[it],[Ye],[Be],[He],[Ke],[je],[F.FormulaReorderController]]),this._initUIPart()}onReady(){[[F.RefSelectionsRenderService]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))})}onRendered(){[[st]].forEach(t=>{this.disposeWithMe(this._renderManagerService.registerRenderModule(a.UniverInstanceType.UNIVER_SHEET,t))}),a.touchDependencies(this._injector,[[Ye],[He],[je]])}onSteady(){this._injector.get(Be),this._injector.get(F.FormulaReorderController)}_initUIPart(){const t=this._injector.get(l.ComponentManager);this.disposeWithMe(t.register(D.RANGE_SELECTOR_COMPONENT_KEY,ut)),this.disposeWithMe(t.register(D.EMBEDDING_FORMULA_EDITOR_COMPONENT_KEY,Vt)),this.disposeWithMe(this._uiPartsService.registerComponent(l.BuiltInUIPart.GLOBAL,()=>l.connectInjector(zr,this._injector)))}},Bt(F.UniverSheetsFormulaUIPlugin,"pluginName",pt),Bt(F.UniverSheetsFormulaUIPlugin,"type",a.UniverInstanceType.UNIVER_SHEET),F.UniverSheetsFormulaUIPlugin=Qr([a.DependentOn(T.UniverFormulaEnginePlugin,ve.UniverSheetsFormulaPlugin),Ge(1,a.Inject(a.Injector)),Ge(2,K.IRenderManagerService),Ge(3,a.IConfigService),Ge(4,l.IUIPartsService)],F.UniverSheetsFormulaUIPlugin),F.FORMULA_PROMPT_ACTIVATED=ht,F.FormulaEditor=Vt,F.GlobalRangeSelectorService=it,F.HelpFunctionOperation=gt,F.InsertFunctionOperation=se,F.MoreFunctionsOperation=Ve,F.RangeSelector=ut,F.ReferenceAbsoluteOperation=rt,F.SearchFunctionOperation=Ct,F.SelectEditorFormulaOperation=Ie,F.SheetOnlyPasteFormulaCommand=Fe,Object.defineProperty(F,Symbol.toStringTag,{value:"Module"})});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@univerjs/sheets-formula-ui",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.1-nightly.202507051607",
|
|
4
4
|
"private": false,
|
|
5
5
|
"author": "DreamNum <developer@univer.ai>",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -64,16 +64,16 @@
|
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
66
|
"@univerjs/icons": "^0.4.4",
|
|
67
|
-
"@univerjs/core": "0.9.
|
|
68
|
-
"@univerjs/design": "0.9.
|
|
69
|
-
"@univerjs/docs": "0.9.
|
|
70
|
-
"@univerjs/docs-ui": "0.9.
|
|
71
|
-
"@univerjs/engine-formula": "0.9.
|
|
72
|
-
"@univerjs/
|
|
73
|
-
"@univerjs/
|
|
74
|
-
"@univerjs/sheets
|
|
75
|
-
"@univerjs/ui": "0.9.
|
|
76
|
-
"@univerjs/
|
|
67
|
+
"@univerjs/core": "0.9.1-nightly.202507051607",
|
|
68
|
+
"@univerjs/design": "0.9.1-nightly.202507051607",
|
|
69
|
+
"@univerjs/docs": "0.9.1-nightly.202507051607",
|
|
70
|
+
"@univerjs/docs-ui": "0.9.1-nightly.202507051607",
|
|
71
|
+
"@univerjs/engine-formula": "0.9.1-nightly.202507051607",
|
|
72
|
+
"@univerjs/engine-render": "0.9.1-nightly.202507051607",
|
|
73
|
+
"@univerjs/sheets-formula": "0.9.1-nightly.202507051607",
|
|
74
|
+
"@univerjs/sheets": "0.9.1-nightly.202507051607",
|
|
75
|
+
"@univerjs/sheets-ui": "0.9.1-nightly.202507051607",
|
|
76
|
+
"@univerjs/ui": "0.9.1-nightly.202507051607"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"postcss": "^8.5.6",
|
|
@@ -83,7 +83,7 @@
|
|
|
83
83
|
"typescript": "^5.8.3",
|
|
84
84
|
"vite": "^6.3.5",
|
|
85
85
|
"vitest": "^3.2.4",
|
|
86
|
-
"@univerjs-infra/shared": "0.9.
|
|
86
|
+
"@univerjs-infra/shared": "0.9.1"
|
|
87
87
|
},
|
|
88
88
|
"scripts": {
|
|
89
89
|
"test": "vitest run",
|
package/LICENSE
DELETED
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
Apache License
|
|
2
|
-
Version 2.0, January 2004
|
|
3
|
-
http://www.apache.org/licenses/
|
|
4
|
-
|
|
5
|
-
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
-
|
|
7
|
-
1. Definitions.
|
|
8
|
-
|
|
9
|
-
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
-
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
-
|
|
12
|
-
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
-
the copyright owner that is granting the License.
|
|
14
|
-
|
|
15
|
-
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
-
other entities that control, are controlled by, or are under common
|
|
17
|
-
control with that entity. For the purposes of this definition,
|
|
18
|
-
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
-
direction or management of such entity, whether by contract or
|
|
20
|
-
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
-
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
-
|
|
23
|
-
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
-
exercising permissions granted by this License.
|
|
25
|
-
|
|
26
|
-
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
-
including but not limited to software source code, documentation
|
|
28
|
-
source, and configuration files.
|
|
29
|
-
|
|
30
|
-
"Object" form shall mean any form resulting from mechanical
|
|
31
|
-
transformation or translation of a Source form, including but
|
|
32
|
-
not limited to compiled object code, generated documentation,
|
|
33
|
-
and conversions to other media types.
|
|
34
|
-
|
|
35
|
-
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
-
Object form, made available under the License, as indicated by a
|
|
37
|
-
copyright notice that is included in or attached to the work
|
|
38
|
-
(an example is provided in the Appendix below).
|
|
39
|
-
|
|
40
|
-
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
-
form, that is based on (or derived from) the Work and for which the
|
|
42
|
-
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
-
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
-
of this License, Derivative Works shall not include works that remain
|
|
45
|
-
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
-
the Work and Derivative Works thereof.
|
|
47
|
-
|
|
48
|
-
"Contribution" shall mean any work of authorship, including
|
|
49
|
-
the original version of the Work and any modifications or additions
|
|
50
|
-
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
-
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
-
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
-
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
-
means any form of electronic, verbal, or written communication sent
|
|
55
|
-
to the Licensor or its representatives, including but not limited to
|
|
56
|
-
communication on electronic mailing lists, source code control systems,
|
|
57
|
-
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
-
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
-
excluding communication that is conspicuously marked or otherwise
|
|
60
|
-
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
-
|
|
62
|
-
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
-
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
-
subsequently incorporated within the Work.
|
|
65
|
-
|
|
66
|
-
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
-
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
-
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
-
Work and such Derivative Works in Source or Object form.
|
|
72
|
-
|
|
73
|
-
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
-
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
-
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
-
(except as stated in this section) patent license to make, have made,
|
|
77
|
-
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
-
where such license applies only to those patent claims licensable
|
|
79
|
-
by such Contributor that are necessarily infringed by their
|
|
80
|
-
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
-
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
-
institute patent litigation against any entity (including a
|
|
83
|
-
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
-
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
-
or contributory patent infringement, then any patent licenses
|
|
86
|
-
granted to You under this License for that Work shall terminate
|
|
87
|
-
as of the date such litigation is filed.
|
|
88
|
-
|
|
89
|
-
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
-
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
-
modifications, and in Source or Object form, provided that You
|
|
92
|
-
meet the following conditions:
|
|
93
|
-
|
|
94
|
-
(a) You must give any other recipients of the Work or
|
|
95
|
-
Derivative Works a copy of this License; and
|
|
96
|
-
|
|
97
|
-
(b) You must cause any modified files to carry prominent notices
|
|
98
|
-
stating that You changed the files; and
|
|
99
|
-
|
|
100
|
-
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
-
that You distribute, all copyright, patent, trademark, and
|
|
102
|
-
attribution notices from the Source form of the Work,
|
|
103
|
-
excluding those notices that do not pertain to any part of
|
|
104
|
-
the Derivative Works; and
|
|
105
|
-
|
|
106
|
-
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
-
distribution, then any Derivative Works that You distribute must
|
|
108
|
-
include a readable copy of the attribution notices contained
|
|
109
|
-
within such NOTICE file, excluding those notices that do not
|
|
110
|
-
pertain to any part of the Derivative Works, in at least one
|
|
111
|
-
of the following places: within a NOTICE text file distributed
|
|
112
|
-
as part of the Derivative Works; within the Source form or
|
|
113
|
-
documentation, if provided along with the Derivative Works; or,
|
|
114
|
-
within a display generated by the Derivative Works, if and
|
|
115
|
-
wherever such third-party notices normally appear. The contents
|
|
116
|
-
of the NOTICE file are for informational purposes only and
|
|
117
|
-
do not modify the License. You may add Your own attribution
|
|
118
|
-
notices within Derivative Works that You distribute, alongside
|
|
119
|
-
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
-
that such additional attribution notices cannot be construed
|
|
121
|
-
as modifying the License.
|
|
122
|
-
|
|
123
|
-
You may add Your own copyright statement to Your modifications and
|
|
124
|
-
may provide additional or different license terms and conditions
|
|
125
|
-
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
-
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
-
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
-
the conditions stated in this License.
|
|
129
|
-
|
|
130
|
-
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
-
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
-
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
-
this License, without any additional terms or conditions.
|
|
134
|
-
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
-
the terms of any separate license agreement you may have executed
|
|
136
|
-
with Licensor regarding such Contributions.
|
|
137
|
-
|
|
138
|
-
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
-
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
-
except as required for reasonable and customary use in describing the
|
|
141
|
-
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
-
|
|
143
|
-
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
-
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
-
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
-
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
-
implied, including, without limitation, any warranties or conditions
|
|
148
|
-
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
-
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
-
appropriateness of using or redistributing the Work and assume any
|
|
151
|
-
risks associated with Your exercise of permissions under this License.
|
|
152
|
-
|
|
153
|
-
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
-
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
-
unless required by applicable law (such as deliberate and grossly
|
|
156
|
-
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
-
liable to You for damages, including any direct, indirect, special,
|
|
158
|
-
incidental, or consequential damages of any character arising as a
|
|
159
|
-
result of this License or out of the use or inability to use the
|
|
160
|
-
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
-
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
-
other commercial damages or losses), even if such Contributor
|
|
163
|
-
has been advised of the possibility of such damages.
|
|
164
|
-
|
|
165
|
-
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
-
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
-
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
-
or other liability obligations and/or rights consistent with this
|
|
169
|
-
License. However, in accepting such obligations, You may act only
|
|
170
|
-
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
-
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
-
defend, and hold each Contributor harmless for any liability
|
|
173
|
-
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
-
of your accepting any such warranty or additional liability.
|
|
175
|
-
|
|
176
|
-
END OF TERMS AND CONDITIONS
|