@univerjs-pro/collaboration-client 0.1.9

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.
Files changed (52) hide show
  1. package/README.md +18 -0
  2. package/lib/cjs/index.js +4 -0
  3. package/lib/es/index.js +3626 -0
  4. package/lib/index.css +1 -0
  5. package/lib/types/controllers/collab-cursor/__tests__/doc-collab-cursor.controller.spec.d.ts +1 -0
  6. package/lib/types/controllers/collab-cursor/__tests__/serialize-text-ranges.spec.d.ts +1 -0
  7. package/lib/types/controllers/collab-cursor/__tests__/sheet-collab-cursor.controller.spec.d.ts +1 -0
  8. package/lib/types/controllers/collab-cursor/collab-cursor.controller.d.ts +24 -0
  9. package/lib/types/controllers/collab-cursor/doc-collab-cursor-entity.d.ts +40 -0
  10. package/lib/types/controllers/collab-cursor/doc-collab-cursor-render.controller.d.ts +22 -0
  11. package/lib/types/controllers/collab-cursor/serialize-text-ranges.d.ts +4 -0
  12. package/lib/types/controllers/collab-cursor/sheet-collab-cursor-entity.d.ts +41 -0
  13. package/lib/types/controllers/collab-cursor/sheet-collab-cursor-render.controller.d.ts +23 -0
  14. package/lib/types/controllers/collab-status/collab-status.controller.d.ts +18 -0
  15. package/lib/types/controllers/collaboration/__tests__/collaboration.controller.spec.d.ts +5 -0
  16. package/lib/types/controllers/collaboration/__tests__/mock-text-selection-render-manager.service.d.ts +10 -0
  17. package/lib/types/controllers/collaboration/__tests__/mocks.d.ts +55 -0
  18. package/lib/types/controllers/collaboration/collaboration-state.d.ts +266 -0
  19. package/lib/types/controllers/collaboration/collaboration.controller.d.ts +110 -0
  20. package/lib/types/controllers/collaboration/utils/changeset-utils.d.ts +17 -0
  21. package/lib/types/controllers/data-loader/__tests__/data-loader.controller.spec.d.ts +1 -0
  22. package/lib/types/controllers/data-loader/data-loader.controller.d.ts +23 -0
  23. package/lib/types/controllers/file-name/file-name.controller.d.ts +13 -0
  24. package/lib/types/index.d.ts +11 -0
  25. package/lib/types/locale/en-US.d.ts +4 -0
  26. package/lib/types/locale/index.d.ts +2 -0
  27. package/lib/types/locale/zh-CN.d.ts +29 -0
  28. package/lib/types/models/cursor.d.ts +29 -0
  29. package/lib/types/plugin.d.ts +20 -0
  30. package/lib/types/services/auth-server/auth-server.service.d.ts +15 -0
  31. package/lib/types/services/collaboration-session/collaboration-session.service.d.ts +107 -0
  32. package/lib/types/services/color-assign/color-assign.service.d.ts +11 -0
  33. package/lib/types/services/ime-cache-transform/doc-transform-ime-cache.service.d.ts +12 -0
  34. package/lib/types/services/local-cache/local-cache.service.d.ts +43 -0
  35. package/lib/types/services/member/member.service.d.ts +33 -0
  36. package/lib/types/services/range-selection/sheet-transform-selections.service.d.ts +9 -0
  37. package/lib/types/services/single-active-unit/single-active-unit.service.d.ts +40 -0
  38. package/lib/types/services/snapshot-server/snapshot-server.service.d.ts +22 -0
  39. package/lib/types/services/socket/collaboration-socket.service.d.ts +36 -0
  40. package/lib/types/services/socket/serialize.d.ts +4 -0
  41. package/lib/types/services/sync-editing-collab-cursor/doc-sync-editing-collab-cursor.service.d.ts +14 -0
  42. package/lib/types/services/text-selection/doc-transform-selections.service.d.ts +9 -0
  43. package/lib/types/services/undoredo/collaborative-undoredo.service.d.ts +20 -0
  44. package/lib/types/services/url/url.service.d.ts +13 -0
  45. package/lib/types/services/url/web-url.service.d.ts +11 -0
  46. package/lib/types/views/components/CollabStatus.d.ts +14 -0
  47. package/lib/types/views/components/CollabStatus.stories.d.ts +9 -0
  48. package/lib/types/views/shapes/doc-collab-cursor.d.ts +27 -0
  49. package/lib/types/views/shapes/sheet-collab-cursor.shape.d.ts +27 -0
  50. package/lib/types/views/shapes/text-bubble.shape.d.ts +20 -0
  51. package/lib/umd/index.js +4 -0
  52. package/package.json +102 -0
@@ -0,0 +1,27 @@
1
+ import { ISheetCollabCursor } from '../../models/cursor';
2
+ import { IMouseEvent, IPointerEvent, IShapeProps, Shape } from '@univerjs/engine-render';
3
+
4
+ export declare const SHEET_COLLAB_CURSOR_ZINDEX = 1;
5
+ export declare const SHEET_COLLAB_CURSOR_BORDER_WIDTH = 1.5;
6
+ export interface ISheetCollabCursorShapeProps extends IShapeProps, ISheetCollabCursor {
7
+ hovered?: boolean;
8
+ labelPosition?: 'bottom' | 'top';
9
+ }
10
+ /**
11
+ * Render a single collaborated cursor on the canvas.
12
+ */
13
+ export declare class SheetCollabCursorShape<T extends ISheetCollabCursorShapeProps = ISheetCollabCursorShapeProps> extends Shape<T> {
14
+ private _color;
15
+ private _hovered;
16
+ private _range;
17
+ private _name;
18
+ private _labelPosition;
19
+ constructor(key?: string, props?: T);
20
+ setShapeProps(props: Partial<ISheetCollabCursorShapeProps>): void;
21
+ onMouseMove(position: {
22
+ row: number;
23
+ column: number;
24
+ }): void;
25
+ triggerDblclick(evt: IPointerEvent | IMouseEvent): boolean;
26
+ protected _draw(ctx: CanvasRenderingContext2D): void;
27
+ }
@@ -0,0 +1,20 @@
1
+ import { IShapeProps, UniverRenderingContext, Shape } from '@univerjs/engine-render';
2
+
3
+ export declare const COLLAB_CURSOR_LABEL_HEIGHT = 20;
4
+ export declare const COLLAB_CURSOR_LABEL_MAX_WIDTH = 200;
5
+ export declare const COLLAB_CURSOR_LABEL_TEXT_PADDING_LR = 4;
6
+ export declare const COLLAB_CURSOR_LABEL_TEXT_PADDING_TB = 5;
7
+ export interface ITextBubbleShapeProps extends IShapeProps {
8
+ color: string;
9
+ text: string;
10
+ }
11
+ /**
12
+ * Render a single collaborated cursor on the canvas.
13
+ */
14
+ export declare class TextBubbleShape<T extends ITextBubbleShapeProps = ITextBubbleShapeProps> extends Shape<T> {
15
+ color: string;
16
+ text: string;
17
+ constructor(key: string, props: T);
18
+ static drawWith(ctx: CanvasRenderingContext2D, props: ITextBubbleShapeProps): void;
19
+ protected _draw(ctx: UniverRenderingContext): void;
20
+ }
@@ -0,0 +1,4 @@
1
+ (function(S,a){typeof exports=="object"&&typeof module<"u"?a(exports,require("@univerjs/core"),require("@univerjs/design"),require("@univerjs/ui"),require("@univerjs-pro/collaboration"),require("@wendellhu/redi"),require("rxjs"),require("rxjs/operators"),require("@univerjs/docs"),require("@univerjs/network"),require("@univerjs/sheets"),require("@univerjs/engine-formula"),require("lodash/debounce"),require("@univerjs/engine-render"),require("@univerjs/sheets-ui"),require("@wendellhu/redi/react-bindings"),require("react"),require("clsx"),require("@univerjs/rpc")):typeof define=="function"&&define.amd?define(["exports","@univerjs/core","@univerjs/design","@univerjs/ui","@univerjs-pro/collaboration","@wendellhu/redi","rxjs","rxjs/operators","@univerjs/docs","@univerjs/network","@univerjs/sheets","@univerjs/engine-formula","lodash/debounce","@univerjs/engine-render","@univerjs/sheets-ui","@wendellhu/redi/react-bindings","react","clsx","@univerjs/rpc"],a):(S=typeof globalThis<"u"?globalThis:S||self,a(S.UniverCollaborationClient={},S.UniverCore,S.UniverDesign,S.UniverUi,S.UniverCollaboration,S["@wendellhu/redi"],S.rxjs,S.rxjs.operators,S.UniverDocs,S.UniverNetwork,S.UniverSheets,S.UniverEngineFormula,S.lodash.debounce,S.UniverEngineRender,S.UniverSheetsUi,S["@wendellhu/redi/react-bindings"],S.React,S.clsx,S.UniverRpc))})(this,function(S,a,k,$,_,l,f,R,L,P,E,qe,Oe,y,ee,Xe,U,yt,Ot){"use strict";var Ys=Object.defineProperty;var Ks=(S,a,k)=>a in S?Ys(S,a,{enumerable:!0,configurable:!0,writable:!0,value:k}):S[a]=k;var d=(S,a,k)=>(Ks(S,typeof a!="symbol"?a+"":a,k),k);var Ge;var j=(i=>(i[i.UNIVER_UNKNOWN=0]="UNIVER_UNKNOWN",i[i.UNIVER_DOC=1]="UNIVER_DOC",i[i.UNIVER_SHEET=2]="UNIVER_SHEET",i[i.UNIVER_SLIDE=3]="UNIVER_SLIDE",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(j||{}),T=(i=>(i[i.UNKNOWN_CMD=0]="UNKNOWN_CMD",i[i.HELLO=1]="HELLO",i[i.JOIN=2]="JOIN",i[i.LEAVE=3]="LEAVE",i[i.INGEST=4]="INGEST",i[i.HEARTBEAT=5]="HEARTBEAT",i[i.RECV=6]="RECV",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(T||{}),Me=(i=>(i[i.UNKNOWN_CODE=0]="UNKNOWN_CODE",i[i.OK=1]="OK",i[i.FAIL=2]="FAIL",i[i.UNRECOGNIZED=-1]="UNRECOGNIZED",i))(Me||{}),Mt=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},Dt=(i,t)=>(e,s)=>t(e,s,i);let G=class extends a.Disposable{constructor(t){super();d(this,"_roomMembers",new Map);d(this,"_currentUser",null);this._univerInstanceService=t,this.disposeWithMe(a.toDisposable(f.merge(this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET).pipe(R.map(e=>e.getUnitId())),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC).pipe(R.map(e=>e.getUnitId())),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SLIDE).pipe(R.map(e=>e.getUnitId()))).subscribe(e=>this._removeRoom(e))))}setCurrentUser(t){this._currentUser=t}getCurrentUser(){return this._currentUser}updateMember(t,e){let s=this._roomMembers.get(t);s||(s=new wt,this._roomMembers.set(t,s)),s.updateMember(e)}removeMember(t,e){const s=this._roomMembers.get(t);s&&s.removeMember(e)}getRoom(t){return this._roomMembers.get(t)}getMember(t,e){const s=this._roomMembers.get(t);if(s)return s.getMember(e)}_removeRoom(t){const e=this._roomMembers.get(t);e&&(e.dispose(),this._roomMembers.delete(t))}dispose(){this._roomMembers.forEach(t=>t.dispose()),this._roomMembers.clear()}};G=Mt([Dt(0,a.IUniverInstanceService)],G);class wt extends a.Disposable{constructor(){super(...arguments);d(this,"_members",new Map)}dispose(){this._members.clear()}updateMember(e){this._members.set(e.memberID,e)}removeMember(e){this._members.delete(e)}getMember(e){return this._members.get(e)}}function ze(i){var s,n,r;const t=i.data,e=JSON.parse(t);switch(e.cmd){case T.HEARTBEAT:case T.HELLO:{const o=e.infoRsp;return{...e,data:o,cmd:e.cmd}}case T.JOIN:{const o=e.joinRsp;return{...e,data:o,cmd:e.cmd}}case T.RECV:{const o=e.collaMsg;switch(o.eventID){case _.CollaborationEvent.CHANGESET_ACK:return{...e,data:{...o,data:(s=o.csAckEvent)==null?void 0:s.cs},cmd:e.cmd};case _.CollaborationEvent.NEW_CHANGESETS:return{...e,data:{...o,data:(n=o.newCsEvent)==null?void 0:n.cs},cmd:e.cmd};case _.CollaborationEvent.CHANGESET_REJ:return{...e,data:{...o,data:(r=o.csRejEvent)==null?void 0:r.cs},cmd:e.cmd};case _.CollaborationEvent.UPDATE_CURSOR:return{...e,data:{...o,data:o.updateCursorEvent},cmd:e.cmd};case _.CollaborationEvent.USERS_ENTER:return{...e,data:{...o,data:o.joinEvent},cmd:e.cmd};case _.CollaborationEvent.USERS_LEAVE:return{...e,data:{...o,data:o.leaveEvent},cmd:e.cmd};case _.CollaborationEvent.LIVESHARE_NEW_HOST:return{...e,data:{...o,data:o.liveShareNewHost},cmd:e.cmd};case _.CollaborationEvent.LIVESHARE_FETCH_OPERATIONS:case _.CollaborationEvent.LIVESHARE_OPERATION:return{...e,data:{...o,data:o.liveShareOperation},cmd:e.cmd};case _.CollaborationEvent.LIVESHARE_TERMINATE:return{...e,data:{...o,data:o.liveShareNewHost},cmd:e.cmd};case _.CollaborationEvent.MSG_FOR_ERROR:return{...e,data:o,cmd:e.cmd};default:return e}}default:return e}}function Je(i){switch(i.cmd){case T.HEARTBEAT:case T.HELLO:return JSON.stringify({cmd:i.cmd,routeKey:i.routeKey});case T.INGEST:{let t;switch(i.data.eventID){case _.CollaborationEvent.UPDATE_CURSOR:{t={eventID:_.CollaborationEvent.UPDATE_CURSOR,updateCursorEvent:i.data.data};break}case _.CollaborationEvent.USERS_LEAVE:{t={eventID:_.CollaborationEvent.USERS_LEAVE,leaveEvent:i.data.data};break}case _.CollaborationEvent.USERS_ENTER:{t={eventID:_.CollaborationEvent.USERS_ENTER,joinEvent:i.data.data};break}case _.CollaborationEvent.LIVESHARE_NEW_HOST:{t={eventID:_.CollaborationEvent.LIVESHARE_NEW_HOST,liveShareNewHost:i.data.data};break}case _.CollaborationEvent.LIVESHARE_OPERATION:{t={eventID:_.CollaborationEvent.LIVESHARE_OPERATION,liveShareOperation:i.data.data};break}case _.CollaborationEvent.LIVESHARE_TERMINATE:{t={eventID:_.CollaborationEvent.LIVESHARE_TERMINATE,liveShareTerminate:i.data.data};break}case _.CollaborationEvent.LIVESHARE_REQUEST_HOST:{t={eventID:_.CollaborationEvent.LIVESHARE_REQUEST_HOST,liveShareRequestHost:i.data.data};break}case _.CollaborationEvent.LIVESHARE_FETCH_OPERATIONS:{t={eventID:_.CollaborationEvent.LIVESHARE_FETCH_OPERATIONS};break}default:t={eventID:i.data.eventID}}return JSON.stringify({cmd:i.cmd,routeKey:i.routeKey,collaMsg:t})}case T.JOIN:return JSON.stringify({cmd:i.cmd,routeKey:i.routeKey,joinReq:i.data});case T.LEAVE:return JSON.stringify({cmd:i.cmd,routeKey:i.routeKey,leaveReq:i.data});default:throw new Error("[serializeCombRequest]: should not fall into default branch!")}}var Ut=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},te=(i,t)=>(e,s)=>t(e,s,i);const De=l.createIdentifier("univer-pro.collaboration-client-socket-service"),Ze="COLLAB_SUBMIT_CHANGESET_URL",Lt="/universer-api/comb";function Nt(i,t,e){return`${i}/${t}/unit/${e}/new_changes`}S.CollaborationSocketService=class{constructor(t,e,s,n,r){this._http=t,this._ws=e,this._configService=s,this._logService=n,this._snapshotServerService=r}createSocket(t){const e=this._ws.createSocket(t);if(!e)throw new Error("[CollaborationSocketService]: failed to create socket!");const s=new a.DisposableCollection,n=new f.Subject;s.add(a.toDisposable(e.close$.subscribe(u=>n.next(u)))),s.add(a.toDisposable(()=>n.complete()));const r=new f.Subject;s.add(a.toDisposable(e.error$.subscribe(u=>r.next(u)))),s.add(a.toDisposable(()=>r.complete()));const o=new f.Subject;s.add(a.toDisposable(e.message$.subscribe(u=>{const v=ze(u);o.next(v)}))),s.add(a.toDisposable(()=>o.complete()));const c=()=>{r.next(new Event("connection error")),n.next(new CloseEvent("connection error")),h.close()},h={memberID:"",close$:n.asObservable(),error$:r.asObservable(),open$:e.open$,message$:o.asObservable(),send:u=>{if(u.cmd===T.INGEST){if(u.data.eventID===_.CollaborationEvent.SUBMIT_CHANGESET){this._submitChangeset(h,u.data).catch(v=>{this._logService.error(v),c()});return}if(u.data.eventID===_.CollaborationEvent.FETCH_MISSING){const v=u.data;this._fetchMissChangesets(v).then(g=>{o.next({cmd:T.RECV,code:Me.OK,routeKey:v.data.unitID,routeType:"",data:{eventID:_.CollaborationEvent.PSEUDO_FETCH_MISSING_RESULT,data:{changesets:g}}})}).catch(g=>{this._logService.error(g),c()});return}}e.send(Je(u))},close:()=>{e.close(),s.dispose()}};return h}async _submitChangeset(t,e){var h;const{unitType:s,unitID:n,changeset:r}=e.data,o={unitID:n,memberID:t.memberID,type:s,changeset:_.parseChangesetToProtocol(r)},c=Nt((h=this._configService.getConfig(Ze))!=null?h:Lt,s,n);try{await this._http.post(c,{body:o})}catch(u){throw this._logService.error("[CollaborationSession]","submit changeset error!"),u}}async _fetchMissChangesets(t){const{unitID:e,from:s,to:n,unitType:r}=t.data;return(await this._snapshotServerService.fetchMissingChangesets({metadata:void 0},{unitID:e,type:r,from:s,to:n})).changesets}},S.CollaborationSocketService=Ut([te(0,l.Inject(P.HTTPService)),te(1,l.Inject(P.WebSocketService)),te(2,a.IConfigService),te(3,a.ILogService),te(4,a.ISnapshotServerService)],S.CollaborationSocketService);var Qe=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},N=(i,t)=>(e,s)=>t(e,s,i),Y=(i=>(i[i.IDLE=0]="IDLE",i[i.JOINING=1]="JOINING",i[i.OFFLINE=2]="OFFLINE",i[i.ONLINE=3]="ONLINE",i))(Y||{});const et="COLLAB_WEB_SOCKET_URL",At="ws://127.0.0.1:8000/universer-api/comb/connect",tt="HEARTBEAT_INTERVAL",kt=3e4,we="HEARTBEAT_TIMEOUT",st=1e4,$t="RETRY_CONNECTING_INTERVAL",Pt=2e4,jt="RETRY_CONNECTING_MAX_COUNT",Ht=3;S.CollaborationSession=class extends a.RxDisposable{constructor(e,s,n,r,o,c,h,u){super();d(this,"_sessionStatus$",new f.BehaviorSubject(0));d(this,"sessionStatus$",this._sessionStatus$.asObservable());d(this,"_event$",new f.Subject);d(this,"event$",this._event$.asObservable());d(this,"_socket");d(this,"_socketMessageSubscription");d(this,"_collaborationTimeoutTimer");this._unitID=e,this._logService=n,this._beforeCloseService=r,this._messageService=o,this._configService=c,this._localeService=h,this._memberService=u,s.pipe(R.takeUntil(this.dispose$)).subscribe(v=>{var g;typeof v>"u"||(this._socket=v,v?(this._joinRoom(v),this._socketMessageSubscription=this._socket.message$.subscribe(I=>{I.routeKey===this._unitID&&this._onCombEvent(I)})):(this._sessionStatus$.next(2),(g=this._socketMessageSubscription)==null||g.unsubscribe(),this._socketMessageSubscription=null))}),this.disposeWithMe(this._beforeCloseService.registerOnClose(()=>{var v;(v=this._socket)==null||v.send({cmd:T.LEAVE,data:{roomID:this._unitID}})}))}get sessionStatus(){return this._sessionStatus$.getValue()}getMemberID(){var e,s;return(s=(e=this._socket)==null?void 0:e.memberID)!=null?s:null}dispose(){super.dispose(),this.dispose$.next(),this.dispose$.complete()}_onCombEvent(e){e.cmd===T.JOIN?this._onJoinRoomEvent(e):e.cmd===T.RECV&&this._onRecvEvent(e)}_joinRoom(e){this._sessionStatus$.next(1),e.send({cmd:T.JOIN,routeKey:this._unitID,routeType:"",data:{rooms:[{roomID:this._unitID}]}})}_onJoinRoomEvent(e){var n;if(e.code===Me.FAIL){this._messageService.show({type:k.MessageType.Warning,content:this._localeService.t("session.room-full")}),this._sessionStatus$.next(2);return}this._sessionStatus$.next(3);const s=(n=e.data.roomInfos[this._unitID])==null?void 0:n.members;s&&s.forEach(r=>this._memberService.updateMember(this._unitID,r))}_onRecvEvent(e){try{const s=e.data;switch(s.eventID){case _.CollaborationEvent.USERS_ENTER:this._onUserJoin(s),this._event$.next(s);break;case _.CollaborationEvent.USERS_LEAVE:this._onUserLeave(s),this._event$.next(s);break;case _.CollaborationEvent.CHANGESET_ACK:this._clearCollaborationTimeoutTimer(),this._event$.next(s);break;case _.CollaborationEvent.MSG_FOR_ERROR:this._logService.error(`save fail reason is ${JSON.stringify(s)}`),this._event$.next(s);break;default:this._event$.next(s)}}catch(s){this._logService.error(s,e)}}_onUserJoin(e){this._memberService.updateMember(this._unitID,e.data)}_onUserLeave(e){this._memberService.removeMember(this._unitID,e.data.memberID)}async send(e,s){if(this.sessionStatus!==3||!this._socket)throw new Error("[CollaborationSession]: should not send message when the session is offline!");try{e.eventID===_.CollaborationEvent.NEW_CHANGESETS&&this._scheduleCollaborationTimeoutTimer(),this._socket.send({cmd:T.INGEST,routeKey:s,routeType:"",data:e})}catch(n){this._logService.error(n)}}_scheduleCollaborationTimeoutTimer(){var e;this._collaborationTimeoutTimer=window.setTimeout(()=>{this._collaborationTimeoutTimer=null,this._messageService.show({type:k.MessageType.Error,content:this._localeService.t("session.collaboration-timeout")})},(e=this._configService.getConfig(we))!=null?e:st)}_clearCollaborationTimeoutTimer(){this._collaborationTimeoutTimer&&(clearTimeout(this._collaborationTimeoutTimer),this._collaborationTimeoutTimer=null)}},S.CollaborationSession=Qe([N(2,a.ILogService),N(3,$.IBeforeCloseService),N(4,$.IMessageService),N(5,a.IConfigService),N(6,l.Inject(a.LocaleService)),N(7,l.Inject(G))],S.CollaborationSession),S.CollaborationSessionService=class extends a.Disposable{constructor(e,s,n,r,o,c){super();d(this,"_socket$",new f.BehaviorSubject(void 0));d(this,"_sessions",new Map);d(this,"_status$",new f.BehaviorSubject(0));d(this,"status$",this._status$.asObservable());d(this,"_socketReady",!1);d(this,"_sendHeartbeatTimer");d(this,"_timeoutTimer");d(this,"_retryConnectingTimer");d(this,"_retryCount",0);this._injector=e,this._localeService=s,this._messageService=n,this._logService=r,this._configService=o,this._socketService=c}get _socket(){return this._socket$.getValue()}dispose(){super.dispose(),this._sessions.forEach(e=>e.dispose()),this._sessions.clear(),this._status$.complete()}async requireSession(e){if(this._sessions.has(e))return this._sessions.get(e);this._tryEnsureSocket();const s=this._injector.createInstance(S.CollaborationSession,e,this._socket$.asObservable());return this._sessions.set(e,s),s}_createSocket(){var n;const e=(n=this._configService.getConfig(et))!=null?n:At;return this._socketService.createSocket(e)}_tryEnsureSocket(){try{const e=this._createSocket();if(e){const s=e.send;e.send=n=>(this._rescheduleHeartbeatEvent(),s.apply(e,[n])),e.message$.subscribe(n=>this._onMessage(e,n)),e.error$.pipe(R.take(1)).subscribe(n=>this._logService.error("[CollaborationSessionService]: socket error",n)),e.open$.pipe(R.take(1)).subscribe(()=>{this._onConnectionOpen(e)}),e.close$.pipe(R.take(1)).subscribe(n=>{this._logService.debug("[CollaborationSessionService]","socket close",n),this._onConnectionFailed()})}}catch(e){this._logService.error(e),this._onConnectionFailed()}}_onConnectionOpen(e){this._logService.debug("[CollaborationSessionService]","socket open."),e.send({cmd:T.HELLO}),this._rescheduleHeartbeatEvent()}_onConnectionFailed(){var e;this._status$.next(2),this._socket$.next(null),this._clearTimeoutTimer(),this._clearHeartbeatTimer(),this._socketReady=!1,this._retryCount<((e=this._configService.getConfig(jt))!=null?e:Ht)?(this._scheduleReconnection(this._retryCount),this._retryCount+=1):this._messageService.show({type:k.MessageType.Error,content:this._localeService.t("session.connection-failed")})}_scheduleReconnection(e){var n;const s=((n=this._configService.getConfig($t))!=null?n:Pt)*2**e;this._messageService.show({type:k.MessageType.Warning,content:this._localeService.t("session.will-retry")}),this._retryConnectingTimer=setTimeout(()=>{this._tryEnsureSocket(),clearTimeout(this._retryConnectingTimer),this._retryConnectingTimer=null},s)}_rescheduleHeartbeatEvent(){var e;this._clearHeartbeatTimer(),this._sendHeartbeatTimer=setTimeout(()=>this._sendHeartbeat(),(e=this._configService.getConfig(tt))!=null?e:kt)}_sendHeartbeat(){this._socket.send({cmd:T.HEARTBEAT}),this._waitForHeartbeatResponse()}_waitForHeartbeatResponse(){var e;this._timeoutTimer=setTimeout(()=>this._onConnectionFailed(),(e=this._configService.getConfig(we))!=null?e:st)}_onMessage(e,s){const{cmd:n}=s;n===T.HELLO&&!this._socketReady&&(e.memberID=s.data.memberID,this._socket$.next(e),this._status$.next(3),this._socketReady=!0),n===T.HEARTBEAT&&this._clearTimeoutTimer(),this._rescheduleHeartbeatEvent()}_clearHeartbeatTimer(){this._sendHeartbeatTimer!=null&&(clearTimeout(this._sendHeartbeatTimer),this._sendHeartbeatTimer=null)}_clearTimeoutTimer(){this._timeoutTimer!=null&&(clearTimeout(this._timeoutTimer),this._timeoutTimer=null)}},S.CollaborationSessionService=Qe([N(0,l.Inject(l.Injector)),N(1,l.Inject(a.LocaleService)),N(2,$.IMessageService),N(3,a.ILogService),N(4,a.IConfigService),N(5,De)],S.CollaborationSessionService);var Bt=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},se=(i,t)=>(e,s)=>t(e,s,i);const nt="LOCAL_CACHE_INTERVAL",xt=1e3;let D=class extends a.Disposable{constructor(t,e,s,n,r){super();d(this,"_cachedData",new Map);d(this,"_saveTaskMap",new Map);d(this,"_disabled",!1);this._configService=t,this._localStorageService=e,this._beforeCloseService=s,this._localeService=n,this._revisionService=r,this._setupBeforeClosingHandler()}disableLocalCache(){this._disabled=!0}enableLocalCache(){this._disabled=!1}dispose(){this._exhaustSavingTask().then(()=>super.dispose())}async loadOfflineData(t){return this._disabled?null:this._localStorageService.getItem(it(t))}async saveOfflineData(t,e){return!!this._localStorageService.setItem(t,e)}updateOfflineData(t,e,s,n){const r=this._revisionService.getCurrentRevForDocument(t);this._cachedData.set(t,{unitID:t,type:e,awaitingChangeset:s,mutations:n,rev:r}),this._saveTaskMap.has(t)||this._scheduleSaving(t)}_scheduleSaving(t){const e=this._getSaveTimeout();e===0?this._saveCache(t):this._saveTaskMap.set(t,setTimeout(()=>this._saveCache(t),e))}_getSaveTimeout(){var t;return(t=this._configService.getConfig(nt))!=null?t:xt}_saveCache(t){const e=this._saveTaskMap.get(t);return e!==void 0&&window.clearTimeout(e),this._localStorageService.setItem(it(t),this._cachedData.get(t)).then(()=>this._saveTaskMap.delete(t))}async _exhaustSavingTask(){const t=[];this._saveTaskMap.forEach((e,s)=>{window.clearTimeout(e),t.push(this._saveCache(s).then(()=>{this._saveTaskMap.delete(s)}))}),await Promise.all(t)}_setupBeforeClosingHandler(){this.disposeWithMe(this._beforeCloseService.registerBeforeClose(()=>{if(this._saveTaskMap.size)return this._localeService.t("collaboration-client.offline-data-not-saved")}))}};D=Bt([se(0,a.IConfigService),se(1,a.ILocalStorageService),se(2,$.IBeforeCloseService),se(3,l.Inject(a.LocaleService)),se(4,l.Inject(_.RevisionService))],D);function it(i){return`unit-cache-${i}`}const de=l.createIdentifier("univer-pro.collaboration-client.single-active-unit-service");var rt=(i=>(i[i.NO_OTHER_CLIENTS_EDITING=0]="NO_OTHER_CLIENTS_EDITING",i[i.OTHER_CLIENTS_EDITING=1]="OTHER_CLIENTS_EDITING",i))(rt||{});const ot=3e4,at="ACTIVE_UNIT_EVENT_CHANNEL";class Vt extends a.Disposable{constructor(){super();d(this,"_id",a.Tools.generateRandomId());d(this,"_selfUnitIDs",new Set);d(this,"_unitOnClients",new Map);d(this,"_heartbeatTimer",null);d(this,"_clearOtherTimers",new Map);d(this,"_unitStatus",new Map);this._init()}dispose(){super.dispose(),this._clearOtherTimers.forEach((e,s)=>this._removeClearOtherTimer(s)),this._heartbeatTimer&&window.clearInterval(this._heartbeatTimer)}getUnitStatus$(e){return this._ensureSubject(e).pipe(f.distinctUntilChanged())}editingUnit(e){this._selfUnitIDs.size===0&&this._scheduleHeartbeat(),this._selfUnitIDs.add(e),this._send({type:0,memberID:this._id,unitID:e})}disposeUnit(e){this._selfUnitIDs.delete(e),this._selfUnitIDs.size===0&&this._heartbeatTimer&&window.clearInterval(this._heartbeatTimer)}_init(){this.disposeWithMe(a.toDisposable(f.fromEvent(window,"storage").subscribe(e=>{if(e.key!==at||!e.newValue)return;const s=JSON.parse(e.newValue);this._handleEvent(s)}))),window.addEventListener("unload",()=>this._send({type:1,memberID:this._id,unitIDs:Array.from(this._selfUnitIDs)}))}_handleEvent(e){switch(e.type){case 0:this._handleJoinEvent(e);break;case 1:this._handleLeaveEvent(e);break;case 2:this._handleHeartbeatEvent(e);break}}_handleJoinEvent(e){const{unitID:s,memberID:n}=e;if(!this._unitOnClients.has(s)||!this._unitOnClients.get(s).has(n)){const r=this._unitOnClients.get(s)||new Set;r.add(n),this._unitOnClients.set(s,r),this._scheduleClearOtherTimer(n),this._send({type:0,memberID:this._id,unitID:s})}else this._ensureSubject(s).next(1)}_scheduleClearOtherTimer(e){this._removeClearOtherTimer(e);const s=window.setTimeout(()=>{this._unitOnClients.forEach(n=>{n.delete(e)})},ot*2);this._clearOtherTimers.set(e,s)}_removeClearOtherTimer(e){if(this._clearOtherTimers.has(e)){const s=this._clearOtherTimers.get(e);s&&window.clearTimeout(s),this._clearOtherTimers.set(e,null)}}_handleLeaveEvent(e){const{memberID:s,unitIDs:n}=e;n.forEach(r=>{var c;const o=this._unitOnClients.get(r);o&&(o.delete(s),(c=this._ensureSubject(r))==null||c.next(o.size===0?0:1))}),this._removeClearOtherTimer(s)}_handleHeartbeatEvent(e){this._scheduleClearOtherTimer(e.memberID)}_send(e){localStorage.setItem(at,JSON.stringify(e))}_scheduleHeartbeat(){this._heartbeatTimer=window.setInterval(()=>{this._send({type:2,memberID:this._id})},ot)}_ensureSubject(e){return this._unitStatus.has(e)||this._unitStatus.set(e,new f.BehaviorSubject(0)),this._unitStatus.get(e)}}var Ft=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},ct=(i,t)=>(e,s)=>t(e,s,i);let ve=class{constructor(i,t){this._injector=i,this._transformService=t}transformIMECache(i){this._transformUndoRedoStack(i),this._transformPreviousActiveRange(i)}transformRemoteChangeset(i){const t=this._injector.get(L.IMEInputManagerService),{redoCache:e}=t.getUndoRedoMutationParamsCache();if(e.length===0)return i;let s=a.Tools.deepClone(i.mutations[0]);for(let n=0;n<e.length;n++){const r={id:"doc.mutation.rich-text-editing",params:{...e[n]}},o=this._transformService.transformMutation(s,r,!1);if(_.isTransformMutationFailure(o))throw o.error;s=o.m1Prime}return{...a.Tools.deepClone(i),mutations:[s]}}_transformUndoRedoStack(i){const t=this._injector.get(L.IMEInputManagerService),{undoCache:e,redoCache:s}=t.getUndoRedoMutationParamsCache();if(e.length===0||s.length===0)return;const n=[],r=[];let o=a.Tools.deepClone(i.mutations[0]),c=a.Tools.deepClone(i.mutations[0]);for(let h=e.length-1;h>=0;h--){const u={id:"doc.mutation.rich-text-editing",params:{...e[h]}},v={id:"doc.mutation.rich-text-editing",params:{...s[h]}},g=this._transformService.transformMutation(o,u,!1),I=this._transformService.transformMutation(c,v,!1);if(_.isTransformMutationFailure(g))throw g.error;if(_.isTransformMutationFailure(I))throw I.error;n.unshift(g.m2Prime.params),r.unshift(I.m2Prime.params),o=g.m1Prime,c=I.m1Prime}t.setUndoRedoMutationParamsCache({undoCache:n,redoCache:r})}_transformPreviousActiveRange(i){const t=this._injector.get(L.IMEInputManagerService),e=t.getActiveRange();if(e==null)return;const s=[{id:"doc.mutation.rich-text-editing",params:{unitId:i.unitID,actions:[],textRanges:[e]}}],n=this._transformService.transformMutationsWithChangeset(i,s);if(!_.isTransformMutationsWithChangesetSuccess(n))throw n.error;const r=n.m2Prime[0].params.textRanges;Array.isArray(r)&&r.length&&t.setActiveRange(r[0])}};ve=Ft([ct(0,l.Inject(l.Injector)),ct(1,_.ITransformService)],ve);var Wt=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},ht=(i,t)=>(e,s)=>t(e,s,i);let Se=class{constructor(i,t){this._injector=i,this._transformService=t}transformSelections(i){var c;const t=this._injector.get(L.TextSelectionManagerService),e=(c=t.getSelections())!=null?c:[],s=e==null?void 0:e.map(L.serializeTextRange);if(s.length===0)return;const n=[{id:"doc.mutation.rich-text-editing",params:{unitId:i.unitID,actions:[],textRanges:s}}],r=this._transformService.transformMutationsWithChangeset(i,n);if(!_.isTransformMutationsWithChangesetSuccess(r))throw r.error;const o=r.m2Prime[0].params.textRanges;Array.isArray(o)&&o.length&&t.replaceTextRanges(o,!1)}};Se=Wt([ht(0,l.Inject(l.Injector)),ht(1,_.ITransformService)],Se);function lt(i){let t="";for(const e of i){const{startOffset:s,endOffset:n,isActive:r}=e;t.length&&(t+=","),t+=`${s}:${n}:${r?"1":"0"}`}return t}function Gt(i){const t=i.split(","),e=[];for(const s of t){const[n,r,o]=s.split(":");e.push({startOffset:Number(n),endOffset:Number(r),collapsed:n===r,isActive:o==="1"})}return e.some(s=>s.isActive)||(e[0].isActive=!0),e}class Ue extends a.RxDisposable{constructor(){super(...arguments);d(this,"_collabCursorState$",new f.BehaviorSubject(null));d(this,"collabCursorState$",this._collabCursorState$.asObservable())}syncEditingCollabCursor(e){const{unitID:s,memberID:n,textRanges:r}=e,o=lt(r),c={unitID:s,memberID:n,selection:o};this._collabCursorState$.next(c)}}var Yt=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},ut=(i,t)=>(e,s)=>t(e,s,i);let ge=class{constructor(i,t){this._injector=i,this._transformService=t}transformSelections(i){var u,v,g,I;const t=this._injector.get(E.SelectionManagerService),{pluginName:e,unitId:s,sheetId:n}=t.getCurrent()||{},r=(u=t.getSelections())!=null?u:[];if(r.length===0||!e||!s||!n)return;const o=[{id:E.SetSelectionsOperation.id,params:{unitId:s,subUnitId:n,pluginName:e,selections:a.Tools.deepClone(r)}}],c=this._transformService.transformMutationsWithChangeset(i,o);if(!_.isTransformMutationsWithChangesetSuccess(c))throw c.error;const h=(I=(g=(v=c.m2Prime[0])==null?void 0:v.params)==null?void 0:g.selections)!=null?I:r;Array.isArray(h)&&h.length&&this._injector.get(a.ICommandService).executeCommand(E.SetSelectionsOperation.id,{unitId:s,subUnitId:n,pluginName:e,selections:h})}};ge=Yt([ut(0,l.Inject(l.Injector)),ut(1,_.ITransformService)],ge);const Kt=new Set([E.InsertSheetMutation.id]);function qt(i,t,e,s,n){var u,v,g,I;const r=[];for(const p of i)if(Kt.has(p.id)){if(r.length>0)break;r.push(p);break}else r.push(p);const o=(v=(u=n.getCurrentUser())==null?void 0:u.userID)!=null?v:"unknown",c=(I=(g=n.getCurrentUser())==null?void 0:g.memberID)!=null?I:"unknown";return{changeset:{unitID:t,type:_.mapDocumentTypeToUniverType(e.getUnitType(t)),baseRev:s.getCurrentRevForDocument(t),revision:0,userID:o,memberID:c,mutations:r},pendingMutations:i.slice(r.length)}}function Xt(i,t,e,s,n){var v,g,I,p;const o=[i.reduce((b,O)=>{var _e;const{id:M}=b,{id:W,type:le}=O,Ye=(_e=b.params)!=null?_e:{actions:[]},ue=O.params;if(M&&M!==W)throw new Error(`Cannot assemble a changeset from multiple mutations of different types: ${M} - ${W}.`);return{...b,id:W,type:le,params:{unitId:ue.unitId,textRanges:ue.textRanges,actions:a.TextX.compose(Ye.actions,ue.actions)}}},{})],c=(g=(v=n.getCurrentUser())==null?void 0:v.userID)!=null?g:"unknown",h=(p=(I=n.getCurrentUser())==null?void 0:I.memberID)!=null?p:"unknown";return{changeset:{unitID:t,type:_.mapDocumentTypeToUniverType(e.getUnitType(t)),baseRev:s.getCurrentRevForDocument(t),revision:0,userID:c,memberID:h,mutations:o},pendingMutations:[]}}var K=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},m=(i,t)=>(e,s)=>t(e,s,i);const _t="SEND_CHANGESET_TIMEOUT",zt=2e3;var w=(i=>(i.NOT_COLLAB="not_collab",i.SYNCED="synced",i.PENDING="pending",i.AWAITING="awaiting",i.AWAITING_WITH_PENDING="awaiting_with_pending",i.FETCH_MISS="fetch_missing",i.CONFLICT="conflict",i.OFFLINE="offline",i))(w||{});class q{constructor(t,e,s,n,r,o,c,h,u){d(this,"_awaitingChangeset",null);d(this,"_pendingMutations",[]);this.unitID=t,this.type=e,this._handler=r,this._commandService=o,this._undoRedoService=c,this._revisionService=h,this._localCacheService=u,this._awaitingChangeset=s,this._pendingMutations=n}_checkMissing(t){const e=this._revisionService.getCurrentRevForDocument(this.unitID);return t.revision>e+1?(this._handler.onMissingChangesets({from:e,to:t.revision-1}),!0):!1}_transformUndoredo(t){this._undoRedoService.transformUndoRedo(this.unitID,t)}_transformSelections(t){var e,s;(s=(e=this._handler).onTransformSelections)==null||s.call(e,t)}_transformIMECache(t){var e,s;return(s=(e=this._handler).onTransformIME)==null?void 0:s.call(e,t)}_transformRemoteChangesetByIMECache(t){var e,s,n;return(n=(s=(e=this._handler).onTransformRemoteChangesetByIMECache)==null?void 0:s.call(e,t))!=null?n:t}_syncEditingCollabCursor(t){var e,s;if(this.type===j.UNIVER_DOC){const{unitID:n,mutations:r,memberID:o}=t,c=r[0].params.textRanges;Array.isArray(c)&&c.length>0&&((s=(e=this._handler).onSyncEditingCollabCursor)==null||s.call(e,{unitID:n,memberID:o,textRanges:c}))}}_updateLocalCache(){this._localCacheService.updateOfflineData(this.unitID,this.type,this._awaitingChangeset,this._pendingMutations)}_getCurrentRevision(){return this._revisionService.getCurrentRevForDocument(this.unitID)}_incrementRevisionNumber(){this._revisionService.incrementRevForDocument(this.unitID)}_executeRemoteChangeset(t){var n;const e=this._transformRemoteChangesetByIMECache(t),s=a.sequenceExecute(e.mutations,this._commandService,{fromCollab:!0});if(!s.result)throw s.error instanceof Error?s.error:new Error((n=s.error)!=null?n:"[CollaborationState]: apply error!");this._transformIMECache(e),this._transformUndoredo(t),this._transformSelections(e),this._syncEditingCollabCursor(e),this._incrementRevisionNumber()}}let ne=class extends q{constructor(t,e,s,n,r,o,c,h,u){super(t,e,null,[],s,h,c,n,r);d(this,"status","synced");this._injector=o,this._logService=u}appendMutation(t){const e=this._injector.createInstance(H,this.unitID,this.type,[t],this._handler);return e._schedule(),e._updateLocalCache(),e}onRemoteChangeset(t){if(this._checkMissing(t))return this._injector.createInstance(x,this.unitID,this.type,null,[],null,[t],this._handler);try{return this._executeRemoteChangeset(t),this}catch(s){return this._logService.error("[CollaborationController]: remote changeset applied error.",s),this}}onRemoteAck(){throw new Error("[SyncedState]: received acknowledgement.")}onRemoteRej(){throw new Error("[SyncedState]: received rejection.")}toggleOffline(){return this._injector.createInstance(F,this.unitID,this.type,null,[],this._handler)}toggleOnline(){return this}resend(){throw new Error("[SyncedState]: invalid calling to `resend`.")}};ne=K([m(3,l.Inject(_.RevisionService)),m(4,l.Inject(D)),m(5,l.Inject(l.Injector)),m(6,a.IUndoRedoService),m(7,a.ICommandService),m(8,a.ILogService)],ne);let H=class extends q{constructor(t,e,s,n,r,o,c,h,u,v,g,I,p,b){super(t,e,null,s,n,v,b,o,c);d(this,"status","pending");d(this,"_scheduleTimestamp",null);d(this,"_sendingTimer",null);this._injector=r,this._memberService=h,this._logService=u,this._configService=g,this._transformService=I,this._univerInstanceService=p}appendMutation(t){return this._pendingMutations.push(t),this._updateLocalCache(),this}onRemoteChangeset(t){if(this._checkMissing(t))return this._clearScheduledTask(),this._injector.createInstance(x,this.unitID,this.type,null,this._pendingMutations,null,[t],this._handler);try{const s=this._transformService.transformMutationsWithChangeset(t,this._pendingMutations);if(_.isTransformMutationsWithChangesetSuccess(s)){const{c1Prime:n,m2Prime:r}=s;this._executeRemoteChangeset(n);const o=this._injector.createInstance(H,this.unitID,this.type,r,this._handler);return this._clearScheduledTask(),o._schedule(this._scheduleTimestamp?Math.max(0,new Date().getTime()-this._scheduleTimestamp):this._getSendChangesetTimeout()),o}throw s.error}catch(s){return this._logService.error(s),this._onConflict()}}onRemoteAck(){throw new Error("[PendingState]: received acknowledgement.")}onRemoteRej(){throw new Error("[PendingState]: received rejection.")}toggleOffline(){return this._clearScheduledTask(),this._injector.createInstance(F,this.unitID,this.type,null,this._pendingMutations,this._handler)}toggleOnline(){return this}_schedule(t){t=t!=null?t:this._getSendChangesetTimeout(),this._scheduleTimestamp=new Date().getTime(),this._sendingTimer=setTimeout(()=>{this._clearScheduledTask();let e=null;switch(this.type){case j.UNIVER_SHEET:{e=qt(this._pendingMutations,this.unitID,this._univerInstanceService,this._revisionService,this._memberService);break}case j.UNIVER_DOC:{e=Xt(this._pendingMutations,this.unitID,this._univerInstanceService,this._revisionService,this._memberService);break}default:throw new Error(`[PendingState]: unhandled univer type: ${this.type} in _schedule.`)}const{changeset:s,pendingMutations:n}=e;this._handler.onSendChangeset(s);const r=n.length?this._injector.createInstance(B,this.unitID,this.type,s,n,this._handler):this._injector.createInstance(V,this.unitID,this.type,s,this._handler);r._updateLocalCache(),this._handler.onStateChange(this,r)},t)}_getSendChangesetTimeout(){var t;return(t=this._configService.getConfig(_t))!=null?t:zt}resend(){throw new Error("[PendingState]: invalid calling to `resend`.")}_clearScheduledTask(){this._sendingTimer!=null&&(clearTimeout(this._sendingTimer),this._sendingTimer=null)}_onConflict(){return this._clearScheduledTask(),this._injector.createInstance(X,this.unitID,this.type,null,this._pendingMutations,this._handler)}};H=K([m(4,l.Inject(l.Injector)),m(5,l.Inject(_.RevisionService)),m(6,l.Inject(D)),m(7,l.Inject(G)),m(8,a.ILogService),m(9,a.ICommandService),m(10,a.IConfigService),m(11,_.ITransformService),m(12,a.IUniverInstanceService),m(13,a.IUndoRedoService)],H);let V=class extends q{constructor(t,e,s,n,r,o,c,h,u,v,g){super(t,e,s,[],n,h,g,o,c);d(this,"status","awaiting");this._injector=r,this._logService=u,this._transformService=v}appendMutation(t){const e=this._injector.createInstance(B,this.unitID,this.type,this._awaitingChangeset,[t],this._handler);return e._updateLocalCache(),e}onRemoteChangeset(t){if(this._checkMissing(t))return this._injector.createInstance(x,this.unitID,this.type,this._awaitingChangeset,[],null,[t],this._handler);try{const s=this._transformService.transformChangesets([t],[this._awaitingChangeset],!1);if(_.isTransformChangesetsSuccess(s)){const{c1Prime:n,c2Prime:r}=s;this._executeRemoteChangeset(n[0]),r[0].baseRev=this._getCurrentRevision();const o=this._injector.createInstance(V,this.unitID,this.type,r[0],this._handler);return o._updateLocalCache(),o}return this._onConflict()}catch(s){return this._logService.error(s),this._onConflict()}}onRemoteAck(t){const e=this._revisionService.getCurrentRevForDocument(this.unitID);if(t.revision<e-1)return this;if(this._checkMissing(t))return this._injector.createInstance(x,this.unitID,this.type,null,[],this._awaitingChangeset,[],this._handler);this._incrementRevisionNumber();const n=this._injector.createInstance(ne,this.unitID,this.type,this._handler);return n._updateLocalCache(),n}onRemoteRej(){return this._onConflict()}toggleOffline(){return this._injector.createInstance(F,this.unitID,this.type,this._awaitingChangeset,[],this._handler)}toggleOnline(){return this}resend(){this._handler.onSendChangeset(this._awaitingChangeset)}_onConflict(){return this._injector.createInstance(X,this.unitID,this.type,this._awaitingChangeset,[],this._handler)}};V=K([m(4,l.Inject(l.Injector)),m(5,l.Inject(_.RevisionService)),m(6,l.Inject(D)),m(7,a.ICommandService),m(8,a.ILogService),m(9,_.ITransformService),m(10,a.IUndoRedoService)],V);let B=class extends q{constructor(t,e,s,n,r,o,c,h,u,v,g,I){super(t,e,s,n,r,u,I,c,h);d(this,"status","awaiting_with_pending");this._injector=o,this._logService=v,this._transformService=g}appendMutation(t){return this._pendingMutations.push(t),this}onRemoteChangeset(t){if(this._checkMissing(t))return this._injector.createInstance(x,this.unitID,this.type,this._awaitingChangeset,this._pendingMutations,null,[t],this._handler);try{const s=this._transformService.transformChangesets([t],[this._awaitingChangeset],!1);if(_.isTransformChangesetsSuccess(s)){const{c1Prime:n,c2Prime:r}=s,o=this._transformService.transformMutationsWithChangeset(n[0],this._pendingMutations);if(_.isTransformMutationsWithChangesetSuccess(o)){const{c1Prime:c,m2Prime:h}=o;return this._executeRemoteChangeset(c),r[0].baseRev=this._getCurrentRevision(),this._injector.createInstance(B,this.unitID,this.type,r[0],h,this._handler)}throw o.error}throw s.error}catch(s){return this._logService.error(s),this._onConflict()}}onRemoteAck(t){if(this._checkMissing(t))return this._injector.createInstance(x,this.unitID,this.type,null,this._pendingMutations,this._awaitingChangeset,[],this._handler);this._incrementRevisionNumber();const s=this._injector.createInstance(H,this.unitID,this.type,this._pendingMutations,this._handler);return s._schedule(),s._updateLocalCache(),s}onRemoteRej(){return this._onConflict()}toggleOffline(){return this._injector.createInstance(F,this.unitID,this.type,this._awaitingChangeset,this._pendingMutations,this._handler)}toggleOnline(){return this}resend(){this._handler.onSendChangeset(this._awaitingChangeset)}_onConflict(){return this._injector.createInstance(X,this.unitID,this.type,null,this._pendingMutations,this._handler)}};B=K([m(5,l.Inject(l.Injector)),m(6,l.Inject(_.RevisionService)),m(7,l.Inject(D)),m(8,a.ICommandService),m(9,a.ILogService),m(10,_.ITransformService),m(11,a.IUndoRedoService)],B);let X=class extends q{constructor(t,e,s,n,r,o,c,h,u,v,g,I){super(t,e,s,n,r,c,h,v,u);d(this,"status","conflict");this._univerPermissionService=o,this._localeService=g,this._notificationService=I,this._showConflictNotification(),this._clearLocalCache(),this._disableEditing()}appendMutation(){return this}onRemoteChangeset(){return this}onRemoteAck(){return this}onRemoteRej(){return this}toggleOffline(){return this}toggleOnline(){return this}resend(){throw new Error("[ConflictState]: invalid calling to `resend`.")}_clearLocalCache(){this._localCacheService.updateOfflineData(this.unitID,this.type,null,[])}_showConflictNotification(){this._notificationService.show({title:this._localeService.t("conflict.title"),content:this._localeService.t("conflict.content"),type:"error",duration:0})}_disableEditing(){this._univerPermissionService.setEditable(this.unitID,!1)}};X=K([m(5,l.Inject(a.UniverPermissionService)),m(6,a.ICommandService),m(7,a.IUndoRedoService),m(8,l.Inject(D)),m(9,l.Inject(_.RevisionService)),m(10,l.Inject(a.LocaleService)),m(11,$.INotificationService)],X);let F=class extends q{constructor(t,e,s,n,r,o,c,h,u,v){super(t,e,s,n,r,u,v,c,h);d(this,"status","offline");this._injector=o}appendMutation(t){return this._pendingMutations.push(t),this._updateLocalCache(),this}onRemoteChangeset(t){throw new Error("[OfflineState]: received changeset.")}onRemoteAck(){throw new Error("[OfflineState]: received acknowledgement.")}onRemoteRej(){throw new Error("[OfflineState]: received rejection.")}toggleOffline(){return this}toggleOnline(){const{_injector:t,_pendingMutations:e,_awaitingChangeset:s,unitID:n,_handler:r,type:o}=this,c=dt(t,n,o,s,e,r);return c instanceof H?c._schedule():(c instanceof B||c instanceof V)&&c.resend(),c}resend(){throw new Error("[OfflineState]: invalid calling to `resend`.")}};F=K([m(5,l.Inject(l.Injector)),m(6,l.Inject(_.RevisionService)),m(7,l.Inject(D)),m(8,a.ICommandService),m(9,a.IUndoRedoService)],F);let x=class extends q{constructor(t,e,s,n,r,o,c,h,u,v,g,I,p,b){super(t,e,s,n,c,I,p,u,v);d(this,"status","fetch_missing");this._acknowledgedAwaitingChangeset=r,this._queuedRemoteChangesets=o,this._injector=h,this._logService=g,this._transformService=b}onMissedChangesetFetched(t){try{const e=[...t,...this._queuedRemoteChangesets],s=[this._awaitingChangeset||this._acknowledgedAwaitingChangeset].filter(h=>!!h);let n,r;if(s.length){const h=this._transformService.transformChangesets(e,s,!1);if(!_.isTransformChangesetsSuccess(h))throw h.error;n=h.c1Prime,r=h.c2Prime}else n=e,r=[];let o=this._pendingMutations;n.forEach(h=>{let u;if(o.length){const v=this._transformService.transformMutationsWithChangeset(h,o);if(!_.isTransformMutationsWithChangesetSuccess(v))throw v.error;u=v.c1Prime,o=v.m2Prime}else u=h;this._executeRemoteChangeset(u)}),this._acknowledgedAwaitingChangeset&&this._incrementRevisionNumber(),this._awaitingChangeset&&r.length&&(r[0].baseRev=this._getCurrentRevision());let c;if(this._awaitingChangeset&&o.length!==0)c=this._injector.createInstance(B,this.unitID,this.type,r[0],o,this._handler);else if(this._awaitingChangeset&&o.length===0)r[0].baseRev=this._getCurrentRevision(),c=this._injector.createInstance(V,this.unitID,this.type,r[0],this._handler);else if(o.length!==0){const h=this._injector.createInstance(H,this.unitID,this.type,o,this._handler);h._schedule(),c=h}else c=this._injector.createInstance(ne,this.unitID,this.type,this._handler);return c._updateLocalCache(),c}catch(e){return this._logService.error("[FetchMissState]","failed to apply missed changesets!",e),this._injector.createInstance(X,this.unitID,this.type,this._awaitingChangeset,this._pendingMutations,this._handler)}}resend(){throw new Error("[FetchingMissState]: invalid calling to `resend`.")}appendMutation(t){return this._pendingMutations.push(t),this}onRemoteChangeset(t){return this._queuedRemoteChangesets.push(t),this}onRemoteAck(t){if(this._awaitingChangeset)return this._acknowledgedAwaitingChangeset=this._awaitingChangeset,this._awaitingChangeset=null,this;throw new Error("[FetchingMissState]: not expected to receive ack when `this._awaitingChangeset` is null!")}onRemoteRej(){return this._onConflict()}toggleOffline(){return this._injector.createInstance(F,this.unitID,this.type,this._awaitingChangeset,this._pendingMutations,this._handler)}toggleOnline(){return this}_onConflict(){return this._injector.createInstance(X,this.unitID,this.type,this._awaitingChangeset,this._pendingMutations,this._handler)}};x=K([m(7,l.Inject(l.Injector)),m(8,l.Inject(_.RevisionService)),m(9,l.Inject(D)),m(10,a.ILogService),m(11,a.ICommandService),m(12,a.IUndoRedoService),m(13,_.ITransformService)],x);function dt(i,t,e,s,n,r){return s&&n.length?i.createInstance(B,t,e,s,n,r):s?i.createInstance(V,t,e,s,r):n.length?i.createInstance(H,t,e,n,r):i.createInstance(ne,t,e,r)}var fe=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},C=(i,t)=>(e,s)=>t(e,s,i);S.CollaborationController=class extends a.RxDisposable{constructor(e,s,n){super();d(this,"_entities",new Map);d(this,"_entityInit$",new f.Subject);this._injector=e,this._collabSessionService=s,this._univerInstanceService=n,this._init()}dispose(){super.dispose(),this._entities.forEach(e=>e.dispose()),this._entities.clear()}getCollabEntity(e){var s;return(s=this._entities.get(e))!=null?s:null}getCollabEntity$(e){const s=this.getCollabEntity(e);return s?f.of(s):this._entityInit$.pipe(R.filter(n=>n.unitID===e))}_init(){this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(f.takeUntil(this.dispose$),R.delay(16)).subscribe(async s=>{const n=s.getUnitId(),r=await this._startCollaboration(n,j.UNIVER_SHEET);this._entities.set(n,r)}),this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(f.takeUntil(this.dispose$),R.delay(16)).pipe(R.filter(s=>!s.getUnitId().startsWith("__"))).subscribe(async s=>{const n=s.getUnitId(),r=await this._startCollaboration(n,j.UNIVER_DOC);this._entities.set(n,r)}),f.merge(this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC)).pipe(f.takeUntil(this.dispose$)).subscribe(s=>{const n=s.getUnitId(),r=this._entities.get(n);r&&(r.dispose(),this._entities.delete(n))})}async _startCollaboration(e,s){const n=await this._collabSessionService.requireSession(e),r=this._injector.createInstance(this._getCtorByUniverType(s),e,s,n);return await r.init(),this._entityInit$.next(r),r}_getCtorByUniverType(e){switch(e){case j.UNIVER_DOC:return Le;case j.UNIVER_SHEET:return Ne;default:throw new Error(`[CollaborationController]: invalid univer type: ${e}`)}}},S.CollaborationController=fe([a.OnLifecycle(a.LifecycleStages.Starting,S.CollaborationController),C(0,l.Inject(l.Injector)),C(1,l.Inject(S.CollaborationSessionService)),C(2,a.IUniverInstanceService)],S.CollaborationController);let me=class extends a.RxDisposable{constructor(t,e,s,n,r,o,c,h,u,v,g,I,p){super();d(this,"_state$",new f.BehaviorSubject(null));d(this,"state$",this._state$.asObservable());d(this,"_state");d(this,"_collaborationPaused",!1);d(this,"status$",this.state$.pipe(R.map(t=>t?t.status:w.OFFLINE),R.shareReplay(1)));d(this,"_transitionLocked",!1);d(this,"_remoteChangesetQueue",[]);this.unitID=t,this._type=e,this._session=s,this._injector=n,this._localCacheService=r,this._univerPermissionService=o,this._compressMutationService=c,this._localeService=h,this._revisionService=u,this._logService=v,this._commandService=g,this._messageService=I,this._singleActiveUnitService=p}get state(){return this._state}async init(){if(this.state)throw new Error('[CollaborationEntity]: initial state has been created before. You should not call "init" twice.');await this._init()}pauseCollaboration(){return this._collaborationPaused=!0,a.toDisposable(()=>{this._collaborationPaused=!1,this._exhaustRemoteChangesetQueue()})}_updateState(t){this._state=t,this._state$.next(t)}async _init(){var t;return this._updateState(await this._createInitialState()),this._singleActiveUnitService&&((t=this._singleActiveUnitService)==null||t.editingUnit(this.unitID),this.disposeWithMe(a.toDisposable(this._singleActiveUnitService.getUnitStatus$(this.unitID).subscribe(e=>{this._logService.debug("[CollaborationEntity]","editing status changed to",e),e===rt.OTHER_CLIENTS_EDITING?(this._messageService.show({content:this._localeService.t("collaboration.single-unit.warning"),type:k.MessageType.Warning}),this._univerPermissionService.setEditable(this.unitID,!1)):this._univerPermissionService.setEditable(this.unitID,!0)})))),this.disposeWithMe(a.toDisposable(this._session.sessionStatus$.subscribe(e=>{e===Y.ONLINE?this._toggleOnline():e===Y.OFFLINE&&this._toggleOffline()}))),this.disposeWithMe(a.toDisposable(this._session.event$.subscribe(e=>{try{const s=e.eventID;s===_.CollaborationEvent.NEW_CHANGESETS?this._onRemoteChangeset(_.parseProtocolChangeset(e.data)):s===_.CollaborationEvent.CHANGESET_ACK?this._onRemoteACK(e.data):s===_.CollaborationEvent.CHANGESET_REJ?this._onRemoteRejected():s===_.CollaborationEvent.PSEUDO_FETCH_MISSING_RESULT&&this._onFetchMissResult(e.data.changesets.map(n=>_.parseProtocolChangeset(n)))}catch(s){throw console.error("Error on receiving event",s),s}}))),this._state}_unlockTransition(){this._transitionLocked=!1}_lockTransition(){if(this._transitionLocked)throw new Error("[CollaborationEntity]: cannot lock transition twice! This is an implementation error, meaning you transit the collaboration state again in the process of a previous transition. This should never happen.");this._transitionLocked=!0}_onLocalMutation(t){this._lockTransition(),this._updateState(this._state.appendMutation(t)),this._unlockTransition()}_onRemoteChangeset(t){if(!(t.revision<=this._revisionService.getCurrentRevForDocument(this.unitID))){if(this._collaborationPaused){this._remoteChangesetQueue.push(t);return}this._applyRemoteChangeset(t)}}_exhaustRemoteChangesetQueue(){this._remoteChangesetQueue.forEach(t=>this._applyRemoteChangeset(t)),this._remoteChangesetQueue=[]}_applyRemoteChangeset(t){const e=this._compressMutationService.interceptor.fetchThroughInterceptors(this._compressMutationService.interceptor.getInterceptPoints().COMPRESS_MUTATION_APPLY)(t.mutations,null)||t.mutations,s={...t,mutations:e};this._lockTransition(),this._updateState(this._state.onRemoteChangeset(s)),this._unlockTransition()}_onRemoteACK(t){this._lockTransition(),this._updateState(this._state.onRemoteAck(t)),this._unlockTransition()}_onRemoteRejected(){this._lockTransition(),this._updateState(this._state.onRemoteRej()),this._unlockTransition()}_onFetchMissResult(t){if(!(this._state instanceof x))throw new TypeError("[CollaborationEntity]: cannot apply missing results on other states!");const e=t.map(s=>{const n=this._compressMutationService.interceptor.fetchThroughInterceptors(this._compressMutationService.interceptor.getInterceptPoints().COMPRESS_MUTATION_APPLY)(s.mutations,null)||s.mutations;return{...s,mutations:n}});this._lockTransition(),this._updateState(this._state.onMissedChangesetFetched(e)),this._unlockTransition()}_toggleOffline(){this._lockTransition(),this._updateState(this._state.toggleOffline()),this._unlockTransition()}_toggleOnline(){this._lockTransition(),this._updateState(this._state.toggleOnline()),this._unlockTransition()}async _createInitialState(){return new Promise(t=>{this._session.sessionStatus$.pipe(R.take(1)).subscribe(async e=>{t(await this._createInitialStateImpl(e===Y.ONLINE))})})}_createHandler(){const t=this.unitID;return{onStateChange:(s,n)=>{if(s!==this._state)throw new Error(`[ClientCollaborationController]: invalid state transition! State transferred from is not the current state.
2
+ Before: ${s.status}
3
+ After: ${n.status}
4
+ Current: ${this._state.status}`);this._updateState(n)},onSendChangeset:s=>{const n={eventID:_.CollaborationEvent.SUBMIT_CHANGESET,data:{unitID:s.unitID,unitType:this._type,changeset:s,memberID:this._session.getMemberID()}};this._session.send(n,this.unitID)},onMissingChangesets:({from:s,to:n})=>{this._logService.debug("[CollaborationEntity]",`fetching missing changesets from ${s} to ${n}`);const r={eventID:_.CollaborationEvent.FETCH_MISSING,data:{unitID:t,unitType:this._type,from:s,to:n}};this._session.send(r,this.unitID)}}}async _createInitialStateImpl(t){var c,h;const e=await this._localCacheService.loadOfflineData(this.unitID),s=(c=e==null?void 0:e.mutations)!=null?c:[],n=(h=e==null?void 0:e.awaitingChangeset)!=null?h:null,r=this.unitID;try{this._replayCachedMutations(n,s)}catch(u){this._logService.error(u)}const o=this._createHandler();if(t){const u=dt(this._injector,r,this._type,n,s,o);return u instanceof H?u._schedule():(u instanceof B||u instanceof V)&&u.resend(),u}return this._injector.createInstance(F,r,this._type,n,s,o)}_replayCachedMutations(t,e){var n,r;const s=this._compressMutationService.interceptor.fetchThroughInterceptors(this._compressMutationService.interceptor.getInterceptPoints().COMPRESS_MUTATION_APPLY);(n=s((t==null?void 0:t.mutations)||[],null))==null||n.forEach(o=>this._commandService.executeCommand(o.id,o.params)),(r=s(e||[],null))==null||r.forEach(o=>this._commandService.executeCommand(o.id,o.params))}};me=fe([C(3,l.Inject(l.Injector)),C(4,l.Inject(D)),C(5,l.Inject(a.UniverPermissionService)),C(6,l.Inject(_.CompressMutationService)),C(7,l.Inject(a.LocaleService)),C(8,l.Inject(_.RevisionService)),C(9,a.ILogService),C(10,a.ICommandService),C(11,$.IMessageService),C(12,l.Optional(de))],me);let Le=class extends me{constructor(i,t,e,s,n,r,o,c,h,u,v,g,I,p,b,O,M){super(i,t,e,s,n,r,o,c,h,p,b,O,M),this.unitID=i,this.type=t,this.session=e,this._docStateChangeManagerService=u,this._docTransformIMECacheService=v,this._docTransformSelectionsService=g,this._docSyncEditingCollabCursorService=I}_createHandler(){const i=super._createHandler();return i.onTransformIME=t=>this._docTransformIMECacheService.transformIMECache(t),i.onTransformSelections=t=>this._docTransformSelectionsService.transformSelections(t),i.onSyncEditingCollabCursor=t=>this._docSyncEditingCollabCursorService.syncEditingCollabCursor(t),i.onTransformRemoteChangesetByIMECache=t=>this._docTransformIMECacheService.transformRemoteChangeset(t),i}async _init(){const i=await super._init();return this._docStateChangeManagerService.docStateChange$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{if(t==null)return;const{unitId:e,redoState:s,commandId:n}=t;if(e!==this.unitID)return;const r={id:n,type:a.CommandType.MUTATION,params:{unitId:e,actions:s.actions,textRanges:null}};this._onLocalMutation(r)}),i}};Le=fe([C(3,l.Inject(l.Injector)),C(4,l.Inject(D)),C(5,l.Inject(a.UniverPermissionService)),C(6,l.Inject(_.CompressMutationService)),C(7,l.Inject(a.LocaleService)),C(8,l.Inject(_.RevisionService)),C(9,l.Inject(L.DocStateChangeManagerService)),C(10,l.Inject(ve)),C(11,l.Inject(Se)),C(12,l.Inject(Ue)),C(13,a.ILogService),C(14,a.ICommandService),C(15,$.IMessageService),C(16,l.Optional(de))],Le);let Ne=class extends me{constructor(i,t,e,s,n,r,o,c,h,u,v,g,I,p){super(i,t,e,s,n,r,o,c,h,v,g,I,p),this.unitID=i,this.type=t,this.session=e,this._sheetTransformSelectionsService=u}_createHandler(){const i=super._createHandler();return i.onTransformSelections=t=>this._sheetTransformSelectionsService.transformSelections(t),i}async _init(){const i=await super._init();return this.disposeWithMe(this._commandService.onCommandExecuted((t,e)=>{if(t.type!==a.CommandType.MUTATION||e!=null&&e.fromCollab||e!=null&&e.onlyLocal)return;const s=t.params;if((s==null?void 0:s.unitId)!==this.unitID)return;const n=t,r=this._compressMutationService.interceptor.fetchThroughInterceptors(this._compressMutationService.interceptor.getInterceptPoints().COMPRESS_MUTATION_SEND)([n],null)||[n];this._onLocalMutation(r[0])})),i}};Ne=fe([C(3,l.Inject(l.Injector)),C(4,l.Inject(D)),C(5,l.Inject(a.UniverPermissionService)),C(6,l.Inject(_.CompressMutationService)),C(7,l.Inject(a.LocaleService)),C(8,l.Inject(_.RevisionService)),C(9,l.Inject(ge)),C(10,a.ILogService),C(11,a.ICommandService),C(12,$.IMessageService),C(13,l.Optional(de))],Ne);const vt=["purple300","jiqing500","verdancy600","red300","blue400","gold400"];class Ae extends a.Disposable{constructor(){super(...arguments);d(this,"_assignedColors",new Map);d(this,"_colorIndex",0)}assignAColorForMemberID(e){if(this._assignedColors.has(e))return this._assignedColors.get(e);const s=vt[this._colorIndex];return this._colorIndex=(this._colorIndex+1)%vt.length,this._assignedColors.set(e,s),s}}var Jt=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},J=(i,t)=>(e,s)=>t(e,s,i);const Zt=300,Qt=100,es=()=>{let i=[],t=!1;return e=>{i.push(e),t||(t=!0,setTimeout(()=>{i.forEach(s=>s()),i=[],t=!1}))}};let ke=class extends a.RxDisposable{constructor(t,e,s,n,r,o,c,h){super();d(this,"_online",!1);d(this,"_init",!1);d(this,"_cursorInfo$",new f.BehaviorSubject(new Map));d(this,"cursorInfo$",this._cursorInfo$.asObservable());d(this,"_roomMembers$",new f.BehaviorSubject([]));d(this,"roomMembers$",this._roomMembers$.pipe(f.debounceTime(Zt)));d(this,"_updateLocalCursor",Oe((t,e)=>{const s={eventID:_.CollaborationEvent.UPDATE_CURSOR,data:{unitID:this.unitID,memberID:this._session.getMemberID(),selection:qe.serializeRangeWithSheet(t,e.range)}};this._session.send(s,this.unitID)},Qt));this.unitID=t,this._session=e,this._injector=s,this._colorAssignService=n,this._memberService=r,this._univerInstanceService=o,this._commandService=c,this._refRangeService=h}get cursorInfo(){return this._cursorInfo$.getValue()}get roomMembers(){return this._roomMembers$.getValue()}dispose(){super.dispose(),this._cursorInfo$.next(new Map),this._cursorInfo$.complete(),this._roomMembers$.next([]),this._roomMembers$.complete()}init(){this._init||(this._init=!0,this._session.sessionStatus$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{t===Y.ONLINE?this._toggleOnline():this._toggleOffline()}),this._session.event$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{const e=t.eventID;e===_.CollaborationEvent.UPDATE_CURSOR&&this._onCursorUpdate(t),e===_.CollaborationEvent.USERS_LEAVE&&this._onCursorDelete(t)}),this._onRefRangeChange(),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(this._online&&t.id===E.SetSelectionsOperation.id&&t.params.unitId===this.unitID){const e=t.params;this._updateLocalCursor(e.subUnitId,e.selections[0])}})))}_onCursorUpdate(t){var u,v;const{memberID:e,selection:s}=t.data,{sheetName:n,range:r}=qe.deserializeRangeWithSheet(s),c={name:(v=(u=this._memberService.getMember(this.unitID,e))==null?void 0:u.name)!=null?v:"Unknown user",range:this._getMergeRange(n,r),sheetID:n,color:this._colorAssignService.assignAColorForMemberID(e),selection:s},h=this.cursorInfo;h.set(e,c),this._cursorInfo$.next(h)}_onCursorDelete(t){const{memberID:e}=t.data,s=this.cursorInfo;s.delete(e),this._cursorInfo$.next(s)}_getMergeRange(t,e){var n,r;const s=(r=(n=this._univerInstanceService.getUniverSheetInstance(this.unitID))==null?void 0:n.getSheetBySheetId(t))==null?void 0:r.getMergeData();return(s==null?void 0:s.find(o=>a.Rectangle.contains(o,e)))||e}_onRefRangeChange(){const t=new a.DisposableCollection,e=es(),s=()=>{t.dispose();const n=(r,o,c,h)=>{let u=[];switch(r.id){case E.EffectRefRangId.DeleteRangeMoveLeftCommandId:{u=E.handleDeleteRangeMoveLeft(r,h);break}case E.EffectRefRangId.DeleteRangeMoveUpCommandId:{u=E.handleDeleteRangeMoveUp(r,h);break}case E.EffectRefRangId.InsertColCommandId:{u=E.handleInsertCol(r,h);break}case E.EffectRefRangId.InsertRangeMoveDownCommandId:{u=E.handleInsertRangeMoveDown(r,h);break}case E.EffectRefRangId.InsertRangeMoveRightCommandId:{u=E.handleInsertRangeMoveRight(r,h);break}case E.EffectRefRangId.InsertRowCommandId:{u=E.handleInsertRow(r,h);break}case E.EffectRefRangId.MoveRangeCommandId:{u=E.handleMoveRange(r,h);break}case E.EffectRefRangId.RemoveColCommandId:{u=E.handleIRemoveCol(r,h);break}case E.EffectRefRangId.RemoveRowCommandId:{u=E.handleIRemoveRow(r,h);break}}const v=E.runRefRangeMutations(u,h),g=this.cursorInfo.get(o);if(g&&v){const I={...g,range:v};this.cursorInfo.set(o,I),e(()=>{const p=this._refRangeService.registerRefRange(v,b=>(p.dispose(),n(b,o,c,v)));t.add(p)})}return{redos:[],undos:[]}};this.cursorInfo.forEach((r,o)=>{const{range:c,sheetID:h}=r,u=this._refRangeService.registerRefRange(c,v=>(u.dispose(),n(v,o,h,c)));t.add(u)})};this.disposeWithMe(a.toDisposable(this._cursorInfo$.subscribe(()=>{s()})))}_toggleOnline(){var s,n;if(this._online=!0,((s=this._univerInstanceService.getFocusedUnit())==null?void 0:s.getUnitId())!==this.unitID)return;const e=(n=this._injector.get(E.SelectionManagerService).getSelections())==null?void 0:n[0];e&&this._updateLocalCursor(this._univerInstanceService.getCurrentUnitForType(a.UniverInstanceType.UNIVER_SHEET).getActiveSheet().getSheetId(),e)}_toggleOffline(){this._online=!1}};ke=Jt([J(2,l.Inject(l.Injector)),J(3,l.Inject(Ae)),J(4,l.Inject(G)),J(5,a.IUniverInstanceService),J(6,a.ICommandService),J(7,l.Inject(E.RefRangeService))],ke);var ts=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},z=(i,t)=>(e,s)=>t(e,s,i);const ss=300,ns=100;let $e=class extends a.RxDisposable{constructor(t,e,s,n,r,o,c,h,u){super();d(this,"_online",!1);d(this,"_init",!1);d(this,"_cursorInfo$",new f.BehaviorSubject(new Map));d(this,"cursorInfo$",this._cursorInfo$.asObservable());d(this,"_roomMembers$",new f.BehaviorSubject([]));d(this,"roomMembers$",this._roomMembers$.pipe(f.debounceTime(ss)));d(this,"_updateLocalCursor",Oe(t=>{const e={eventID:_.CollaborationEvent.UPDATE_CURSOR,data:{unitID:this.unitID,memberID:this._session.getMemberID(),selection:lt(t)}};this._session.send(e,this.unitID)},ns));this.unitID=t,this._session=e,this._injector=s,this._colorAssignService=n,this._memberService=r,this._syncEditingCollabCursorService=o,this._transformService=c,this._univerInstanceService=h,this._commandService=u}get cursorInfo(){return this._cursorInfo$.getValue()}get roomMembers(){return this._roomMembers$.getValue()}dispose(){super.dispose(),this._cursorInfo$.next(new Map),this._cursorInfo$.complete(),this._roomMembers$.next([]),this._roomMembers$.complete()}init(){this._init||(this._init=!0,this._session.sessionStatus$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{t===Y.ONLINE?this._toggleOnline():this._toggleOffline()}),this._session.event$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{const e=t.eventID;e===_.CollaborationEvent.UPDATE_CURSOR&&this._onCursorUpdate(t),e===_.CollaborationEvent.USERS_LEAVE&&this._onCursorDelete(t)}),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{const e=t.params;e!=null&&this._online&&t.id===L.SetTextSelectionsOperation.id&&e.unitId===this.unitID&&e.isEditing===!1&&this._updateLocalCursor(e.ranges)})),this._syncEditingCollabCursorService.collabCursorState$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{if((t==null?void 0:t.unitID)!==this.unitID)return;const e={eventID:_.CollaborationEvent.UPDATE_CURSOR,data:t};this._onCursorUpdate(e)}),this.disposeWithMe(this._commandService.onCommandExecuted(t=>{if(t.params==null)return;const e=t.params;if(t.id!==L.RichTextEditingMutation.id||e.unitId!==this.unitID)return;const s={id:"doc.mutation.rich-text-editing",params:e},n=this.cursorInfo;for(const[r,o]of n){const c={id:"doc.mutation.rich-text-editing",params:{unitId:this.unitID,actions:[],textRanges:o.ranges}},h=this._transformService.transformMutation(s,c,!1);if(_.isTransformMutationFailure(h))throw h.error;n.set(r,{...o,ranges:h.m2Prime.params.textRanges})}queueMicrotask(()=>{this._cursorInfo$.next(n)})})))}_onCursorUpdate(t){var h,u;const{memberID:e,selection:s}=t.data,n=Gt(s),r=(u=(h=this._memberService.getMember(this.unitID,e))==null?void 0:h.name)!=null?u:"Unknown user",o={color:this._colorAssignService.assignAColorForMemberID(e),name:r,ranges:n},c=this.cursorInfo;c.set(e,o),this._cursorInfo$.next(c)}_onCursorDelete(t){const{memberID:e}=t.data,s=this.cursorInfo;s.delete(e),this._cursorInfo$.next(s)}_toggleOnline(){var n;if(this._online=!0,((n=this._univerInstanceService.getFocusedUnit())==null?void 0:n.getUnitId())!==this.unitID)return;const e=this._injector.get(L.TextSelectionManagerService).getSelections(),s=e==null?void 0:e.map(L.serializeTextRange);Array.isArray(s)&&s.length>0&&this._updateLocalCursor(s)}_toggleOffline(){this._online=!1}};$e=ts([z(2,l.Inject(l.Injector)),z(3,l.Inject(Ae)),z(4,l.Inject(G)),z(5,l.Inject(Ue)),z(6,_.ITransformService),z(7,a.IUniverInstanceService),z(8,a.ICommandService)],$e);var is=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},Pe=(i,t)=>(e,s)=>t(e,s,i);let Z=class extends a.RxDisposable{constructor(t,e,s){super();d(this,"_entities",new Map);d(this,"_entityInit$",new f.Subject);this._univerInstanceService=t,this._injector=e,this._collabSessionService=s,this._init()}dispose(){super.dispose(),this._entityInit$.complete(),this._entities.forEach(t=>t.dispose())}getCollabCursors$(t){return this._entities.has(t)?this._entities.get(t).cursorInfo$:this._entityInit$.pipe(f.filter(e=>e.unitID===t),f.switchMap(e=>e.cursorInfo$))}_init(){this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_SHEET).pipe(f.takeUntil(this.dispose$)).subscribe(async t=>{const e=t.getUnitId(),s=await this._startSheetCollabCursor(e);this._entityInit$.next(s),this._entities.set(e,s)}),this._univerInstanceService.getTypeOfUnitAdded$(a.UniverInstanceType.UNIVER_DOC).pipe(f.takeUntil(this.dispose$)).pipe(f.filter(t=>!t.getUnitId().startsWith("__"))).subscribe(async t=>{const e=t.getUnitId(),s=await this._startDocCollabCursor(e);this._entityInit$.next(s),this._entities.set(e,s)}),f.merge(this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_DOC),this._univerInstanceService.getTypeOfUnitDisposed$(a.UniverInstanceType.UNIVER_SHEET)).pipe(f.takeUntil(this.dispose$)).subscribe(t=>{const e=t.getUnitId(),s=this._entities.get(e);s&&(s.dispose(),this._entities.delete(e))})}async _startSheetCollabCursor(t){const e=await this._collabSessionService.requireSession(t),s=this._injector.createInstance(ke,t,e);return s.init(),s}async _startDocCollabCursor(t){const e=await this._collabSessionService.requireSession(t),s=this._injector.createInstance($e,t,e);return s.init(),s}};Z=is([a.OnLifecycle(a.LifecycleStages.Starting,Z),Pe(0,a.IUniverInstanceService),Pe(1,l.Inject(l.Injector)),Pe(2,l.Inject(S.CollaborationSessionService))],Z);const ie=20,St=200,je=4,rs=5;function os(i,t){let{radius:e,width:s,height:n}=t;e=e!=null?e:0,s=s!=null?s:30,n=n!=null?n:30;let r=0,o=0,c=0;r=o=c=Math.min(e,s/2,n/2),i.beginPath(),i.moveTo(r,0),i.lineTo(s-o,0),i.arc(s-o,o,o,Math.PI*3/2,0,!1),i.lineTo(s,n-c),i.arc(s-c,n-c,c,0,Math.PI/2,!1),i.lineTo(0,n),i.lineTo(0,r),i.arc(r,r,r,Math.PI,Math.PI*3/2,!1),i.closePath(),t.fill&&(i.save(),i.fillStyle=t.fill,t.fillRule==="evenodd"?i.fill("evenodd"):i.fill(),i.restore())}class Ie extends y.Shape{constructor(e,s){super(e,s);d(this,"color");d(this,"text");this.color=s==null?void 0:s.color,this.text=s==null?void 0:s.text}static drawWith(e,s){const{text:n,color:r}=s;e.save(),e.font="bold 13px Source Han Sans CN";const o=e.measureText(n).width,c=Math.min(o+2*je,St);os(e,{height:ie,radius:4,width:c,fill:r,evented:!1}),e.fillStyle="#FFF";const h=je,u=ie-rs,v=St-2*je;if(o>v){let g="",I=0;for(const p of n){const b=e.measureText(p).width;if(I+b<=v-e.measureText("...").width)g+=p,I+=b;else{g+="...";break}}e.fillText(g,h,u)}else e.fillText(n,h,u);e.restore()}_draw(e){Ie.drawWith(e,this)}}const as=1,cs=1.5;class hs extends y.Shape{constructor(e,s){super(e,s);d(this,"_color");d(this,"_hovered",!1);d(this,"_range");d(this,"_name","");d(this,"_labelPosition","top");s&&this.setShapeProps(s),this.onPointerEnterObserver.add(()=>this.setShapeProps({hovered:!0})),this.onPointerLeaveObserver.add(()=>this.setShapeProps({hovered:!1}))}setShapeProps(e){var s,n,r,o,c;this._color=(s=e.color)!=null?s:this._color,this._hovered=(n=e.hovered)!=null?n:this._hovered,this._range=(r=e.range)!=null?r:this._range,this._name=(o=e.name)!=null?o:this._name,this._labelPosition=(c=e.labelPosition)!=null?c:this._labelPosition,this.transformByState({width:e.width,height:e.height})}onMouseMove(e){const{row:s,column:n}=e;if(s>=this._range.startRow&&s<=this._range.endRow&&n>=this._range.startColumn&&n<=this._range.endColumn){this.setShapeProps({hovered:!0});return}this.setShapeProps({hovered:!1})}triggerDblclick(e){return!1}_draw(e){y.Rect.drawWith(e,{width:this.width,height:this.height,strokeWidth:cs,stroke:this._color,evented:!1}),this._hovered&&(e.save(),e.transform(1,0,0,1,this.width,this._labelPosition==="bottom"?0:-ie),Ie.drawWith(e,{text:this._name,color:this._color}),e.restore())}}var ls=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},re=(i,t)=>(e,s)=>t(e,s,i);let Ce=class extends a.RxDisposable{constructor(t,e,s,n,r){super();d(this,"_cursors",new Set);d(this,"_lastPointer",null);this._collabCursorController=t,this._univerInstanceService=e,this._renderManagerService=s,this._sheetSkeletonManagerService=n,this._themeService=r,this._init()}_init(){this._sheetSkeletonManagerService.currentSkeleton$.pipe(R.takeUntil(this.dispose$),R.switchMap(t=>{if(t){const e=t.sheetId;return f.combineLatest(this._collabCursorController.getCollabCursors$(t.unitId),this._themeService.currentTheme$).pipe(R.map(([s,n])=>{const r=new Map;return s.forEach((o,c)=>{if(o.sheetID===e){const h={...o};h.color=n[o.color],r.set(c,h)}}),{skeleton:t,cursors:r}}))}return f.of({skeleton:null,cursors:new Map})})).subscribe(({skeleton:t,cursors:e})=>{this._removeCollabCursors(),t&&this._updateCollabCursors(t,e)}),this._sheetSkeletonManagerService.currentSkeleton$.subscribe(t=>{if(t==null)return;const{unitId:e,skeleton:s}=t,n=this._renderManagerService.getRenderById(e);if(n==null)return;const{scene:r}=n;r.onPointerMoveObserver.add(Oe(o=>{var M,W;const{offsetX:c,offsetY:h}=o,{x:u,y:v}=r.getRelativeCoord(y.Vector2.FromArray([c,h])),{scaleX:g,scaleY:I}=r.getAncestorScale(),p=r.getViewport(ee.VIEWPORT_KEY.VIEW_MAIN),b=r.getScrollXYByRelativeCoords(y.Vector2.FromArray([u,v]),p),O=s.getCellPositionByOffset(c,h,g,I,b);((M=this._lastPointer)==null?void 0:M.column)===O.column&&((W=this._lastPointer)==null?void 0:W.row)===O.row||this._cursors.forEach(le=>{le.onMouseMove(O)})},100))})}_updateCollabCursors(t,e){var c;const s=(c=this._sheetSkeletonManagerService.getCurrent())==null?void 0:c.skeleton;if(!s)return;const n=this._getSheetObject();if(!n)return;this._cursors.forEach(h=>{h.makeDirty()});const{scene:r}=n,o=us(Array.from(e.values())).map(h=>{const{color:u,range:v,name:g,selection:I,sheetID:p}=h,{startColumn:b,startRow:O,endColumn:M,endRow:W}=v,le=ee.getCoordByCell(O,b,r,s),Ye=ee.getCoordByCell(W,M,r,s),{columnHeaderHeightAndMarginTop:ue}=s,{startX:_e,startY:Ke}=le,{endX:xs,endY:Vs}=Ye,Fs=xs-_e,Ws=Vs-Ke,Gs={labelPosition:Ke-ue>=ie?"top":"bottom",sheetID:p,range:v,color:u,name:g,selection:I,left:_e,top:Ke,width:Fs,height:Ws,evented:!1};return new hs(g,Gs)});r.addObjects(o,as),this._cursors=new Set(o)}_removeCollabCursors(){var t;(t=this._cursors)==null||t.forEach(e=>e.dispose())}_getSheetObject(){return ee.getSheetObject(this._univerInstanceService,this._renderManagerService)}};Ce=ls([a.OnLifecycle(a.LifecycleStages.Steady,Ce),re(0,l.Inject(Z)),re(1,a.IUniverInstanceService),re(2,y.IRenderManagerService),re(3,l.Inject(ee.SheetSkeletonManagerService)),re(4,l.Inject(a.ThemeService))],Ce);function us(i){const t=new Map;return i.forEach(e=>{if(t.has(e.selection)){const s=t.get(e.selection);s.name+=`, ${e.name}`}else t.set(e.selection,e)}),Array.from(t.values())}var A=function(){return A=Object.assign||function(i){for(var t,e=1,s=arguments.length;e<s;e++){t=arguments[e];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(i[n]=t[n])}return i},A.apply(this,arguments)},_s=function(i,t){var e={};for(var s in i)Object.prototype.hasOwnProperty.call(i,s)&&t.indexOf(s)<0&&(e[s]=i[s]);if(i!=null&&typeof Object.getOwnPropertySymbols=="function")for(var n=0,s=Object.getOwnPropertySymbols(i);n<s.length;n++)t.indexOf(s[n])<0&&Object.prototype.propertyIsEnumerable.call(i,s[n])&&(e[s[n]]=i[s[n]]);return e},He=U.forwardRef(function(i,t){var e=i.icon,s=i.id,n=i.className,r=i.extend,o=_s(i,["icon","id","className","extend"]),c="univerjs-icon univerjs-icon-".concat(s," ").concat(n||"").trim(),h=U.useRef("_".concat(Ss()));return gt(e,"".concat(s),{defIds:e.defIds,idSuffix:h.current},A({ref:t,className:c},o),r)});function gt(i,t,e,s,n){return U.createElement(i.tag,A(A({key:t},ds(i,e,n)),s),(vs(i,e).children||[]).map(function(r,o){return gt(r,"".concat(t,"-").concat(i.tag,"-").concat(o),e,void 0,n)}))}function ds(i,t,e){var s=A({},i.attrs);e!=null&&e.colorChannel1&&s.fill==="colorChannel1"&&(s.fill=e.colorChannel1);var n=t.defIds;return!n||n.length===0||(i.tag==="use"&&s["xlink:href"]&&(s["xlink:href"]=s["xlink:href"]+t.idSuffix),Object.entries(s).forEach(function(r){var o=r[0],c=r[1];typeof c=="string"&&(s[o]=c.replace(/url\(#(.*)\)/,"url(#$1".concat(t.idSuffix,")")))})),s}function vs(i,t){var e,s=t.defIds;return!s||s.length===0?i:i.tag==="defs"&&(!((e=i.children)===null||e===void 0)&&e.length)?A(A({},i),{children:i.children.map(function(n){return typeof n.attrs.id=="string"&&s&&s.indexOf(n.attrs.id)>-1?A(A({},n),{attrs:A(A({},n.attrs),{id:n.attrs.id+t.idSuffix})}):n})}):i}function Ss(){return Math.random().toString(36).substring(2,8)}He.displayName="UniverIcon";var gs={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_585",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_102_585)"},children:[{tag:"path",attrs:{d:"M8.00011 11.7216C7.64665 11.7216 7.36011 11.435 7.36011 11.0816V2.76158C7.36011 2.40812 7.64665 2.12158 8.00011 2.12158 8.35357 2.12158 8.64011 2.40812 8.64011 2.76158V11.0816C8.64011 11.435 8.35357 11.7216 8.00011 11.7216zM8.00008 13.8783C8.46032 13.8783 8.83342 13.5052 8.83342 13.045 8.83342 12.5847 8.46032 12.2116 8.00008 12.2116 7.53985 12.2116 7.16675 12.5847 7.16675 13.045 7.16675 13.5052 7.53985 13.8783 8.00008 13.8783zM9.43991 3.3083V4.6566C11.1747 4.93531 12.8439 5.72115 14.2082 7.01405 14.4754 7.26731 14.8974 7.25598 15.1506 6.98873 15.4039 6.72149 15.3926 6.29953 15.1253 6.04626 13.5035 4.50928 11.5069 3.59665 9.43991 3.3083zM2.3565 6.52137C3.60481 5.51948 5.05771 4.89789 6.55991 4.65657V3.30842C4.7603 3.55961 3.014 4.284 1.52191 5.48155 1.3003 5.65943 1.08439 5.84768.874838 6.04627.607592 6.29953.59626 6.72149.849526 6.98873 1.10279 7.25598 1.52475 7.26731 1.79199 7.01405 1.97498 6.84063 2.16333 6.67643 2.3565 6.52137zM2.86201 8.33667C3.91262 7.28606 5.2049 6.62442 6.55991 6.35175V7.71826C5.55037 7.96981 4.59408 8.49022 3.80482 9.27947 3.54447 9.53982 3.12236 9.53982 2.86201 9.27947 2.60166 9.01912 2.60166 8.59701 2.86201 8.33667zM9.43991 7.71818V6.35169C10.795 6.62431 12.0875 7.28597 13.1382 8.33667 13.3985 8.59701 13.3985 9.01912 13.1382 9.27947 12.8778 9.53982 12.4557 9.53982 12.1953 9.27947 11.406 8.49013 10.4496 7.9697 9.43991 7.71818zM4.86201 10.5082C5.35689 10.0134 5.93957 9.65979 6.55991 9.44753V10.8951C6.28821 11.0374 6.03315 11.2227 5.80482 11.451 5.54447 11.7114 5.12236 11.7114 4.86201 11.451 4.60166 11.1907 4.60166 10.7686 4.86201 10.5082zM9.43991 10.8949V9.44741C10.0604 9.65966 10.6432 10.0133 11.1382 10.5082 11.3985 10.7686 11.3985 11.1907 11.1382 11.451 10.8778 11.7114 10.4557 11.7114 10.1953 11.451 9.96691 11.2226 9.71174 11.0372 9.43991 10.8949z"}}]}]},ft=U.forwardRef(function(i,t){return U.createElement(He,Object.assign({},i,{id:"off-line-single",ref:t,icon:gs}))});ft.displayName="OffLineSingle";var fs={tag:"svg",attrs:{fill:"none",viewBox:"0 0 16 16",width:"1em",height:"1em"},children:[{tag:"mask",attrs:{id:"mask0_102_580",style:{maskType:"alpha"},width:16,height:16,x:0,y:0,maskUnits:"userSpaceOnUse"},children:[{tag:"path",attrs:{fill:"#D9D9D9",d:"M0 0H16V16H0z"}}]},{tag:"g",attrs:{fill:"currentColor",mask:"url(#mask0_102_580)",fillRule:"evenodd",clipRule:"evenodd"},children:[{tag:"path",attrs:{d:"M5.82613 4.56746C5.40036 5.04236 5.18674 5.65314 5.02643 6.21425C4.94606 6.49553 4.68897 6.68945 4.39644 6.68945C4.17409 6.68945 3.56092 6.78651 3.0238 7.12221C2.52284 7.43531 2.10324 7.93892 2.10324 8.81885C2.10324 9.60442 2.39454 10.0131 2.72844 10.2503C3.09823 10.5131 3.60322 10.6206 4.06884 10.6206C4.43069 10.6206 4.72404 10.914 4.72404 11.2758C4.72404 11.6377 4.43069 11.931 4.06884 11.931C3.44246 11.931 2.63705 11.7929 1.96945 11.3185C1.26595 10.8187 0.792847 9.99887 0.792847 8.81885C0.792847 7.40558 1.51984 6.5169 2.32929 6.011C2.8676 5.67455 3.44845 5.50028 3.89776 5.42544C4.07573 4.89085 4.35413 4.2463 4.85044 3.69271C5.51609 2.95026 6.5174 2.43066 8.00003 2.43066C9.27898 2.43066 10.2502 2.7993 10.9548 3.3781C11.5184 3.84106 11.881 4.41324 12.1008 4.9709C12.1429 4.98097 12.1875 4.99222 12.2342 5.00477C12.549 5.08928 12.9754 5.23648 13.408 5.48878C14.2932 6.00515 15.2072 6.97409 15.2072 8.65505C15.2072 9.79541 14.8194 10.6501 14.1525 11.2059C13.5065 11.7442 12.6838 11.931 11.9312 11.931C11.5694 11.931 11.276 11.6377 11.276 11.2758C11.276 10.914 11.5694 10.6206 11.9312 10.6206C12.4891 10.6206 12.9767 10.4799 13.3136 10.1992C13.6294 9.93602 13.8968 9.48028 13.8968 8.65505C13.8968 7.55142 13.3367 6.96426 12.7477 6.62068C12.4431 6.443 12.1325 6.33426 11.8944 6.27034C11.7766 6.23871 11.6799 6.21893 11.6151 6.20737C11.5828 6.2016 11.5587 6.19792 11.5442 6.19585L11.53 6.19391L11.5302 6.19393L11.5307 6.19398C11.2667 6.16442 11.0466 5.97834 10.9736 5.72285C10.8382 5.24885 10.5726 4.75996 10.123 4.39067C9.68107 4.02762 9.01427 3.74106 8.00003 3.74106C6.86186 3.74106 6.22518 4.12236 5.82613 4.56746ZM11.53 6.19391L11.5294 6.19384L11.5286 6.19374C11.5284 6.19372 11.5288 6.19377 11.53 6.19391Z"}},{tag:"path",attrs:{d:"M11.0302 9.12626C11.3127 9.35231 11.3585 9.76463 11.1325 10.0472L8.51171 13.3232C8.40173 13.4606 8.24107 13.5481 8.06592 13.5658C7.89077 13.5835 7.71587 13.5299 7.58063 13.4172L5.61504 11.7792C5.33705 11.5476 5.2995 11.1344 5.53115 10.8564C5.7628 10.5785 6.17595 10.5409 6.45393 10.7725L7.90602 11.9826L10.1093 9.22859C10.3353 8.94603 10.7476 8.90021 11.0302 9.12626Z"}}]}]},mt=U.forwardRef(function(i,t){return U.createElement(He,Object.assign({},i,{id:"on-line-single",ref:t,icon:fs}))});mt.displayName="OnLineSingle";const oe={onlineStatusIcon:"univer-online-status-icon",onlineStatusTitle:"univer-online-status-title",onlineStatus:"univer-online-status",online:"univer-online",offline:"univer-offline"};function ms(i){switch(i){case w.OFFLINE:return"collabStatus.offline";case w.CONFLICT:return"collabStatus.conflict";case w.FETCH_MISS:return"collabStatus.fetchMiss";case w.NOT_COLLAB:return"collabStatus.notCollab";case w.PENDING:case w.AWAITING:case w.AWAITING_WITH_PENDING:return"collabStatus.syncing";case w.SYNCED:return"collabStatus.synced"}}function Is(i){const t=$.useObservable(i.status$,w.NOT_COLLAB),e=Xe.useDependency(a.LocaleService),s=t!==w.OFFLINE,n=e.t(ms(t)),r=yt(oe.onlineStatus,{[oe.online]:s,[oe.offline]:!s}),o=s?U.createElement(mt,null):U.createElement(ft,null);return U.createElement("div",{className:r},U.createElement("div",{className:oe.onlineStatusIcon},o),U.createElement("div",{className:oe.onlineStatusTitle},n))}var Cs=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},pe=(i,t)=>(e,s)=>t(e,s,i);let Ee=class extends a.Disposable{constructor(t,e,s,n){super();d(this,"_status$",new f.BehaviorSubject(w.NOT_COLLAB));this._uiController=t,this._univerInstanceService=e,this._injector=s,this._collaborationController=n,this._mountOnlineHint(),this._initStatusListener()}_mountOnlineHint(){this.disposeWithMe(this._uiController.registerComponent($.DesktopUIPart.HEADER_MENU,()=>Xe.connectInjector(ps({status$:this._status$.asObservable()}),this._injector)))}_initStatusListener(){this.disposeWithMe(a.toDisposable(this._univerInstanceService.focused$.pipe(f.switchMap(()=>{const t=this._univerInstanceService.getFocusedUnit();return t?this._collaborationController.getCollabEntity$(t.getUnitId()):f.of(null)}),f.switchMap(t=>t?t.status$:f.of(w.NOT_COLLAB))).subscribe(t=>{this._status$.next(t)})))}};Ee=Cs([a.OnLifecycle(a.LifecycleStages.Starting,Ee),pe(0,$.IUIController),pe(1,a.IUniverInstanceService),pe(2,l.Inject(l.Injector)),pe(3,l.Inject(S.CollaborationController))],Ee);function ps(i){const{status$:t}=i;return function(){return U.createElement(Is,{status$:t})}}const It=l.createIdentifier("uni.network.url-service");var Es=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},Q=(i,t)=>(e,s)=>t(e,s,i);let ae=class extends a.RxDisposable{constructor(i,t,e,s,n,r){super(),this._urlService=i,this._logService=t,this._commandService=e,this._localCacheService=s,this._snapshotService=n,r?r==null||r.whenReady().then(()=>this._init()):(this._logService.debug("[DataLoaderController]","No remote instance service injected. May not syncing edits to the web worker."),this._init())}async _init(){const i=this._urlService.getParam("unit"),t=this._urlService.getParam("type");if(!i||!t){this._logService.debug("[DataLoaderController]","No unitID or type in URL. Will not load files from remote address.");return}switch(Number(t)){case j.UNIVER_SHEET:{const e=await this._loadSheet(i);this._setupSubUnitSync(e);break}case j.UNIVER_DOC:{await this._loadDoc(i);break}default:{this._logService.error("[DataLoaderController]","Unknown type in URL. Will not load files from remote address.");break}}}async _setupSubUnitSync(i){await this._updateSubUnitFromURLParams(i),i.activeSheet$.pipe(f.takeUntil(this.dispose$)).subscribe(t=>{t&&this._updateURLWithCurrentState(t)}),this._urlService.urlChange$.pipe(f.takeUntil(this.dispose$)).subscribe(()=>this._updateSubUnitFromURLParams(i))}_updateURLWithCurrentState(i,t=!1){const e=this._urlService.getParam("subunit");i.getSheetId()!==e&&this._urlService.setParam("subunit",i.getSheetId(),t)}async _updateSubUnitFromURLParams(i){const t=this._urlService.getParam("subunit");if(!t||!i.getSheetBySheetId(t)){this._updateURLWithCurrentState(i.getActiveSheet(),!0);return}i.getActiveSheet().getSheetId()!==t&&await this._commandService.executeCommand(E.SetWorksheetActivateCommand.id,{unitId:i.getUnitId(),subUnitId:t})}async _loadSheet(i){let t=0;const e=await this._localCacheService.loadOfflineData(i);return e&&(e.awaitingChangeset||e.mutations.length!==0)&&(t=e.rev),t===0&&this._logService.debug("[DataLoaderController]","fetching the latest document from the server."),this._snapshotService.loadSheet(i,t)}async _loadDoc(i){let t=0;const e=await this._localCacheService.loadOfflineData(i);return e&&(e.awaitingChangeset||e.mutations.length!==0)&&(t=e.rev),t===0&&this._logService.debug("[DataLoaderController]","fetching the latest document from the server."),this._snapshotService.loadDoc(i,t)}};ae=Es([a.OnLifecycle(a.LifecycleStages.Starting,ae),Q(0,It),Q(1,a.ILogService),Q(2,a.ICommandService),Q(3,l.Inject(D)),Q(4,l.Inject(_.SnapshotService)),Q(5,l.Optional(Ot.IRemoteInstanceService))],ae);var bs=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},Ct=(i,t)=>(e,s)=>t(e,s,i);const Ts="DEFAULT_FILE_NAME",Rs="Univer";let be=class extends a.Disposable{constructor(i,t){super(),this._univerInstanceService=i,this._configService=t,this._init()}_init(){this.disposeWithMe(a.toDisposable(this._univerInstanceService.focused$.subscribe(()=>{var e;const i=this._univerInstanceService.getFocusedUnit();let t=(e=this._configService.getConfig(Ts))!=null?e:Rs;i instanceof a.Workbook&&(t=i.name),document.title=t})))}};be=bs([a.OnLifecycle(a.LifecycleStages.Ready,be),Ct(0,a.IUniverInstanceService),Ct(1,a.IConfigService)],be);const pt={collabStatus:{fetchMiss:"正在同步服务端数据...",conflict:"编辑冲突",notCollab:"本地文件",synced:"已保存",syncing:"保存中...",offline:"编辑将在本地保存"},session:{"connection-failed":"连接失败,请检查你的网络","will-retry":"连接失败,将在一会儿之后重试","room-full":"协同房间已满,你的编辑将在本地保存","collaboration-timeout":"服务器未响应你的协同请求,你的编辑将在本地保存"},conflict:{title:"协同冲突",content:"你的本地文档和服务器的文档存在冲突。请在别处保存你的本地编辑,本地编辑将在刷新页面后丢弃。"},collaboration:{"single-unit":{warning:"你在另一个标签页打开了同一个文件。为了避免数据丢失,这个标签页的编辑行为将会被限制。"}},auth:{needGotoLoginAlert:"你的登录已过期,点击确认重新登陆,点击取消去保存你的本地编辑。"}};var ys=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},Et=(i,t)=>(e,s)=>t(e,s,i);const bt="SNAPSHOT_SERVER_URL_KEY",Os="/universer-api/snapshot";let Be=class{constructor(i,t){this._configService=i,this._httpService=t}async getUnitOnRev(i,t){var v;const{unitID:e,type:s,revision:n=0}=t,o=`${this._getAPIPrefixPath()}/${s}/unit/${e}/rev/${n===1?0:n}`,h=(await this._httpService.get(o)).body,u=(v=h.snapshot)==null?void 0:v.workbook;if(u){const g=u==null?void 0:u.originalMeta,I=a.textEncoder.encode(a.b64DecodeUnicode(g));u.originalMeta=I,Object.entries(u.sheets).forEach(([,p])=>{const b=p.originalMeta,O=a.textEncoder.encode(a.b64DecodeUnicode(b));p.originalMeta=O})}return h}async getSheetBlock(i,t){const{unitID:e,type:s,blockID:n}=t,o=`${this._getAPIPrefixPath()}/${s}/unit/${e}/block/${n}`;return(await this._httpService.get(o)).body}async fetchMissingChangesets(i,t){const{unitID:e,type:s,from:n,to:r}=t,c=`${this._getAPIPrefixPath()}/${s}/unit/${e}/fetchmissing?from=${n}&to=${r}`;return(await this._httpService.get(c)).body}_getAPIPrefixPath(){var i;return(i=this._configService.getConfig(bt))!=null?i:Os}async getResourcesRequest(i,t){const e=`/universer-api/snapshot/${t.type}/unit/${t.unitID}/resources`;return(await this._httpService.get(e,{params:{resourceId:JSON.stringify(t.resourceIDs)}})).body}saveSnapshot(){throw new Error("This method should not be called on the client side!")}saveSheetBlock(){throw new Error("This method should not be called on the client side!")}saveChangeset(){throw new Error("This method should not be called on the client side!")}};Be=ys([Et(0,a.IConfigService),Et(1,l.Inject(P.HTTPService))],Be);var Ms=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},ce=(i,t)=>(e,s)=>t(e,s,i);let xe=class extends a.LocalUndoRedoService{constructor(i,t,e,s,n){super(i,t,e),this._transformService=s,this._logService=n}transformUndoRedo(i,t){const e=this._getUndoStack(i);if(e)try{const n=this._transformStack(e,t);this._substituteUndoStack(i,n)}catch(n){this._logService.error("[CollaborationUndoRedoService]",n),this._clearUndo(i)}const s=this._getRedoStack(i);if(s)try{const n=this._transformStack(s,t);this._substituteRedoStack(i,n)}catch(n){this._logService.error(n),this._clearRedo(i)}}_clearUndo(i){const t=this._getUndoStack(i);t&&(t.length=0,this._updateStatus())}_clearRedo(i){const t=this._getRedoStack(i);t&&(t.length=0,this._updateStatus())}_substituteUndoStack(i,t){this._undoStacks.set(i,t),this._updateStatus()}_substituteRedoStack(i,t){this._redoStacks.set(i,t),this._updateStatus()}_transformStack(i,t){const e=[];let s=t,n=t;for(let r=i.length-1;r>=0;r--){const{unitID:o,undoMutations:c,redoMutations:h}=i[r],u=this._transformService.transformMutationsWithChangeset(s,c),v=this._transformService.transformMutationsWithChangeset(n,h);if(_.isTransformMutationsWithChangesetFailure(u)||_.isTransformMutationsWithChangesetFailure(v)){this._logService.error("[CollaborationUndoRedoService]","transformStack failed!",u,v);break}s=u.c1Prime,n=v.c1Prime,e.push({unitID:o,undoMutations:u.m2Prime,redoMutations:v.m2Prime})}return e.reverse()}};xe=Ms([ce(0,a.IUniverInstanceService),ce(1,a.ICommandService),ce(2,a.IContextService),ce(3,_.ITransformService),ce(4,a.ILogService)],xe);class Ds extends a.RxDisposable{constructor(){super();d(this,"urlChange$");this.urlChange$=f.fromEvent(window,"popstate").pipe(f.takeUntil(this.dispose$),f.shareReplay(1),f.mapTo(void 0))}setParam(e,s,n=!1){const r=new URL(window.location.href);r.searchParams.set(e,s),n?window.history.replaceState("","",r.toString()):window.history.pushState("","",r.toString())}removeParam(e,s=!1){const n=new URL(window.location.href);n.searchParams.delete(e),s?window.history.replaceState("","",n.toString()):window.history.pushState("","",n.toString())}getParam(e){var n;return(n=new URL(window.location.href).searchParams.get(e))!=null?n:void 0}}const Ve="collab-text-anchor-",ws="collab-text-range-",Te=6,Us=1.5,Fe=4,Ls=1.5,Ns="rgba(255, 255, 255, 0.01)";class As{constructor(t,e,s,n){d(this,"_shapes",[]);d(this,"_anchor",null);d(this,"_textBubble",null);d(this,"_anchorDot",null);d(this,"_hideTimer",null);d(this,"_eventUnsubscribe",null);this._cursor=t,this._scene=e,this._docSkeleton=s,this._document=n,this._render()}set _hover(t){t?(this._anchorDot&&this._anchorDot.hide(),this._textBubble&&this._textBubble.show()):(this._anchorDot&&this._anchorDot.show(),this._textBubble&&this._textBubble.hide())}dispose(){for(const t of this._shapes)t.dispose();this._textBubble&&this._textBubble.dispose(),this._anchorDot&&this._anchorDot.dispose(),this._anchor&&this._anchor.dispose(),this._eventUnsubscribe&&this._eventUnsubscribe()}_render(){const{_docSkeleton:t,_document:e}=this,{color:s,name:n,ranges:r}=this._cursor,o=e.getOffsetConfig(),{docsLeft:c,docsTop:h}=o,u=new y.NodePositionConvertToCursor(o,t);for(const{startOffset:v,endOffset:g,collapsed:I,isActive:p}of r){const b=t.findNodePositionByCharIndex(v),O=t.findNodePositionByCharIndex(g);if(p){const{contentBoxPointGroup:M}=u.getRangePointData(O,O);if(M.length===0)continue;this._drawAnchor(s,M,c,h,n),this._eventUnsubscribe=this._handleHover()}if(!I){const{contentBoxPointGroup:M}=u.getRangePointData(b,O);if(M.length===0)continue;this._drawRange(s,M,c,h)}}}_drawAnchor(t,e,s,n,r){const o=this._getAnchorBounding(e),{left:c,top:h,height:u}=o,v=this._getScale(),g=Ls/v,I=new y.Rect(Ve+a.Tools.generateRandomId(Te),{left:c+s-g,top:h+n,height:u,width:Us,fill:t||y.getColor(a.COLORS.black,0),strokeWidth:g,stroke:Ns,evented:!0});this._anchor=I,this._scene.addObject(I,y.TEXT_RANGE_LAYER_INDEX);const p=new y.Rect(Ve+a.Tools.generateRandomId(Te),{left:c+s-g,top:h+n-Fe/2,height:Fe,width:Fe,fill:t||y.getColor(a.COLORS.black,0),strokeWidth:0,stroke:t||y.getColor(a.COLORS.black,0),evented:!1});this._anchorDot=p,this._scene.addObject(p,y.TEXT_RANGE_LAYER_INDEX);const b=new Ie(Ve+a.Tools.generateRandomId(Te),{left:c+s-g,top:h+n-ie,text:r,color:t});this._textBubble=b,this._scene.addObject(b,y.TEXT_RANGE_LAYER_INDEX),this._hover=!1}_handleHover(){const t=this._anchor.onPointerEnterObserver.add(()=>{this._hover=!0}),e=this._anchor.onPointerLeaveObserver.add(()=>{this._hideTimer&&clearTimeout(this._hideTimer),this._hideTimer=setTimeout(()=>{this._hover=!1},2e3)});return()=>{var s,n;(s=this._anchor)==null||s.onPointerEnterObserver.remove(t),(n=this._anchor)==null||n.onPointerLeaveObserver.remove(e)}}_drawRange(t,e,s,n){const o=new a.ColorKit(t).setAlpha(.2).toRgbString(),c=new y.RegularPolygon(ws+a.Tools.generateRandomId(Te),{pointsGroup:e,fill:o||y.getColor(a.COLORS.black,.2),left:s,top:n,evented:!1,debounceParentDirty:!1});this._shapes.push(c),this._scene.addObject(c,y.TEXT_RANGE_LAYER_INDEX)}_getAnchorBounding(t){const e=t[0],s=e[0],n=e[2],{x:r,y:o}=s,{x:c,y:h}=n;return{left:r,top:o,width:c-r,height:h-o}}_getScale(){const{scaleX:t,scaleY:e}=this._scene.getAncestorScale();return Math.max(t,e)}}var ks=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},he=(i,t)=>(e,s)=>t(e,s,i);let Re=class extends a.RxDisposable{constructor(t,e,s,n,r){super();d(this,"_cursors",[]);this._collabCursorController=t,this._univerInstanceService=e,this._renderManagerService=s,this._docSkeletonManagerService=n,this._themeService=r,this._init()}_init(){this._docSkeletonManagerService.currentSkeleton$.pipe(R.takeUntil(this.dispose$),R.switchMap(t=>{if(t){const{unitId:e}=t;return f.combineLatest(this._collabCursorController.getCollabCursors$(e),this._themeService.currentTheme$).pipe(R.map(([s,n])=>({skeleton:t,cursors:[...s.values()].flatMap(r=>({...r,color:n[r.color]}))})))}return f.of({skeleton:null,cursors:[]})})).subscribe(({skeleton:t,cursors:e})=>{this._removeCollabCursors(),t&&this._updateCollabCursors(t.skeleton,e)})}_updateCollabCursors(t,e){const s=this._getDocObject();if(s==null)return;const{scene:n,document:r}=s,o=e.map(c=>new As(c,n,t,r));this._cursors=o}_removeCollabCursors(){this._cursors.forEach(t=>t.dispose()),this._cursors=[]}_getDocObject(){return L.getDocObject(this._univerInstanceService,this._renderManagerService)}};Re=ks([a.OnLifecycle(a.LifecycleStages.Steady,Re),he(0,l.Inject(Z)),he(1,a.IUniverInstanceService),he(2,y.IRenderManagerService),he(3,l.Inject(L.DocSkeletonManagerService)),he(4,l.Inject(a.ThemeService))],Re);var $s=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},We=(i,t)=>(e,s)=>t(e,s,i);const Tt="LOGIN_URL_KEY",Ps="/universer-api/oidc/authpage";let ye=class{constructor(i,t,e){this._configService=i,this._httpService=t,this.localeService=e,this.init()}init(){this._httpService.registerHTTPInterceptor({priority:1,interceptor:(i,t)=>t(i).pipe(f.concatMap(async e=>{if(e.status===401&&window.confirm(this.localeService.t("auth.needGotoLoginAlert"))){const n=window.encodeURIComponent(window.location.href);window.location.href=`${this._getLoginPath()}?url=${n}`}return e}))})}_getLoginPath(){var i;return(i=this._configService.getConfig(Tt))!=null?i:Ps}};ye=$s([We(0,a.IConfigService),We(1,l.Inject(P.HTTPService)),We(2,l.Inject(a.LocaleService))],ye);var js=(i,t,e,s)=>{for(var n=t,r=i.length-1,o;r>=0;r--)(o=i[r])&&(n=o(n)||n);return n},Rt=(i,t)=>(e,s)=>t(e,s,i);const Hs="collaboration-client";S.CollaborationClientPlugin=(Ge=class extends a.Plugin{constructor(t,e,s){super(),this._config=t,this._injector=e,this._localeService=s,this._localeService.load({zhCN:pt})}onStarting(t){var n,r,o,c;t.replace([a.IUndoRedoService,{useClass:xe}]);const e=[[S.CollaborationSessionService],[Ae],[P.HTTPService],[It,{useClass:Ds}],[G],[D],[P.WebSocketService],[ge],[Se],[ve],[Ue],[ye],[De,{useClass:(r=(n=this._config)==null?void 0:n.socketService)!=null?r:S.CollaborationSocketService}],[P.IHTTPImplementation,{useClass:P.XHRHTTPImplementation}],[a.ISnapshotServerService,{useClass:Be}],[S.CollaborationController],[ae],[Ee],[be],[Z]];(o=this._config)!=null&&o.enableSingleActiveInstanceLock&&e.push([de,{useClass:Vt}]),((c=this._config)==null?void 0:c.collaborationUniverTypes)==null||this._config.collaborationUniverTypes.includes(a.UniverInstanceType.UNIVER_SHEET)?e.push([Ce]):this._config.collaborationUniverTypes.includes(a.UniverInstanceType.UNIVER_DOC)&&e.push([Re]),e.forEach(h=>t.add(h)),t.get(P.HTTPService).registerHTTPInterceptor({priority:20,interceptor:t.invoke(P.ThresholdInterceptorFactory,{maxParallel:6})}),this._initModules()}_initModules(){var t,e;this._injector.get(ae),(t=this._config)!=null&&t.enableOfflineEditing||this._injector.get(D).disableLocalCache(),(e=this._config)!=null&&e.enableAuthServer&&this._injector.get(ye)}},d(Ge,"pluginName",Hs),Ge),S.CollaborationClientPlugin=js([Rt(1,l.Inject(l.Injector)),Rt(2,l.Inject(a.LocaleService))],S.CollaborationClientPlugin);const Bs={collabStatus:{fetchMiss:"Syncing server data...",conflict:"Edit conflicts",notCollab:"Local file",synced:"Synced",syncing:"Syncing...",offline:"Offline, edits would be save on local"},session:{"connection-failed":"Connection failed, please check your network.","will-retry":"Connection failed, we retry in a while.","room-full":"Collaboration room is full. You edits would be saved locally.","collaboration-timeout":"The server is not responding to your collaboration request. Your edits would be saved locally."},conflict:{title:"Collaboration Conflict",content:"There is a conflict between your local copy and the copy on the server. Please save your local edits, because they will be lost when you reload the page."},collaboration:{"single-unit":{warning:"You opened the same file in another tab. In case of data missing, you cannot edit on this tab."}},auth:{needGotoLoginAlert:"Your login has expired, click OK to re-login, click Cancel to save your local edits."}};S.COLLAB_SUBMIT_CHANGESET_URL_KEY=Ze,S.COLLAB_WEB_SOCKET_URL_KEY=et,S.HEARTBEAT_INTERVAL_KEY=tt,S.HEARTBEAT_TIMEOUT_KEY=we,S.ICollaborationSocketService=De,S.LOCAL_CACHE_INTERVAL_KEY=nt,S.LOGIN_URL_KEY=Tt,S.SEND_CHANGESET_TIMEOUT_KEY=_t,S.SNAPSHOT_SERVER_URL_KEY=bt,S.SessionStatus=Y,S.deserializeToCombResponse=ze,S.enUS=Bs,S.serializeCombRequest=Je,S.zhCN=pt,Object.defineProperty(S,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,102 @@
1
+ {
2
+ "name": "@univerjs-pro/collaboration-client",
3
+ "version": "0.1.9",
4
+ "private": false,
5
+ "description": "Univer Collaboration Client",
6
+ "author": "DreamNum <developer@univer.ai>",
7
+ "funding": {
8
+ "type": "opencollective",
9
+ "url": "https://opencollective.com/univer"
10
+ },
11
+ "homepage": "https://univer.ai",
12
+ "repository": {
13
+ "type": "git",
14
+ "url": "https://github.com/dream-num/univer"
15
+ },
16
+ "bugs": {
17
+ "url": "https://github.com/dream-num/univer/issues"
18
+ },
19
+ "keywords": [],
20
+ "sideEffects": [
21
+ "**/*.css"
22
+ ],
23
+ "exports": {
24
+ ".": {
25
+ "import": "./lib/es/index.js",
26
+ "require": "./lib/cjs/index.js",
27
+ "types": "./lib/types/index.d.ts"
28
+ },
29
+ "./*": {
30
+ "import": "./lib/es/*",
31
+ "require": "./lib/cjs/*",
32
+ "types": "./lib/types/index.d.ts"
33
+ },
34
+ "./lib/*": "./lib/*"
35
+ },
36
+ "main": "./lib/cjs/index.js",
37
+ "module": "./lib/es/index.js",
38
+ "types": "./lib/types/index.d.ts",
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "directories": {
43
+ "lib": "lib"
44
+ },
45
+ "files": [
46
+ "lib"
47
+ ],
48
+ "peerDependencies": {
49
+ "@wendellhu/redi": "^0.13.3",
50
+ "clsx": ">=2.0.0",
51
+ "lodash": ">=4.0.0",
52
+ "react": "^16.9.0 || ^17.0.0 || ^18.0.0",
53
+ "rxjs": ">=7.0.0",
54
+ "@univerjs-pro/collaboration": "0.1.9",
55
+ "@univerjs/docs": "0.1.9",
56
+ "@univerjs/core": "0.1.9",
57
+ "@univerjs/design": "0.1.9",
58
+ "@univerjs/engine-render": "0.1.9",
59
+ "@univerjs/network": "0.1.9",
60
+ "@univerjs/sheets": "0.1.9",
61
+ "@univerjs/rpc": "0.1.9",
62
+ "@univerjs/sheets-ui": "0.1.9",
63
+ "@univerjs/ui": "0.1.9",
64
+ "@univerjs/engine-formula": "0.1.9"
65
+ },
66
+ "dependencies": {
67
+ "@univerjs/icons": "^0.1.42",
68
+ "@univerjs/protocol": "0.1.23"
69
+ },
70
+ "devDependencies": {
71
+ "@types/lodash": "^4.17.0",
72
+ "@types/react": "^18.2.72",
73
+ "@wendellhu/redi": "^0.13.3",
74
+ "clsx": "^2.1.0",
75
+ "less": "^4.2.0",
76
+ "lodash": "^4.17.21",
77
+ "react": "18.2.0",
78
+ "rxjs": "^7.8.1",
79
+ "typescript": "^5.4.5",
80
+ "vite": "^5.2.6",
81
+ "vitest": "^1.4.0",
82
+ "@univerjs/design": "0.1.9",
83
+ "@univerjs/engine-formula": "0.1.9",
84
+ "@univerjs-pro/collaboration": "0.1.9",
85
+ "@univerjs/docs": "0.1.9",
86
+ "@univerjs/network": "0.1.9",
87
+ "@univerjs/engine-render": "0.1.9",
88
+ "@univerjs/core": "0.1.9",
89
+ "@univerjs/rpc": "0.1.9",
90
+ "@univerjs/sheets": "0.1.9",
91
+ "@univerjs/ui": "0.1.9",
92
+ "@univerjs/sheets-ui": "0.1.9",
93
+ "@univerjs/shared": "0.1.9"
94
+ },
95
+ "scripts": {
96
+ "test": "vitest run",
97
+ "test:watch": "vitest",
98
+ "coverage": "vitest run --coverage",
99
+ "lint:types": "tsc --noEmit",
100
+ "build": "tsc && vite build"
101
+ }
102
+ }