@kerebron/yjs 0.0.0-stage → 0.9.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +23 -0
- package/README.md +4 -2
- package/esm/ExtensionYjs.d.ts +19 -0
- package/esm/ExtensionYjs.js +144 -0
- package/esm/ExtensionYjs.js.map +1 -0
- package/esm/MarkYChange.d.ts +6 -0
- package/esm/MarkYChange.js +21 -0
- package/esm/MarkYChange.js.map +1 -0
- package/esm/WebsocketProvider.d.ts +69 -0
- package/esm/WebsocketProvider.js +377 -0
- package/esm/WebsocketProvider.js.map +1 -0
- package/esm/YjsEditorKit.d.ts +10 -0
- package/esm/YjsEditorKit.js +44 -0
- package/esm/YjsEditorKit.js.map +1 -0
- package/esm/YjsProvider.d.ts +47 -0
- package/esm/YjsProvider.js +12 -0
- package/esm/YjsProvider.js.map +1 -0
- package/esm/binding/BindingMetadata.d.ts +5 -0
- package/esm/binding/BindingMetadata.js +2 -0
- package/esm/binding/BindingMetadata.js.map +1 -0
- package/esm/binding/DiffViewer.d.ts +16 -0
- package/esm/binding/DiffViewer.js +95 -0
- package/esm/binding/DiffViewer.js.map +1 -0
- package/esm/binding/PmYjsBinding.d.ts +46 -0
- package/esm/binding/PmYjsBinding.js +246 -0
- package/esm/binding/PmYjsBinding.js.map +1 -0
- package/esm/binding/convertUtils.d.ts +47 -0
- package/esm/binding/convertUtils.js +80 -0
- package/esm/binding/convertUtils.js.map +1 -0
- package/esm/binding/createNodeFromYElement.d.ts +9 -0
- package/esm/binding/createNodeFromYElement.js +123 -0
- package/esm/binding/createNodeFromYElement.js.map +1 -0
- package/esm/binding/updateYFragment.d.ts +16 -0
- package/esm/binding/updateYFragment.js +337 -0
- package/esm/binding/updateYFragment.js.map +1 -0
- package/esm/debug.d.ts +12 -0
- package/esm/debug.js +158 -0
- package/esm/debug.js.map +1 -0
- package/esm/keys.d.ts +7 -0
- package/esm/keys.js +5 -0
- package/esm/keys.js.map +1 -0
- package/esm/lib.d.ts +7 -0
- package/esm/lib.js +2 -0
- package/esm/lib.js.map +1 -0
- package/esm/package.json +3 -0
- package/esm/position.d.ts +7 -0
- package/esm/position.js +165 -0
- package/esm/position.js.map +1 -0
- package/esm/ui/RoomController.d.ts +16 -0
- package/esm/ui/RoomController.js +115 -0
- package/esm/ui/RoomController.js.map +1 -0
- package/esm/ui/selection.d.ts +28 -0
- package/esm/ui/selection.js +128 -0
- package/esm/ui/selection.js.map +1 -0
- package/esm/utils.d.ts +3 -0
- package/esm/utils.js +15 -0
- package/esm/utils.js.map +1 -0
- package/esm/yPositionPlugin.d.ts +26 -0
- package/esm/yPositionPlugin.js +216 -0
- package/esm/yPositionPlugin.js.map +1 -0
- package/esm/ySyncPlugin.d.ts +22 -0
- package/esm/ySyncPlugin.js +140 -0
- package/esm/ySyncPlugin.js.map +1 -0
- package/esm/yUndoPlugin.d.ts +22 -0
- package/esm/yUndoPlugin.js +128 -0
- package/esm/yUndoPlugin.js.map +1 -0
- package/package.json +53 -3
- package/src/ExtensionYjs.ts +204 -0
- package/src/MarkYChange.ts +23 -0
- package/src/WebsocketProvider.ts +528 -0
- package/src/YjsEditorKit.ts +58 -0
- package/src/YjsProvider.ts +75 -0
- package/src/binding/BindingMetadata.ts +6 -0
- package/src/binding/DiffViewer.ts +138 -0
- package/src/binding/PmYjsBinding.ts +383 -0
- package/src/binding/convertUtils.ts +124 -0
- package/src/binding/createNodeFromYElement.ts +175 -0
- package/src/binding/updateYFragment.ts +447 -0
- package/src/debug.ts +239 -0
- package/src/keys.ts +14 -0
- package/src/lib.ts +12 -0
- package/src/position.ts +191 -0
- package/src/ui/RoomController.ts +131 -0
- package/src/ui/selection.ts +217 -0
- package/src/utils.ts +19 -0
- package/src/yPositionPlugin.ts +351 -0
- package/src/ySyncPlugin.ts +211 -0
- package/src/yUndoPlugin.ts +175 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
Permission is hereby granted, free of charge, to any
|
|
2
|
+
person obtaining a copy of this software and associated
|
|
3
|
+
documentation files (the "Software"), to deal in the
|
|
4
|
+
Software without restriction, including without
|
|
5
|
+
limitation the rights to use, copy, modify, merge,
|
|
6
|
+
publish, distribute, sublicense, and/or sell copies of
|
|
7
|
+
the Software, and to permit persons to whom the Software
|
|
8
|
+
is furnished to do so, subject to the following
|
|
9
|
+
conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice
|
|
12
|
+
shall be included in all copies or substantial portions
|
|
13
|
+
of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF
|
|
16
|
+
ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
|
|
17
|
+
TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
18
|
+
PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
|
|
19
|
+
SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
20
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
|
|
22
|
+
IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
23
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
# Temporary Holding Version
|
|
2
1
|
|
|
3
|
-
|
|
2
|
+
# Debugging:
|
|
3
|
+
|
|
4
|
+
* ydoc => pm Event - grep for: yXmlChanged
|
|
5
|
+
* pm => ydoc Event - grep for: prosemirrorChanged
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Plugin } from 'prosemirror-state';
|
|
2
|
+
import { Extension } from '@kerebron/editor';
|
|
3
|
+
import type { CommandFactories, CommandShortcuts } from '@kerebron/editor/commands';
|
|
4
|
+
import type { CreateYjsProvider } from './YjsProvider.js';
|
|
5
|
+
export interface YjsConfig {
|
|
6
|
+
createYjsProvider?: CreateYjsProvider;
|
|
7
|
+
addMenu?: boolean;
|
|
8
|
+
}
|
|
9
|
+
export declare class ExtensionYjs extends Extension {
|
|
10
|
+
config: YjsConfig;
|
|
11
|
+
name: string;
|
|
12
|
+
overrides: string[];
|
|
13
|
+
requires: string[];
|
|
14
|
+
constructor(config: YjsConfig);
|
|
15
|
+
getCommandFactories(): Partial<CommandFactories>;
|
|
16
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
17
|
+
getProseMirrorPlugins(): Plugin[];
|
|
18
|
+
created(): void;
|
|
19
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { Extension } from '@kerebron/editor';
|
|
2
|
+
import { icons } from '@kerebron/ui/icons';
|
|
3
|
+
import { ySyncPlugin } from './ySyncPlugin.js';
|
|
4
|
+
import { yPositionPlugin } from './yPositionPlugin.js';
|
|
5
|
+
import { redoCommand, undoCommand, yUndoPlugin } from './yUndoPlugin.js';
|
|
6
|
+
import { ySyncPluginKey } from './keys.js';
|
|
7
|
+
import { RoomController } from './ui/RoomController.js';
|
|
8
|
+
export class ExtensionYjs extends Extension {
|
|
9
|
+
config;
|
|
10
|
+
name = 'yjs';
|
|
11
|
+
overrides = ['history'];
|
|
12
|
+
requires = ['remote-selection'];
|
|
13
|
+
constructor(config) {
|
|
14
|
+
super();
|
|
15
|
+
this.config = config;
|
|
16
|
+
}
|
|
17
|
+
getCommandFactories() {
|
|
18
|
+
const changeRoom = (roomId) => {
|
|
19
|
+
return (state, dispatch) => {
|
|
20
|
+
const tr = state.tr;
|
|
21
|
+
tr.setMeta(ySyncPluginKey, { changeRoom: { roomId } });
|
|
22
|
+
if (dispatch) {
|
|
23
|
+
dispatch(tr);
|
|
24
|
+
}
|
|
25
|
+
return true;
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
const leaveRoom = () => {
|
|
29
|
+
return (state, dispatch) => {
|
|
30
|
+
const tr = state.tr;
|
|
31
|
+
tr.setMeta(ySyncPluginKey, { leaveRoom: true });
|
|
32
|
+
if (dispatch) {
|
|
33
|
+
dispatch(tr);
|
|
34
|
+
}
|
|
35
|
+
return true;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const getYDoc = ({ resolve, reject }) => {
|
|
39
|
+
return (state, dispatch) => {
|
|
40
|
+
const tr = state.tr;
|
|
41
|
+
tr.setMeta(ySyncPluginKey, { getYDoc: { resolve, reject } });
|
|
42
|
+
if (dispatch) {
|
|
43
|
+
dispatch(tr);
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
const getYSnapshot = ({ resolve, reject }) => {
|
|
49
|
+
return (state, dispatch) => {
|
|
50
|
+
const tr = state.tr;
|
|
51
|
+
tr.setMeta(ySyncPluginKey, { getYSnapshot: { resolve, reject } });
|
|
52
|
+
if (dispatch) {
|
|
53
|
+
dispatch(tr);
|
|
54
|
+
}
|
|
55
|
+
return true;
|
|
56
|
+
};
|
|
57
|
+
};
|
|
58
|
+
const setYSnapshot = (opts) => {
|
|
59
|
+
return (state, dispatch) => {
|
|
60
|
+
const tr = state.tr;
|
|
61
|
+
tr.setMeta(ySyncPluginKey, { setYSnapshot: opts });
|
|
62
|
+
if (dispatch) {
|
|
63
|
+
dispatch(tr);
|
|
64
|
+
}
|
|
65
|
+
return true;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const resetYSnapshot = () => {
|
|
69
|
+
return (state, dispatch) => {
|
|
70
|
+
const tr = state.tr;
|
|
71
|
+
tr.setMeta(ySyncPluginKey, { resetYSnapshot: true });
|
|
72
|
+
if (dispatch) {
|
|
73
|
+
dispatch(tr);
|
|
74
|
+
}
|
|
75
|
+
return true;
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
return {
|
|
79
|
+
getYDoc,
|
|
80
|
+
changeRoom,
|
|
81
|
+
leaveRoom,
|
|
82
|
+
'undo': () => undoCommand,
|
|
83
|
+
'redo': () => redoCommand,
|
|
84
|
+
getYSnapshot,
|
|
85
|
+
setYSnapshot,
|
|
86
|
+
resetYSnapshot,
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
getKeyboardShortcuts() {
|
|
90
|
+
return {
|
|
91
|
+
'Mod-z': 'undo',
|
|
92
|
+
'Mod-y': 'redo',
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
getProseMirrorPlugins() {
|
|
96
|
+
return [
|
|
97
|
+
ySyncPlugin(this.editor, this.config.createYjsProvider),
|
|
98
|
+
yPositionPlugin(this.editor),
|
|
99
|
+
yUndoPlugin(),
|
|
100
|
+
];
|
|
101
|
+
}
|
|
102
|
+
created() {
|
|
103
|
+
if (this.config.addMenu) {
|
|
104
|
+
const ui = this.editor.ci.resolve('ui');
|
|
105
|
+
const controller = new RoomController();
|
|
106
|
+
this.editor.addEventListener('ready', () => {
|
|
107
|
+
const menuFile = {
|
|
108
|
+
type: 'item',
|
|
109
|
+
id: 'yjs-room',
|
|
110
|
+
title: 'YJS Room',
|
|
111
|
+
icon: icons.user,
|
|
112
|
+
action: async (_editor) => {
|
|
113
|
+
const popup = ui.createPopup({
|
|
114
|
+
anchorId: '--menuitem-more-tools',
|
|
115
|
+
layer: 'toplayer',
|
|
116
|
+
group: 'menu',
|
|
117
|
+
});
|
|
118
|
+
popup.addEventListener('remove', () => {
|
|
119
|
+
// popup = undefined;
|
|
120
|
+
});
|
|
121
|
+
controller.bindEvents(popup);
|
|
122
|
+
await controller.init();
|
|
123
|
+
const templates = this.editor.ci.resolve('templates');
|
|
124
|
+
const renderForm = () => {
|
|
125
|
+
ui.setPopupContent(popup, templates['room-selector'](controller));
|
|
126
|
+
};
|
|
127
|
+
renderForm();
|
|
128
|
+
controller.addEventListener('change-room', (event) => {
|
|
129
|
+
renderForm();
|
|
130
|
+
popup.remove();
|
|
131
|
+
});
|
|
132
|
+
controller.addEventListener('change-user', (event) => {
|
|
133
|
+
renderForm();
|
|
134
|
+
popup.remove();
|
|
135
|
+
});
|
|
136
|
+
return true;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
this.editor.run.addMenuItem(menuFile, 0, 'tray');
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=ExtensionYjs.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionYjs.js","sourceRoot":"","sources":["../src/ExtensionYjs.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAO7C,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAG3C,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAI3C,OAAO,EAAE,cAAc,EAAE,MAAM,wBAAwB,CAAC;AAOxD,MAAM,OAAO,YAAa,SAAQ,SAAS;IAMb;IAL5B,IAAI,GAAG,KAAK,CAAC;IAEJ,SAAS,GAAG,CAAC,SAAS,CAAC,CAAC;IACjC,QAAQ,GAAG,CAAC,kBAAkB,CAAC,CAAC;IAEhC,YAA4B,MAAiB;QAC3C,KAAK,EAAE,CAAC;QADkB,WAAM,GAAN,MAAM,CAAW;IAE7C,CAAC;IAEQ,mBAAmB;QAC1B,MAAM,UAAU,GAAmB,CAAC,MAAc,EAAE,EAAE;YACpD,OAAO,CAAC,KAAkB,EAAE,QAAoC,EAAE,EAAE;gBAClE,MAAM,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;gBACpB,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,UAAU,EAAE,EAAE,MAAM,EAAE,EAAE,CAA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,CAAC,KAAK,EAAE,EAAE;4BACnD,UAAU,EAAE,CAAC;4BACb,KAAK,CAAC,MAAM,EAAE,CAAC;wBACjB,CAAC,CAAC,CAAC;wBACH,UAAU,CAAC,gBAAgB,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;4BACnD,UAAU,EAAE,CAAC;4BACb,KAAK,CAAC,MAAM,EAAE,CAAC;wBACjB,CAAC,CAAC,CAAC;wBAEH,OAAO,IAAI,CAAC;oBACd,CAAC;iBACF,CAAC;gBAEF,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC;YACnD,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Mark } from '@kerebron/editor';
|
|
2
|
+
export class MarkYChange extends Mark {
|
|
3
|
+
name = 'ychange';
|
|
4
|
+
getMarkSpec() {
|
|
5
|
+
return {
|
|
6
|
+
attrs: {
|
|
7
|
+
user: { default: null },
|
|
8
|
+
type: { default: null },
|
|
9
|
+
},
|
|
10
|
+
inclusive: false,
|
|
11
|
+
parseDOM: [{ tag: 'ychange' }],
|
|
12
|
+
toDOM(node) {
|
|
13
|
+
return ['ychange', {
|
|
14
|
+
ychange_user: node.attrs.user,
|
|
15
|
+
ychange_type: node.attrs.type,
|
|
16
|
+
}];
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=MarkYChange.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MarkYChange.js","sourceRoot":"","sources":["../src/MarkYChange.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,MAAM,kBAAkB,CAAC;AAExC,MAAM,OAAO,WAAY,SAAQ,IAAI;IAC1B,IAAI,GAAG,SAAS,CAAC;IAEjB,WAAW;QAClB,OAAO;YACL,KAAK,EAAE;gBACL,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;gBACvB,IAAI,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE;aACxB;YACD,SAAS,EAAE,KAAK;YAChB,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,SAAS,EAAE,CAAC;YAC9B,KAAK,CAAC,IAAI;gBACR,OAAO,CAAC,SAAS,EAAE;wBACjB,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;wBAC7B,YAAY,EAAE,IAAI,CAAC,KAAK,CAAC,IAAI;qBAC9B,CAAC,CAAC;YACL,CAAC;SACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as Y from 'yjs';
|
|
2
|
+
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
3
|
+
import { MessageHandler, YjsProvider } from './YjsProvider.js';
|
|
4
|
+
interface WebsocketProviderOpts {
|
|
5
|
+
connect: boolean;
|
|
6
|
+
awareness: awarenessProtocol.Awareness;
|
|
7
|
+
params: Record<string, string>;
|
|
8
|
+
protocols: Array<string>;
|
|
9
|
+
WebSocketPolyfill: typeof WebSocket;
|
|
10
|
+
resyncInterval: number;
|
|
11
|
+
maxBackoffTime: number;
|
|
12
|
+
disableBc: boolean;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Websocket Provider for Yjs. Creates a websocket connection to sync the shared document.
|
|
16
|
+
* The document name is attached to the provided url. I.e. the following example
|
|
17
|
+
* creates a websocket connection to http://localhost:1234/my-document-name
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* import * as Y from 'yjs'
|
|
21
|
+
* import { WebsocketProvider } from '@kerebron/yjs/WebsocketProvider'
|
|
22
|
+
* const doc = new Y.Doc()
|
|
23
|
+
* const provider = new WebsocketProvider('http://localhost:1234', 'my-document-name', doc)
|
|
24
|
+
*/
|
|
25
|
+
export declare class WebsocketProvider extends EventTarget implements YjsProvider {
|
|
26
|
+
roomname: string;
|
|
27
|
+
doc: Y.Doc;
|
|
28
|
+
_synced: boolean;
|
|
29
|
+
shouldConnect: boolean;
|
|
30
|
+
ws: WebSocket | undefined;
|
|
31
|
+
_resyncInterval: number;
|
|
32
|
+
serverUrl: string;
|
|
33
|
+
bcChannel: string;
|
|
34
|
+
maxBackoffTime: number;
|
|
35
|
+
/**
|
|
36
|
+
* The specified url parameters. This can be safely updated. The changed parameters will be used
|
|
37
|
+
* when a new connection is established.
|
|
38
|
+
*/
|
|
39
|
+
params: Record<string, string>;
|
|
40
|
+
protocols: string[];
|
|
41
|
+
_WS: typeof WebSocket;
|
|
42
|
+
awareness: awarenessProtocol.Awareness;
|
|
43
|
+
destroyed: boolean;
|
|
44
|
+
wsconnected: boolean;
|
|
45
|
+
wsconnecting: boolean;
|
|
46
|
+
bcconnected: boolean;
|
|
47
|
+
disableBc: boolean;
|
|
48
|
+
wsUnsuccessfulReconnects: number;
|
|
49
|
+
messageHandlers: MessageHandler<WebsocketProvider>[];
|
|
50
|
+
wsLastMessageReceived: number;
|
|
51
|
+
readonly bc: BroadcastChannel;
|
|
52
|
+
private _bcSubscriber;
|
|
53
|
+
private _updateHandler;
|
|
54
|
+
private _awarenessUpdateHandler;
|
|
55
|
+
private _exitHandler;
|
|
56
|
+
private _checkInterval;
|
|
57
|
+
setupWSTimeout: number | undefined;
|
|
58
|
+
constructor(serverUrl: string, roomname: string, doc: Y.Doc, opts?: WebsocketProviderOpts);
|
|
59
|
+
get url(): string;
|
|
60
|
+
get synced(): boolean;
|
|
61
|
+
set synced(state: boolean);
|
|
62
|
+
destroy(): void;
|
|
63
|
+
connectBc(): void;
|
|
64
|
+
disconnectBc(): void;
|
|
65
|
+
disconnect(): void;
|
|
66
|
+
connect(): void;
|
|
67
|
+
private setupMessageHandlers;
|
|
68
|
+
}
|
|
69
|
+
export {};
|