Skip to content

Commit 09788ae

Browse files
committed
refactor: fix circular dependency
1 parent d3481fd commit 09788ae

File tree

6 files changed

+62
-64
lines changed

6 files changed

+62
-64
lines changed

src/cursor-plugin.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
type LoroNodeMapping,
2222
WEAK_NODE_TO_LORO_CONTAINER_MAPPING,
2323
} from "./lib";
24-
import { loroSyncPluginKey, type LoroSyncPluginState } from "./sync-plugin";
24+
import { loroSyncPluginKey, type LoroSyncPluginState } from "./sync-plugin-key";
2525

2626
const loroCursorPluginKey = new PluginKey<{ awarenessUpdated: boolean }>(
2727
"loro-cursor",

src/index.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
export { LoroSyncPlugin } from "./sync-plugin";
12
export {
2-
LoroSyncPlugin,
33
loroSyncPluginKey,
44
type LoroSyncPluginProps,
55
type LoroSyncPluginState,
6-
} from "./sync-plugin";
6+
} from "./sync-plugin-key";
77
export {
88
createNodeFromLoroObj,
99
updateLoroToPmState,
@@ -21,12 +21,5 @@ export {
2121
} from "./lib";
2222
export { LoroCursorPlugin } from "./cursor-plugin";
2323
export { CursorAwareness } from "./awareness";
24-
export {
25-
LoroUndoPlugin,
26-
loroUndoPluginKey,
27-
type LoroUndoPluginProps,
28-
undo,
29-
redo,
30-
canUndo,
31-
canRedo,
32-
} from "./undo-plugin";
24+
export { LoroUndoPlugin, undo, redo, canUndo, canRedo } from "./undo-plugin";
25+
export { loroUndoPluginKey, type LoroUndoPluginProps } from "./undo-plugin-key";

src/sync-plugin-key.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { ContainerID, LoroDoc, Subscription } from "loro-crdt";
2+
import { PluginKey } from "prosemirror-state";
3+
import type { EditorView } from "prosemirror-view";
4+
import type { LoroDocType, LoroNodeMapping } from "./lib";
5+
6+
export const loroSyncPluginKey = new PluginKey<LoroSyncPluginState>(
7+
"loro-sync",
8+
);
9+
10+
export interface LoroSyncPluginProps {
11+
doc: LoroDocType;
12+
mapping?: LoroNodeMapping;
13+
containerId?: ContainerID;
14+
}
15+
16+
export interface LoroSyncPluginState extends LoroSyncPluginProps {
17+
changedBy: "local" | "import" | "checkout";
18+
mapping: LoroNodeMapping;
19+
snapshot?: LoroDoc | null;
20+
view?: EditorView;
21+
containerId?: ContainerID;
22+
docSubscription?: Subscription | null;
23+
}

src/sync-plugin.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,6 @@
1-
import type {
2-
ContainerID,
3-
Cursor,
4-
LoroDoc,
5-
LoroEventBatch,
6-
LoroMap,
7-
Subscription,
8-
} from "loro-crdt";
1+
import type { Cursor, LoroEventBatch, LoroMap } from "loro-crdt";
92
import { Fragment, Slice } from "prosemirror-model";
10-
import {
11-
type EditorState,
12-
Plugin,
13-
PluginKey,
14-
type StateField,
15-
} from "prosemirror-state";
3+
import { type EditorState, Plugin, type StateField } from "prosemirror-state";
164
import type { EditorView } from "prosemirror-view";
175

186
import {
@@ -29,12 +17,13 @@ import {
2917
safeSetSelection,
3018
updateLoroToPmState,
3119
} from "./lib";
20+
import {
21+
loroSyncPluginKey,
22+
type LoroSyncPluginProps,
23+
type LoroSyncPluginState,
24+
} from "./sync-plugin-key";
3225
import { configLoroTextStyle } from "./text-style";
33-
import { loroUndoPluginKey } from "./undo-plugin";
34-
35-
export const loroSyncPluginKey = new PluginKey<LoroSyncPluginState>(
36-
"loro-sync",
37-
);
26+
import { loroUndoPluginKey } from "./undo-plugin-key";
3827

3928
type PluginTransactionType =
4029
| {
@@ -48,21 +37,6 @@ type PluginTransactionType =
4837
state: Partial<LoroSyncPluginState>;
4938
};
5039

51-
export interface LoroSyncPluginProps {
52-
doc: LoroDocType;
53-
mapping?: LoroNodeMapping;
54-
containerId?: ContainerID;
55-
}
56-
57-
export interface LoroSyncPluginState extends LoroSyncPluginProps {
58-
changedBy: "local" | "import" | "checkout";
59-
mapping: LoroNodeMapping;
60-
snapshot?: LoroDoc | null;
61-
view?: EditorView;
62-
containerId?: ContainerID;
63-
docSubscription?: Subscription | null;
64-
}
65-
6640
export const LoroSyncPlugin = (props: LoroSyncPluginProps): Plugin => {
6741
return new Plugin({
6842
key: loroSyncPluginKey,

src/undo-plugin-key.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import type { LoroDoc, UndoManager } from "loro-crdt";
2+
import { PluginKey } from "prosemirror-state";
3+
4+
export const loroUndoPluginKey = new PluginKey<LoroUndoPluginState>(
5+
"loro-undo",
6+
);
7+
8+
export interface LoroUndoPluginProps {
9+
doc: LoroDoc;
10+
undoManager?: UndoManager;
11+
}
12+
13+
export interface LoroUndoPluginState {
14+
undoManager: UndoManager;
15+
canUndo: boolean;
16+
canRedo: boolean;
17+
isUndoing: { current: boolean };
18+
}

src/undo-plugin.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,22 @@
11
import type { Cursor } from "loro-crdt";
2-
import { LoroDoc, UndoManager } from "loro-crdt";
2+
import { UndoManager } from "loro-crdt";
33
import {
44
type Command,
55
EditorState,
66
Plugin,
7-
PluginKey,
87
type StateField,
98
} from "prosemirror-state";
109
import { EditorView } from "prosemirror-view";
1110
import { convertPmSelectionToCursors } from "./cursor-plugin";
12-
import { loroSyncPluginKey, syncCursorsToPmSelection } from "./sync-plugin";
11+
import { syncCursorsToPmSelection } from "./sync-plugin";
12+
import { loroSyncPluginKey } from "./sync-plugin-key";
1313
import { configLoroTextStyle } from "./text-style";
14+
import {
15+
loroUndoPluginKey,
16+
type LoroUndoPluginProps,
17+
type LoroUndoPluginState,
18+
} from "./undo-plugin-key";
1419

15-
export interface LoroUndoPluginProps {
16-
doc: LoroDoc;
17-
undoManager?: UndoManager;
18-
}
19-
20-
export const loroUndoPluginKey = new PluginKey<LoroUndoPluginState>(
21-
"loro-undo",
22-
);
23-
24-
interface LoroUndoPluginState {
25-
undoManager: UndoManager;
26-
canUndo: boolean;
27-
canRedo: boolean;
28-
isUndoing: { current: boolean };
29-
}
3020
type Cursors = { anchor: Cursor | null; focus: Cursor | null };
3121
export const LoroUndoPlugin = (props: LoroUndoPluginProps): Plugin => {
3222
const undoManager = props.undoManager || new UndoManager(props.doc, {});

0 commit comments

Comments
 (0)