@veltdev/ace-crdt-react 1.0.0

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.
@@ -0,0 +1,5 @@
1
+ import 'ace-builds/src-noconflict/mode-javascript';
2
+ import 'ace-builds/src-noconflict/theme-textmate';
3
+ import type { AceCrdtEditorProps } from './types';
4
+ export declare function AceCrdtEditor(props: AceCrdtEditorProps): import("react").JSX.Element | null;
5
+ //# sourceMappingURL=ace-crdt-editor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ace-crdt-editor.d.ts","sourceRoot":"","sources":["../../../src/ace-crdt-editor.tsx"],"names":[],"mappings":"AAKA,OAAO,2CAA2C,CAAC;AACnD,OAAO,0CAA0C,CAAC;AAGlD,OAAO,KAAK,EAAE,kBAAkB,EAA6B,MAAM,SAAS,CAAC;AAG7E,wBAAgB,aAAa,CAAC,KAAK,EAAE,kBAAkB,sCAmHtD"}
@@ -0,0 +1,15 @@
1
+ import type { AceCrdtProviderProps, UseCollaborationReturn } from './types';
2
+ export declare const CollaborationContext: import("react").Context<UseCollaborationReturn | null>;
3
+ /**
4
+ * Context provider that runs useCollaboration once and shares the hook result
5
+ * with descendants. The context value is the hook's memoized return object, so
6
+ * consumers only re-render when collaboration state actually changes.
7
+ */
8
+ export declare function AceCrdtProvider({ config, children }: AceCrdtProviderProps): import("react").JSX.Element | null;
9
+ export declare const CollaborationProvider: typeof AceCrdtProvider;
10
+ /**
11
+ * Read the collaboration value shared by the nearest AceCrdtProvider.
12
+ * Returns null (never throws) when called outside a provider.
13
+ */
14
+ export declare function useCollaborationContext(): UseCollaborationReturn | null;
15
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/context.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAI5E,eAAO,MAAM,oBAAoB,wDAAqD,CAAC;AAEvF;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,EAAE,MAAM,EAAE,QAAQ,EAAE,EAAE,oBAAoB,sCAazE;AAED,eAAO,MAAM,qBAAqB,wBAAkB,CAAC;AAErD;;;GAGG;AACH,wBAAgB,uBAAuB,IAAI,sBAAsB,GAAG,IAAI,CAOvE"}
@@ -0,0 +1,6 @@
1
+ export { CollaborationContext, CollaborationProvider, AceCrdtProvider, useCollaborationContext } from './context';
2
+ export { AceCrdtEditor } from './ace-crdt-editor';
3
+ export { useCollaboration } from './use-collaboration';
4
+ export { CollaborationManager, createCollaboration, indexToPosition, normalizeText, offsetsToRange, positionToIndex, rangeToOffsets, } from '@veltdev/ace-crdt';
5
+ export type { AceAwarenessSelection, AceCrdtEditorProps, AceCrdtProviderProps, AceCursorData, AceDelta, AceEditorLike, AcePosition, AceRangeFactory, AceSelectionRange, BindEditorOptions, CollaborationConfig, CollaborationPrimitives, CollaborationProviderProps, CollaborationStats, ReactAceProps, RemoteSelection, SyncStatus, Unsubscribe, UseCollaborationConfig, UseCollaborationReturn, Version, } from './types';
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,eAAe,EAAE,uBAAuB,EAAE,MAAM,WAAW,CAAC;AAClH,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAEvD,OAAO,EACL,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,EACf,aAAa,EACb,cAAc,EACd,eAAe,EACf,cAAc,GACf,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,qBAAqB,EACrB,kBAAkB,EAClB,oBAAoB,EACpB,aAAa,EACb,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,uBAAuB,EACvB,0BAA0B,EAC1B,kBAAkB,EAClB,aAAa,EACb,eAAe,EACf,UAAU,EACV,WAAW,EACX,sBAAsB,EACtB,sBAAsB,EACtB,OAAO,GACR,MAAM,SAAS,CAAC"}
@@ -0,0 +1,139 @@
1
+ import type { ComponentProps, ReactNode } from 'react';
2
+ import type AceEditorComponent from 'react-ace';
3
+ import type { Velt } from '@veltdev/types';
4
+ import type { AceAwarenessSelection, AceCursorData, AceDelta, AceEditorLike, AcePosition, AceRangeFactory, AceSelectionRange, BindEditorOptions, CollaborationConfig as BaseCollaborationConfig, CollaborationManager, CollaborationPrimitives, CollaborationStats, RemoteSelection, SyncStatus, Unsubscribe, Version } from '@veltdev/ace-crdt';
5
+ export type { AceAwarenessSelection, AceCursorData, AceDelta, AceEditorLike, AcePosition, AceRangeFactory, AceSelectionRange, BindEditorOptions, CollaborationManager, CollaborationPrimitives, CollaborationStats, RemoteSelection, SyncStatus, Unsubscribe, Version, };
6
+ export type CollaborationConfig = BaseCollaborationConfig;
7
+ export type ReactAceProps = ComponentProps<typeof AceEditorComponent>;
8
+ /**
9
+ * Hook configuration.
10
+ *
11
+ * Re-initialization is driven only by identity-relevant inputs: `editorId`,
12
+ * `veltClient`, the attached editor instance, `enabled`, and
13
+ * `initializeWithoutEditor`. The remaining fields inherited from the base
14
+ * config (`initialContent`, `forceResetInitialContent`, `cursorData`,
15
+ * `rangeFactory`, `debounceMs`, `onError`'s identity) are read once at
16
+ * initialization time — changing them later has no effect until the manager
17
+ * re-initializes.
18
+ */
19
+ export interface UseCollaborationConfig extends Omit<BaseCollaborationConfig, 'veltClient'> {
20
+ /** Optional Velt client override. Falls back to VeltProvider context. */
21
+ veltClient?: Velt;
22
+ /** Set false to render/capture the editor without creating collaboration. */
23
+ enabled?: boolean;
24
+ /**
25
+ * By default, `editor: null` delays manager initialization until Ace exists.
26
+ * Set this to true to initialize first and attach the editor later.
27
+ */
28
+ initializeWithoutEditor?: boolean;
29
+ }
30
+ export interface UseCollaborationReturn {
31
+ /** Callback ref for react-ace onLoad or custom Ace creation. */
32
+ editorRef: (editor: AceEditorLike | null) => void;
33
+ /** Escape hatch to the base CollaborationManager. */
34
+ manager: CollaborationManager | null;
35
+ /** Currently attached Ace editor instance, if any. */
36
+ editor: AceEditorLike | null;
37
+ /** Lower-level Yjs/Velt primitives from the base manager. */
38
+ primitives: CollaborationPrimitives | null;
39
+ /** true until the CollaborationManager is initialized or fails. */
40
+ isLoading: boolean;
41
+ /** true after the first backend sync completes. */
42
+ synced: boolean;
43
+ /** Alias for `synced`, matching the other Velt React wrappers. */
44
+ isSynced: boolean;
45
+ /** Connection status from the base manager/provider. */
46
+ status: SyncStatus;
47
+ /** Non-null if initialization failed. */
48
+ error: Error | null;
49
+ /** Current shared text value from the base manager. */
50
+ value: string;
51
+ /** Latest saved versions list from the base manager. */
52
+ versions: Version[];
53
+ /** Latest remote text selections from awareness. */
54
+ remoteSelections: RemoteSelection[];
55
+ /** Snapshot of base manager statistics. */
56
+ stats: CollaborationStats | null;
57
+ /** Refresh React snapshots from the current base manager state. */
58
+ refreshSnapshots: () => void;
59
+ /** Attach an Ace editor to the current manager. */
60
+ attachEditor: (editor: AceEditorLike | null | undefined, options?: BindEditorOptions) => boolean;
61
+ /** Detach the current Ace editor from the manager. */
62
+ detachEditor: () => void;
63
+ /** Get the current shared text value. */
64
+ getValue: () => string;
65
+ /** Replace the shared text value. */
66
+ setValue: (value: string, reason?: string) => boolean;
67
+ /** Insert text at an index or current cursor. */
68
+ insertText: (value: string, index?: number) => boolean;
69
+ /** Flush the attached editor into the CRDT Store. */
70
+ flushEditorToStore: (reason?: string) => boolean;
71
+ /** Force the shared text state to initial content or supplied content. */
72
+ forceReset: (initialContent?: string) => Promise<boolean>;
73
+ /** Publish the current local selection through awareness. */
74
+ publishCurrentSelection: (kind?: AceAwarenessSelection['kind']) => boolean;
75
+ /** Set or clear the local awareness selection. */
76
+ setLocalSelection: (selection: Partial<AceAwarenessSelection> | null) => boolean;
77
+ /** Add a remote-awareness highlight marker for the current or supplied range. */
78
+ addHighlight: (range?: Partial<AceSelectionRange>, color?: string) => boolean;
79
+ /** Render remote selection/cursor/highlight markers in Ace. */
80
+ renderRemoteSelections: () => number;
81
+ /** Clear rendered remote markers. */
82
+ clearRemoteMarkers: () => void;
83
+ /** Undo through the base Y.UndoManager. */
84
+ undo: () => boolean;
85
+ /** Redo through the base Y.UndoManager. */
86
+ redo: () => boolean;
87
+ /** Save a named version and refresh the hook version list. */
88
+ saveVersion: (name: string) => Promise<string>;
89
+ /** Read saved versions without mutating hook state. */
90
+ getVersions: () => Promise<Version[]>;
91
+ /** Read a single saved version by id. */
92
+ getVersionById: (versionId: string) => Promise<Version | null>;
93
+ /** Refresh and store saved versions in hook state. */
94
+ refreshVersions: () => Promise<Version[]>;
95
+ /** Restore a version and refresh hook state. */
96
+ restoreVersion: (versionId: string) => Promise<boolean>;
97
+ /** Apply a Version object returned by the base package. */
98
+ setStateFromVersion: (version: Version) => Promise<void>;
99
+ /** Destroy the manager early. Also runs on unmount. */
100
+ destroy: () => void;
101
+ }
102
+ export interface AceCrdtProviderProps {
103
+ config: UseCollaborationConfig;
104
+ children: ReactNode | ((value: UseCollaborationReturn) => ReactNode);
105
+ }
106
+ export interface AceCrdtEditorProps extends Omit<ReactAceProps, 'value' | 'defaultValue' | 'onLoad'> {
107
+ /** Unique editor/document identifier for syncing. */
108
+ editorId?: string;
109
+ /** Convenience document identifier used as editorId when editorId is omitted. */
110
+ documentId?: string;
111
+ /** Optional Velt client override. Falls back to VeltProvider context. */
112
+ veltClient?: Velt;
113
+ /** Initial text applied once for brand-new documents. */
114
+ initialContent?: string;
115
+ /** Reset shared content to initialContent during initialization. */
116
+ forceResetInitialContent?: boolean;
117
+ /** Cursor label/color data for this user's remote cursor. */
118
+ cursorData?: AceCursorData;
119
+ /** Ace Range constructor adapter used by the base manager for markers. */
120
+ rangeFactory?: AceRangeFactory;
121
+ /** Store debounce interval in ms. */
122
+ debounceMs?: number;
123
+ /** Set false to render Ace without creating the collaboration manager. */
124
+ enabled?: boolean;
125
+ /** Callback for non-fatal errors. */
126
+ onError?: (error: Error) => void;
127
+ /** Called whenever the sync connection status changes. */
128
+ onStatusChange?: (status: SyncStatus) => void;
129
+ /** Called once the base CollaborationManager is ready. */
130
+ onManagerReady?: (manager: CollaborationManager) => void;
131
+ /** Called with the Ace editor instance after react-ace loads. */
132
+ onEditorReady?: (editor: AceEditorLike) => void;
133
+ /** Original react-ace onLoad callback. */
134
+ onLoad?: (editor: AceEditorLike) => void;
135
+ /** Optional render prop for status/tooling around the editor. */
136
+ children?: (value: UseCollaborationReturn) => ReactNode;
137
+ }
138
+ export type CollaborationProviderProps = AceCrdtProviderProps;
139
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/types.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvD,OAAO,KAAK,kBAAkB,MAAM,WAAW,CAAC;AAChD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,KAAK,EACV,qBAAqB,EACrB,aAAa,EACb,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,IAAI,uBAAuB,EAC9C,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,WAAW,EACX,OAAO,EACR,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,qBAAqB,EACrB,aAAa,EACb,QAAQ,EACR,aAAa,EACb,WAAW,EACX,eAAe,EACf,iBAAiB,EACjB,iBAAiB,EACjB,oBAAoB,EACpB,uBAAuB,EACvB,kBAAkB,EAClB,eAAe,EACf,UAAU,EACV,WAAW,EACX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AElB,qCAAqC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;IAEjC,0DAA0D;IAC1D,cAAc,CAAC,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IAE9C,0DAA0D;IAC1D,cAAc,CAAC,EAAE,CAAC,OAAO,EAAE,oBAAoB,KAAK,IAAI,CAAC;IAEzD,iEAAiE;IACjE,aAAa,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAEhD,0CAA0C;IAC1C,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,aAAa,KAAK,IAAI,CAAC;IAEzC,iEAAiE;IACjE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,sBAAsB,KAAK,SAAS,CAAC;CACzD;AAED,MAAM,MAAM,0BAA0B,GAAG,oBAAoB,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { UseCollaborationConfig, UseCollaborationReturn } from './types';
2
+ export declare function useCollaboration(config: UseCollaborationConfig): UseCollaborationReturn;
3
+ //# sourceMappingURL=use-collaboration.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-collaboration.d.ts","sourceRoot":"","sources":["../../../src/use-collaboration.ts"],"names":[],"mappings":"AAmBA,OAAO,KAAK,EAAE,sBAAsB,EAAE,sBAAsB,EAAE,MAAM,SAAS,CAAC;AAuB9E,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,sBAAsB,CA+hBvF"}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Log an error/warning — only visible when debug mode is enabled
3
+ * via sessionStorage.setItem('forceCrdtDebugMode', 'true').
4
+ */
5
+ export declare function logError(message: string, error?: unknown): void;
6
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../../src/utils.ts"],"names":[],"mappings":"AAKA;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,OAAO,GAAG,IAAI,CAW/D"}
package/index.d.ts ADDED
@@ -0,0 +1,161 @@
1
+ import * as react from 'react';
2
+ import { ComponentProps, ReactNode } from 'react';
3
+ import AceEditorComponent from 'react-ace';
4
+ import { Velt } from '@veltdev/types';
5
+ import { AceCursorData, AceRangeFactory, SyncStatus, CollaborationManager, AceEditorLike, CollaborationPrimitives, Version, RemoteSelection, CollaborationStats, BindEditorOptions, AceAwarenessSelection, AceSelectionRange, CollaborationConfig as CollaborationConfig$1 } from '@veltdev/ace-crdt';
6
+ export { AceAwarenessSelection, AceCursorData, AceDelta, AceEditorLike, AcePosition, AceRangeFactory, AceSelectionRange, BindEditorOptions, CollaborationManager, CollaborationPrimitives, CollaborationStats, RemoteSelection, SyncStatus, Unsubscribe, Version, createCollaboration, indexToPosition, normalizeText, offsetsToRange, positionToIndex, rangeToOffsets } from '@veltdev/ace-crdt';
7
+
8
+ type CollaborationConfig = CollaborationConfig$1;
9
+ type ReactAceProps = ComponentProps<typeof AceEditorComponent>;
10
+ /**
11
+ * Hook configuration.
12
+ *
13
+ * Re-initialization is driven only by identity-relevant inputs: `editorId`,
14
+ * `veltClient`, the attached editor instance, `enabled`, and
15
+ * `initializeWithoutEditor`. The remaining fields inherited from the base
16
+ * config (`initialContent`, `forceResetInitialContent`, `cursorData`,
17
+ * `rangeFactory`, `debounceMs`, `onError`'s identity) are read once at
18
+ * initialization time — changing them later has no effect until the manager
19
+ * re-initializes.
20
+ */
21
+ interface UseCollaborationConfig extends Omit<CollaborationConfig$1, 'veltClient'> {
22
+ /** Optional Velt client override. Falls back to VeltProvider context. */
23
+ veltClient?: Velt;
24
+ /** Set false to render/capture the editor without creating collaboration. */
25
+ enabled?: boolean;
26
+ /**
27
+ * By default, `editor: null` delays manager initialization until Ace exists.
28
+ * Set this to true to initialize first and attach the editor later.
29
+ */
30
+ initializeWithoutEditor?: boolean;
31
+ }
32
+ interface UseCollaborationReturn {
33
+ /** Callback ref for react-ace onLoad or custom Ace creation. */
34
+ editorRef: (editor: AceEditorLike | null) => void;
35
+ /** Escape hatch to the base CollaborationManager. */
36
+ manager: CollaborationManager | null;
37
+ /** Currently attached Ace editor instance, if any. */
38
+ editor: AceEditorLike | null;
39
+ /** Lower-level Yjs/Velt primitives from the base manager. */
40
+ primitives: CollaborationPrimitives | null;
41
+ /** true until the CollaborationManager is initialized or fails. */
42
+ isLoading: boolean;
43
+ /** true after the first backend sync completes. */
44
+ synced: boolean;
45
+ /** Alias for `synced`, matching the other Velt React wrappers. */
46
+ isSynced: boolean;
47
+ /** Connection status from the base manager/provider. */
48
+ status: SyncStatus;
49
+ /** Non-null if initialization failed. */
50
+ error: Error | null;
51
+ /** Current shared text value from the base manager. */
52
+ value: string;
53
+ /** Latest saved versions list from the base manager. */
54
+ versions: Version[];
55
+ /** Latest remote text selections from awareness. */
56
+ remoteSelections: RemoteSelection[];
57
+ /** Snapshot of base manager statistics. */
58
+ stats: CollaborationStats | null;
59
+ /** Refresh React snapshots from the current base manager state. */
60
+ refreshSnapshots: () => void;
61
+ /** Attach an Ace editor to the current manager. */
62
+ attachEditor: (editor: AceEditorLike | null | undefined, options?: BindEditorOptions) => boolean;
63
+ /** Detach the current Ace editor from the manager. */
64
+ detachEditor: () => void;
65
+ /** Get the current shared text value. */
66
+ getValue: () => string;
67
+ /** Replace the shared text value. */
68
+ setValue: (value: string, reason?: string) => boolean;
69
+ /** Insert text at an index or current cursor. */
70
+ insertText: (value: string, index?: number) => boolean;
71
+ /** Flush the attached editor into the CRDT Store. */
72
+ flushEditorToStore: (reason?: string) => boolean;
73
+ /** Force the shared text state to initial content or supplied content. */
74
+ forceReset: (initialContent?: string) => Promise<boolean>;
75
+ /** Publish the current local selection through awareness. */
76
+ publishCurrentSelection: (kind?: AceAwarenessSelection['kind']) => boolean;
77
+ /** Set or clear the local awareness selection. */
78
+ setLocalSelection: (selection: Partial<AceAwarenessSelection> | null) => boolean;
79
+ /** Add a remote-awareness highlight marker for the current or supplied range. */
80
+ addHighlight: (range?: Partial<AceSelectionRange>, color?: string) => boolean;
81
+ /** Render remote selection/cursor/highlight markers in Ace. */
82
+ renderRemoteSelections: () => number;
83
+ /** Clear rendered remote markers. */
84
+ clearRemoteMarkers: () => void;
85
+ /** Undo through the base Y.UndoManager. */
86
+ undo: () => boolean;
87
+ /** Redo through the base Y.UndoManager. */
88
+ redo: () => boolean;
89
+ /** Save a named version and refresh the hook version list. */
90
+ saveVersion: (name: string) => Promise<string>;
91
+ /** Read saved versions without mutating hook state. */
92
+ getVersions: () => Promise<Version[]>;
93
+ /** Read a single saved version by id. */
94
+ getVersionById: (versionId: string) => Promise<Version | null>;
95
+ /** Refresh and store saved versions in hook state. */
96
+ refreshVersions: () => Promise<Version[]>;
97
+ /** Restore a version and refresh hook state. */
98
+ restoreVersion: (versionId: string) => Promise<boolean>;
99
+ /** Apply a Version object returned by the base package. */
100
+ setStateFromVersion: (version: Version) => Promise<void>;
101
+ /** Destroy the manager early. Also runs on unmount. */
102
+ destroy: () => void;
103
+ }
104
+ interface AceCrdtProviderProps {
105
+ config: UseCollaborationConfig;
106
+ children: ReactNode | ((value: UseCollaborationReturn) => ReactNode);
107
+ }
108
+ interface AceCrdtEditorProps extends Omit<ReactAceProps, 'value' | 'defaultValue' | 'onLoad'> {
109
+ /** Unique editor/document identifier for syncing. */
110
+ editorId?: string;
111
+ /** Convenience document identifier used as editorId when editorId is omitted. */
112
+ documentId?: string;
113
+ /** Optional Velt client override. Falls back to VeltProvider context. */
114
+ veltClient?: Velt;
115
+ /** Initial text applied once for brand-new documents. */
116
+ initialContent?: string;
117
+ /** Reset shared content to initialContent during initialization. */
118
+ forceResetInitialContent?: boolean;
119
+ /** Cursor label/color data for this user's remote cursor. */
120
+ cursorData?: AceCursorData;
121
+ /** Ace Range constructor adapter used by the base manager for markers. */
122
+ rangeFactory?: AceRangeFactory;
123
+ /** Store debounce interval in ms. */
124
+ debounceMs?: number;
125
+ /** Set false to render Ace without creating the collaboration manager. */
126
+ enabled?: boolean;
127
+ /** Callback for non-fatal errors. */
128
+ onError?: (error: Error) => void;
129
+ /** Called whenever the sync connection status changes. */
130
+ onStatusChange?: (status: SyncStatus) => void;
131
+ /** Called once the base CollaborationManager is ready. */
132
+ onManagerReady?: (manager: CollaborationManager) => void;
133
+ /** Called with the Ace editor instance after react-ace loads. */
134
+ onEditorReady?: (editor: AceEditorLike) => void;
135
+ /** Original react-ace onLoad callback. */
136
+ onLoad?: (editor: AceEditorLike) => void;
137
+ /** Optional render prop for status/tooling around the editor. */
138
+ children?: (value: UseCollaborationReturn) => ReactNode;
139
+ }
140
+ type CollaborationProviderProps = AceCrdtProviderProps;
141
+
142
+ declare const CollaborationContext: react.Context<UseCollaborationReturn | null>;
143
+ /**
144
+ * Context provider that runs useCollaboration once and shares the hook result
145
+ * with descendants. The context value is the hook's memoized return object, so
146
+ * consumers only re-render when collaboration state actually changes.
147
+ */
148
+ declare function AceCrdtProvider({ config, children }: AceCrdtProviderProps): react.JSX.Element | null;
149
+ declare const CollaborationProvider: typeof AceCrdtProvider;
150
+ /**
151
+ * Read the collaboration value shared by the nearest AceCrdtProvider.
152
+ * Returns null (never throws) when called outside a provider.
153
+ */
154
+ declare function useCollaborationContext(): UseCollaborationReturn | null;
155
+
156
+ declare function AceCrdtEditor(props: AceCrdtEditorProps): react.JSX.Element | null;
157
+
158
+ declare function useCollaboration(config: UseCollaborationConfig): UseCollaborationReturn;
159
+
160
+ export { AceCrdtEditor, AceCrdtProvider, CollaborationContext, CollaborationProvider, useCollaboration, useCollaborationContext };
161
+ export type { AceCrdtEditorProps, AceCrdtProviderProps, CollaborationConfig, CollaborationProviderProps, ReactAceProps, UseCollaborationConfig, UseCollaborationReturn };
package/package.json ADDED
@@ -0,0 +1,42 @@
1
+ {
2
+ "name": "@veltdev/ace-crdt-react",
3
+ "version": "1.0.0",
4
+ "description": "React hook and component wrapper for Ace CRDT collaboration over @veltdev/ace-crdt",
5
+ "homepage": "https://velt.dev",
6
+ "keywords": [
7
+ "velt",
8
+ "crdt",
9
+ "react",
10
+ "collaboration",
11
+ "ace",
12
+ "ace-builds",
13
+ "react-ace",
14
+ "yjs"
15
+ ],
16
+ "scripts": {
17
+ "version:update": "node ../update-npm-package.mjs",
18
+ "publish:crdt": "npm publish --access public"
19
+ },
20
+ "author": "Velt Inc.",
21
+ "license": "Proprietary",
22
+ "main": "cjs/index.js",
23
+ "module": "esm/index.js",
24
+ "types": "index.d.ts",
25
+ "peerDependencies": {
26
+ "@veltdev/ace-crdt": "^1.0.1",
27
+ "@veltdev/react": ">=5.0.2-beta.8 || >=6.0.0-0",
28
+ "@veltdev/types": ">=5.0.2-beta.8 || >=6.0.0-0",
29
+ "ace-builds": "^1.44.0",
30
+ "react": "^18.2.0 || ^19.0.0",
31
+ "react-ace": "^14.0.1",
32
+ "react-dom": "^18.2.0 || ^19.0.0"
33
+ },
34
+ "peerDependenciesMeta": {
35
+ "@veltdev/react": {
36
+ "optional": true
37
+ },
38
+ "@veltdev/types": {
39
+ "optional": true
40
+ }
41
+ }
42
+ }