@fileverse-dev/dsheet 2.0.36-shortcut-1 → 2.0.36-shortcut-3

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 (45) hide show
  1. package/dist/{constants-CnhOvijG.js → constants-yStXQJiK.js} +35 -14
  2. package/dist/constants.d.ts +4 -0
  3. package/dist/constants.js +6 -3
  4. package/dist/editor/components/collab-status-chip.d.ts +8 -0
  5. package/dist/editor/contexts/editor-context.d.ts +15 -5
  6. package/dist/editor/dsheet-editor.d.ts +1 -1
  7. package/dist/editor/hooks/use-collab-awareness.d.ts +17 -0
  8. package/dist/editor/hooks/use-editor-data.d.ts +2 -1
  9. package/dist/editor/hooks/use-editor-sync.d.ts +9 -6
  10. package/dist/editor/types.d.ts +2 -2
  11. package/dist/editor/utils/after-update-cell.d.ts +12 -0
  12. package/dist/editor/utils/formula-ui-sync.d.ts +3 -1
  13. package/dist/editor/utils/remote-apply-guard.d.ts +19 -0
  14. package/dist/{executeStringFunction-6r6Tl4Z6.js → executeStringFunction-tdvZ0KTi.js} +4646 -4612
  15. package/dist/formula.js +1 -1
  16. package/dist/index-D_IxoHMJ.js +52167 -0
  17. package/dist/index.d.ts +3 -1
  18. package/dist/index.es.js +46 -41
  19. package/dist/sheet-engine/core/api/cell.d.ts +21 -0
  20. package/dist/sheet-engine/core/events/index.d.ts +1 -0
  21. package/dist/sheet-engine/core/events/keyboard-shortcut-utils.d.ts +61 -0
  22. package/dist/sheet-engine/core/index.d.ts +2 -2
  23. package/dist/sheet-engine/core/modules/filter.d.ts +13 -0
  24. package/dist/sheet-engine/core/modules/index.d.ts +2 -2
  25. package/dist/sheet-engine/core/modules/selection.d.ts +1 -0
  26. package/dist/sheet-engine/core/modules/zoom.d.ts +0 -1
  27. package/dist/sheet-engine/core/settings.d.ts +3 -0
  28. package/dist/sheet-engine/core/types.d.ts +1 -0
  29. package/dist/sheet-engine/react/components/Workbook/api.d.ts +23 -0
  30. package/dist/sheet-engine/react/components/Workbook/index.d.ts +15 -0
  31. package/dist/style.css +1 -1
  32. package/dist/sync-local/SyncManager.d.ts +69 -0
  33. package/dist/sync-local/collabStateMachine.d.ts +23 -0
  34. package/dist/sync-local/crypto/index.d.ts +6 -0
  35. package/dist/sync-local/index.d.ts +3 -0
  36. package/dist/sync-local/socketClient.d.ts +68 -0
  37. package/dist/sync-local/types/index.d.ts +212 -0
  38. package/dist/sync-local/useSyncManager.d.ts +12 -0
  39. package/dist/sync-local/utils/createAwarenessUpdateHandler.d.ts +8 -0
  40. package/dist/sync-local/utils/objectToFile.d.ts +1 -0
  41. package/dist/{use-xlsx-import-impl-ehiopPNr.js → use-xlsx-import-impl-AI2QDZt1.js} +2 -2
  42. package/dist/{xlsx-export-impl-BLKOiPKJ.js → xlsx-export-impl-Buly1jC6.js} +293 -295
  43. package/package.json +13 -9
  44. package/dist/editor/hooks/use-editor-collaboration.d.ts +0 -9
  45. package/dist/index-D-9Q_hz4.js +0 -40345
@@ -0,0 +1,69 @@
1
+ import { Awareness } from 'y-protocols/awareness.js';
2
+ import { SyncManagerConfig, CollabConnectionConfig, CollabServices, CollabCallbacks, CollabStatus, CollabState } from './types';
3
+
4
+ export declare class SyncManager {
5
+ private onCollabStateChange;
6
+ private _status;
7
+ private _context;
8
+ private _awareness;
9
+ private socketClient;
10
+ private roomKey;
11
+ private roomKeyBytes;
12
+ private isOwner;
13
+ private updateQueue;
14
+ private uncommittedUpdatesIdList;
15
+ private contentTobeAppliedQueue;
16
+ private isProcessing;
17
+ /** Prevents parallel terminateSession calls (UI + effect cleanup). */
18
+ private _terminating;
19
+ private flushTimer;
20
+ private readonly FLUSH_INTERVAL_MS;
21
+ private readonly MAX_QUEUE_SIZE;
22
+ private _awarenessUpdateHandler;
23
+ private ydoc;
24
+ private servicesRef;
25
+ private callbacksRef;
26
+ private onLocalUpdate?;
27
+ constructor(config: SyncManagerConfig, onCollabStateChange: (state: CollabState) => void);
28
+ /** Called by useSyncManager on every render to keep refs fresh */
29
+ updateRefs(services: CollabServices | undefined, callbacks: CollabCallbacks | undefined, onLocalUpdate?: (updatedDocContent: string, updateChunk: string) => void): void;
30
+ get isConnected(): boolean;
31
+ get isReady(): boolean;
32
+ get awareness(): Awareness | null;
33
+ get status(): CollabStatus;
34
+ get collabState(): CollabState;
35
+ private send;
36
+ private runExitActions;
37
+ private runEntryActions;
38
+ connect(config: CollabConnectionConfig): Promise<void>;
39
+ disconnect(): Promise<void>;
40
+ terminateSession(): Promise<void>;
41
+ enqueueLocalUpdate(update: Uint8Array): void;
42
+ private flushUpdates;
43
+ private awaitFlush;
44
+ /**
45
+ * Fire-and-forget: merge all queued updates, encrypt, and emit via Socket.IO
46
+ * without awaiting the server ACK. The server broadcasts to peers immediately
47
+ * (before MongoDB write), so content reaches observers in near-real-time.
48
+ * ACK callback handles updateId tracking and auto-commit asynchronously.
49
+ */
50
+ private sendUpdateBatch;
51
+ forceCleanup(): void;
52
+ private handleConnectionError;
53
+ private handleReconnection;
54
+ private connectSocket;
55
+ private syncLatestCommit;
56
+ private initializeAwareness;
57
+ private cleanupAwareness;
58
+ private commitLocalContents;
59
+ private broadcastLocalContents;
60
+ private processUpdateQueue;
61
+ private processNextUpdate;
62
+ private processCommit;
63
+ private handleRemoteContentUpdate;
64
+ private applyRemoteYjsUpdate;
65
+ private applyQueuedRemoteContents;
66
+ private withRetry;
67
+ private disconnectInternal;
68
+ private resetInternalState;
69
+ }
@@ -0,0 +1,23 @@
1
+ import { CollabStatus, CollabEvent, CollabContext, CollabState, CollabErrorCode } from './types';
2
+
3
+ export declare const INITIAL_CONTEXT: CollabContext;
4
+ type TransitionResult = {
5
+ status: CollabStatus;
6
+ context: Partial<CollabContext>;
7
+ } | null;
8
+ /**
9
+ * Transition map: (currentStatus, eventType) → nextStatus + context mutations.
10
+ * Returns null if the transition is invalid.
11
+ */
12
+ export declare function transition(currentStatus: CollabStatus, event: CollabEvent, context: CollabContext): TransitionResult;
13
+ /**
14
+ * Derives the consumer-facing CollabState from internal status + context.
15
+ */
16
+ export declare function deriveCollabState(status: CollabStatus, context: CollabContext): CollabState;
17
+ /** Helper to create a CollabError */
18
+ export declare function createCollabError(code: CollabErrorCode, message: string, recoverable?: boolean): {
19
+ code: CollabErrorCode;
20
+ message: string;
21
+ recoverable: boolean;
22
+ };
23
+ export {};
@@ -0,0 +1,6 @@
1
+ export declare const crypto: {
2
+ generateKeyPair: () => import('@fileverse/crypto/ecies').EciesKeyPairBytes;
3
+ encryptData: (key: Uint8Array, message: Uint8Array) => string;
4
+ decryptData: (key: Uint8Array, message: string) => Uint8Array<ArrayBufferLike>;
5
+ generateRandomBytes: <E extends import('@fileverse/crypto/types').EncodingType = "bytes">(length?: number, encoding?: E) => import('@fileverse/crypto/types').EncodedReturnType<E>;
6
+ };
@@ -0,0 +1,3 @@
1
+ export { useSyncManager } from './useSyncManager';
2
+ export { SyncManager } from './SyncManager';
3
+ export type { SyncManagerConfig, CollabConnectionConfig, CollabServices, CollabCallbacks, CollaborationProps, CollabSessionMeta, CollabStatus, CollabState, CollabError, CollabErrorCode, CollabEvent, CollabContext, CollabUser, } from './types';
@@ -0,0 +1,68 @@
1
+ import { ISocketInitConfig, RoomMember, SocketStatusEnum, SendUpdateResponse, CommitResponse, AckResponse } from './types';
2
+ import { Awareness } from 'y-protocols/awareness.js';
3
+
4
+ interface ISocketClientConfig {
5
+ wsUrl: string;
6
+ roomKey: string;
7
+ roomId: string;
8
+ ownerEdSecret?: string;
9
+ contractAddress?: string;
10
+ ownerAddress?: string;
11
+ onHandshakeData?: (response: {
12
+ data: AckResponse;
13
+ roomKey: string;
14
+ }) => void;
15
+ roomInfo?: {
16
+ documentTitle: string;
17
+ portalAddress: string;
18
+ commentKey: string;
19
+ };
20
+ }
21
+ export declare class SocketClient {
22
+ private _socketUrl;
23
+ private _socket;
24
+ private _webSocketStatus;
25
+ private _isIntentionalDisconnect;
26
+ get isConnected(): boolean;
27
+ get status(): SocketStatusEnum;
28
+ private _websocketServiceDid;
29
+ private roomId;
30
+ roomMembers: RoomMember[];
31
+ private collaborationKeyPair;
32
+ private ownerKeyPair?;
33
+ private contractAddress?;
34
+ private ownerUcan?;
35
+ private collaborationUcan?;
36
+ private ownerAddress?;
37
+ private roomKey;
38
+ private roomInfo?;
39
+ private awareness;
40
+ private connectionAttemptErrorCount;
41
+ private _onHandshakeData;
42
+ constructor(config: ISocketClientConfig);
43
+ registerAwareness(awareness: Awareness): void;
44
+ private _emitWithAck;
45
+ private _fetchRoomMembers;
46
+ sendUpdate({ update }: {
47
+ update: string;
48
+ }): Promise<SendUpdateResponse>;
49
+ commitUpdates({ updates, cid }: {
50
+ updates: string[];
51
+ cid: string;
52
+ }): Promise<CommitResponse>;
53
+ fetchLatestCommit(): Promise<AckResponse<any>>;
54
+ getUncommittedChanges(): Promise<AckResponse<any>>;
55
+ broadcastAwareness(awarenessUpdate: string): Promise<void>;
56
+ disconnect: () => void;
57
+ terminateSession: () => Promise<void>;
58
+ private getCollaborationKeyPair;
59
+ private isUcanValid;
60
+ private getOwnerToken;
61
+ private buildSessionToken;
62
+ private _handleHandShake;
63
+ private _handleAwarenessUpdate;
64
+ connectSocket(config: ISocketInitConfig): Promise<void>;
65
+ private _onSessionTerminated;
66
+ private resetSocketClient;
67
+ }
68
+ export {};
@@ -0,0 +1,212 @@
1
+ import * as Y from 'yjs';
2
+ export interface CollabUser {
3
+ clientId: number;
4
+ name: string;
5
+ color: string;
6
+ isEns: boolean;
7
+ cell?: {
8
+ r: number;
9
+ c: number;
10
+ sheetId: string;
11
+ };
12
+ }
13
+ /** Connection identity — changes to these trigger reconnect */
14
+ export interface CollabConnectionConfig {
15
+ roomKey: string;
16
+ roomId: string;
17
+ wsUrl: string;
18
+ isOwner: boolean;
19
+ ownerEdSecret?: string;
20
+ contractAddress?: string;
21
+ ownerAddress?: string;
22
+ roomInfo?: {
23
+ documentTitle: string;
24
+ portalAddress: string;
25
+ commentKey: string;
26
+ };
27
+ }
28
+ /** Session metadata — changes to these update awareness, NOT reconnect */
29
+ export interface CollabSessionMeta {
30
+ username: string;
31
+ color?: string;
32
+ isEns?: boolean;
33
+ }
34
+ /** Storage integrations the sync engine depends on */
35
+ export interface CollabServices {
36
+ commitToStorage?: (file: File) => Promise<string>;
37
+ fetchFromStorage?: (cid: string) => Promise<any>;
38
+ }
39
+ export type CollabErrorCode = 'CONNECTION_FAILED' | 'AUTH_FAILED' | 'SYNC_FAILED' | 'TIMEOUT' | 'UNKNOWN';
40
+ export type CollabError = {
41
+ code: CollabErrorCode;
42
+ message: string;
43
+ recoverable: boolean;
44
+ };
45
+ export type CollabStatus = 'idle' | 'connecting' | 'syncing' | 'ready' | 'reconnecting' | 'error' | 'terminated';
46
+ export type CollabState = {
47
+ status: 'idle';
48
+ } | {
49
+ status: 'connecting';
50
+ } | {
51
+ status: 'syncing';
52
+ hasUnmergedPeerUpdates: boolean;
53
+ } | {
54
+ status: 'ready';
55
+ } | {
56
+ status: 'reconnecting';
57
+ attempt: number;
58
+ maxAttempts: number;
59
+ } | {
60
+ status: 'error';
61
+ error: CollabError;
62
+ } | {
63
+ status: 'terminated';
64
+ reason?: string;
65
+ };
66
+ export type CollabEvent = {
67
+ type: 'CONNECT';
68
+ } | {
69
+ type: 'AUTH_SUCCESS';
70
+ } | {
71
+ type: 'SYNC_COMPLETE';
72
+ } | {
73
+ type: 'SET_UNMERGED_UPDATES';
74
+ hasUpdates: boolean;
75
+ } | {
76
+ type: 'SOCKET_DROPPED';
77
+ } | {
78
+ type: 'RECONNECTED';
79
+ } | {
80
+ type: 'RETRY_EXHAUSTED';
81
+ } | {
82
+ type: 'ERROR';
83
+ error: CollabError;
84
+ } | {
85
+ type: 'SESSION_TERMINATED';
86
+ reason?: string;
87
+ } | {
88
+ type: 'RESET';
89
+ };
90
+ export interface CollabContext {
91
+ hasUnmergedPeerUpdates: boolean;
92
+ reconnectAttempt: number;
93
+ maxReconnectAttempts: number;
94
+ error: CollabError | null;
95
+ terminationReason?: string;
96
+ }
97
+ /** Event callbacks the consumer reacts to */
98
+ export interface CollabCallbacks {
99
+ onStateChange?: (state: CollabState) => void;
100
+ onError?: (error: CollabError) => void;
101
+ onCollaboratorsChange?: (collaborators: CollabUser[]) => void;
102
+ onHandshakeData?: (data: {
103
+ data: AckResponse;
104
+ roomKey: string;
105
+ }) => void;
106
+ }
107
+ /** Discriminated union — TypeScript enforces config+services only when enabled */
108
+ export type CollaborationProps = {
109
+ enabled: false;
110
+ } | {
111
+ enabled: true;
112
+ connection: CollabConnectionConfig;
113
+ session: CollabSessionMeta;
114
+ services: CollabServices;
115
+ on?: CollabCallbacks;
116
+ };
117
+ export interface SyncManagerConfig {
118
+ ydoc: Y.Doc;
119
+ services?: CollabServices;
120
+ callbacks?: CollabCallbacks;
121
+ onLocalUpdate?: (updatedDocContent: string, updateChunk: string) => void;
122
+ /** Origins to ignore in the ydoc update handler (e.g. IndexedDB provider) */
123
+ ignoredOrigins?: Array<{
124
+ current: unknown;
125
+ }>;
126
+ }
127
+ export declare enum ServerErrorCode {
128
+ AUTH_TOKEN_MISSING = "AUTH_TOKEN_MISSING",
129
+ AUTH_TOKEN_INVALID = "AUTH_TOKEN_INVALID",
130
+ SESSION_NOT_FOUND = "SESSION_NOT_FOUND",
131
+ SESSION_TERMINATED = "SESSION_TERMINATED",
132
+ SESSION_DID_MISSING = "SESSION_DID_MISSING",
133
+ DOCUMENT_ID_MISSING = "DOCUMENT_ID_MISSING",
134
+ UPDATE_DATA_MISSING = "UPDATE_DATA_MISSING",
135
+ COMMIT_UNAUTHORIZED = "COMMIT_UNAUTHORIZED",
136
+ COMMIT_MISSING_DATA = "COMMIT_MISSING_DATA",
137
+ INVALID_ADDRESS = "INVALID_ADDRESS",
138
+ NOT_AUTHENTICATED = "NOT_AUTHENTICATED",
139
+ DB_ERROR = "DB_ERROR",
140
+ INTERNAL_ERROR = "INTERNAL_ERROR",
141
+ APP_MISMATCH = "APP_MISMATCH"
142
+ }
143
+ export interface AckResponse<T = Record<string, any>> {
144
+ status: boolean;
145
+ statusCode: number;
146
+ data?: T;
147
+ error?: string;
148
+ errorCode?: ServerErrorCode;
149
+ }
150
+ export interface SendUpdateResponse extends AckResponse<{
151
+ id: string;
152
+ documentId: string;
153
+ data: string;
154
+ updateType: string;
155
+ commitCid: string | null;
156
+ createdAt: number;
157
+ }> {
158
+ }
159
+ export interface CommitResponse extends AckResponse<{
160
+ cid: string;
161
+ createdAt: number;
162
+ documentId: string;
163
+ updates: string[];
164
+ }> {
165
+ }
166
+ export interface ISocketInitConfig {
167
+ onHandshakeSuccess: () => void;
168
+ onDisconnect: () => void;
169
+ onSocketDropped: () => void;
170
+ onError: (err: Error) => void;
171
+ onHandShakeError: (err: Error, statusCode?: number) => void;
172
+ onContentUpdate: (data: {
173
+ id: string;
174
+ data: string;
175
+ createdAt: number;
176
+ roomId: string;
177
+ }) => void;
178
+ onMembershipChange: (data: {
179
+ action: string;
180
+ user: {
181
+ role: string;
182
+ };
183
+ roomId: string;
184
+ }) => void;
185
+ onSessionTerminated: (data: {
186
+ roomId: string;
187
+ }) => void;
188
+ onReconnectFailed: () => void;
189
+ }
190
+ export declare enum SocketStatusEnum {
191
+ CLOSED = "CLOSED",
192
+ CONNECTED = "CONNECTED",
193
+ CONNECTING = "CONNECTING",
194
+ DISCONNECTING = "DISCONNECTING",
195
+ DISCONNECTED = "DISCONNECTED"
196
+ }
197
+ export interface RoomMember {
198
+ username: string;
199
+ userId: string;
200
+ role: 'owner' | 'editor';
201
+ }
202
+ export type AppType = 'ddoc' | 'dsheet';
203
+ export interface IAuthArgs {
204
+ collaborationToken: string;
205
+ documentId: string;
206
+ ownerToken?: string;
207
+ ownerAddress?: string;
208
+ contractAddress?: string;
209
+ sessionDid?: string;
210
+ roomInfo?: string;
211
+ appType?: AppType;
212
+ }
@@ -0,0 +1,12 @@
1
+ import { SyncManagerConfig, CollabConnectionConfig, CollabState } from './types';
2
+
3
+ export declare const useSyncManager: (config: SyncManagerConfig) => {
4
+ state: CollabState;
5
+ connect: (connectConfig: CollabConnectionConfig) => void;
6
+ disconnect: () => void;
7
+ terminateSession: () => void;
8
+ isReady: boolean;
9
+ isSyncing: boolean;
10
+ awareness: import('y-protocols/awareness.js').Awareness | null;
11
+ hasCollabContentInitialised: boolean;
12
+ };
@@ -0,0 +1,8 @@
1
+ import { Awareness } from 'y-protocols/awareness';
2
+ import { SocketClient } from '../socketClient';
3
+
4
+ export declare const createAwarenessUpdateHandler: (awareness: Awareness, socketClient: SocketClient, roomKey: string) => ({ added, updated, removed, }: {
5
+ added: number[];
6
+ updated: number[];
7
+ removed: number[];
8
+ }, origin: any) => void;
@@ -0,0 +1 @@
1
+ export declare const objectToFile: (data: Record<string, unknown>, fileName: string) => File;
@@ -1,6 +1,6 @@
1
- import { g as Ue } from "./executeStringFunction-6r6Tl4Z6.js";
1
+ import { g as Ue } from "./executeStringFunction-tdvZ0KTi.js";
2
2
  import * as qe from "yjs";
3
- import { m as Xe, y as Ze } from "./index-D-9Q_hz4.js";
3
+ import { m as Xe, y as Ze } from "./index-D_IxoHMJ.js";
4
4
  import { n as Je } from "./xlsx-hyperlink-inline-DzewAypN.js";
5
5
  import { toast as Be } from "@fileverse/ui";
6
6
  var We = { exports: {} };