@kerebron/extension-yjs 0.0.1
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 +34 -0
- package/esm/ExtensionYjs.d.ts +12 -0
- package/esm/ExtensionYjs.d.ts.map +1 -0
- package/esm/ExtensionYjs.js +44 -0
- package/esm/SyncPlugin.d.ts +83 -0
- package/esm/SyncPlugin.d.ts.map +1 -0
- package/esm/SyncPlugin.js +923 -0
- package/esm/package.json +3 -0
- package/esm/yCursorPlugin.d.ts +42 -0
- package/esm/yCursorPlugin.d.ts.map +1 -0
- package/esm/yCursorPlugin.js +169 -0
- package/package.json +15 -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
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
# Kerebron - Prosemirror based online editor kit
|
|
2
|
+
|
|
3
|
+
Using vanilla Prosemirror modules is often impossible because of incompatibilities.
|
|
4
|
+
|
|
5
|
+
Kerebron forks several prosemirror projects into one monorepo in order to keep them in sync.
|
|
6
|
+
|
|
7
|
+
Project is inspired on https://tiptap.dev/, but instead of building wrapper around a wrapper it borrows concept of extension and command manager.
|
|
8
|
+
|
|
9
|
+
It has simplified tooling (deno), fewer dependencies and resulting in lower number of output npm modules.
|
|
10
|
+
|
|
11
|
+
**Work in progress**
|
|
12
|
+
|
|
13
|
+
## Development
|
|
14
|
+
|
|
15
|
+
To start example server:
|
|
16
|
+
|
|
17
|
+
```
|
|
18
|
+
deno task -f example-server-hono start
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## Build
|
|
22
|
+
|
|
23
|
+
# NPM packages are generated using DNT
|
|
24
|
+
|
|
25
|
+
- https://deno.com/blog/publish-esm-cjs-module-dnt - the easiest way to publish
|
|
26
|
+
a hybrid npm module for ESM and CommonJS
|
|
27
|
+
- https://github.com/denoland/dnt
|
|
28
|
+
- https://gaubee.com/article/Publishing-Your-Deno-Project-as-a-Monorepo-using-dnt/
|
|
29
|
+
|
|
30
|
+
To generate npm packages
|
|
31
|
+
|
|
32
|
+
```shell
|
|
33
|
+
deno -A ./scripts/build_npm.ts
|
|
34
|
+
```
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Schema } from 'prosemirror-model';
|
|
2
|
+
import { Plugin } from 'prosemirror-state';
|
|
3
|
+
import { CoreEditor, Extension } from '@kerebron/editor';
|
|
4
|
+
import { Commands, CommandShortcuts } from '@kerebron/editor/commands';
|
|
5
|
+
export declare class ExtensionYjs extends Extension {
|
|
6
|
+
name: string;
|
|
7
|
+
doc: any;
|
|
8
|
+
getCommands(editor: CoreEditor): Partial<Commands>;
|
|
9
|
+
getKeyboardShortcuts(): Partial<CommandShortcuts>;
|
|
10
|
+
getProseMirrorPlugins(editor: CoreEditor, schema: Schema): Plugin[];
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ExtensionYjs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtensionYjs.d.ts","sourceRoot":"","sources":["../src/ExtensionYjs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAY,MAAM,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAGzD,OAAO,EAAE,QAAQ,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AAIvE,qBAAa,YAAa,SAAQ,SAAS;IACzC,IAAI,SAAS;IACb,GAAG,EAAE,GAAG,CAAC;IAGA,WAAW,CAAC,MAAM,EAAE,UAAU,GAAG,OAAO,CAAC,QAAQ,CAAC;IAOlD,oBAAoB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAOjD,qBAAqB,CAAC,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE;CAY7E"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Extension } from '@kerebron/editor';
|
|
2
|
+
import { initProseMirrorDoc, redo, undo, yUndoPlugin } from 'y-prosemirror';
|
|
3
|
+
import { ySyncPlugin } from './SyncPlugin.js';
|
|
4
|
+
import { yCursorPlugin } from './yCursorPlugin.js';
|
|
5
|
+
export class ExtensionYjs extends Extension {
|
|
6
|
+
constructor() {
|
|
7
|
+
super(...arguments);
|
|
8
|
+
Object.defineProperty(this, "name", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
configurable: true,
|
|
11
|
+
writable: true,
|
|
12
|
+
value: 'yjs'
|
|
13
|
+
});
|
|
14
|
+
Object.defineProperty(this, "doc", {
|
|
15
|
+
enumerable: true,
|
|
16
|
+
configurable: true,
|
|
17
|
+
writable: true,
|
|
18
|
+
value: void 0
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
// declare type Command = (state: EditorState, dispatch?: (tr: Transaction) => void, view?: EditorView) => boolean;
|
|
22
|
+
getCommands(editor) {
|
|
23
|
+
return {
|
|
24
|
+
'undo': () => undo,
|
|
25
|
+
'redo': () => redo,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
getKeyboardShortcuts() {
|
|
29
|
+
return {
|
|
30
|
+
'Mod-z': 'undo',
|
|
31
|
+
'Mod-y': 'redo',
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
getProseMirrorPlugins(editor, schema) {
|
|
35
|
+
const ydoc = this.config.ydoc;
|
|
36
|
+
const fragment = ydoc.getXmlFragment('prosemirror');
|
|
37
|
+
const { mapping } = initProseMirrorDoc(fragment, schema);
|
|
38
|
+
return [
|
|
39
|
+
ySyncPlugin(fragment, { mapping }),
|
|
40
|
+
yCursorPlugin(this.config.provider.awareness),
|
|
41
|
+
yUndoPlugin(),
|
|
42
|
+
];
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import * as PModel from 'prosemirror-model';
|
|
2
|
+
import * as Y from 'yjs';
|
|
3
|
+
import { mutex } from 'lib0/mutex';
|
|
4
|
+
import { EditorView } from 'prosemirror-view';
|
|
5
|
+
import { ProsemirrorMapping } from 'y-prosemirror';
|
|
6
|
+
import { YSyncOpts } from 'y-prosemirror';
|
|
7
|
+
/**
|
|
8
|
+
* @param {Y.Item} item
|
|
9
|
+
* @param {Y.Snapshot} [snapshot]
|
|
10
|
+
*/
|
|
11
|
+
export declare const isVisible: (item: any, snapshot: any) => any;
|
|
12
|
+
export declare const ySyncPlugin: (yXmlFragment: Y.XmlFragment, { colors, colorMapping, permanentUserData, onFirstRender, mapping, }?: YSyncOpts) => any;
|
|
13
|
+
export declare const getRelativeSelection: (pmbinding: any, state: any) => {
|
|
14
|
+
anchor: any;
|
|
15
|
+
head: any;
|
|
16
|
+
};
|
|
17
|
+
/**
|
|
18
|
+
* Binding for prosemirror.
|
|
19
|
+
*
|
|
20
|
+
* @protected
|
|
21
|
+
*/
|
|
22
|
+
export declare class ProsemirrorBinding {
|
|
23
|
+
private yXmlFragment;
|
|
24
|
+
private mapping;
|
|
25
|
+
type: Y.XmlFragment;
|
|
26
|
+
mux: mutex;
|
|
27
|
+
private _observeFunction;
|
|
28
|
+
private prosemirrorView;
|
|
29
|
+
private doc;
|
|
30
|
+
beforeTransactionSelection: {
|
|
31
|
+
anchor: any;
|
|
32
|
+
head: any;
|
|
33
|
+
};
|
|
34
|
+
afterAllTransactions: () => void;
|
|
35
|
+
beforeAllTransactions: (arg0: Y.Doc) => void;
|
|
36
|
+
constructor(yXmlFragment: Y.XmlFragment, mapping?: ProsemirrorMapping);
|
|
37
|
+
/**
|
|
38
|
+
* Create a transaction for changing the prosemirror state.
|
|
39
|
+
*
|
|
40
|
+
* @returns
|
|
41
|
+
*/
|
|
42
|
+
get _tr(): any;
|
|
43
|
+
_isLocalCursorInView(): any;
|
|
44
|
+
_isDomSelectionInView(): boolean;
|
|
45
|
+
renderSnapshot(snapshot: Y.Snapshot, prevSnapshot: Y.Snapshot): void;
|
|
46
|
+
unrenderSnapshot(): void;
|
|
47
|
+
_forceRerender(): void;
|
|
48
|
+
_renderSnapshot(snapshot: Y.Snapshot | Uint8Array, prevSnapshot: Y.Snapshot | Uint8Array, pluginState: Object): void;
|
|
49
|
+
_typeChanged(events: Array<Y.YEvent<any>>, transaction: Y.Transaction): void;
|
|
50
|
+
_prosemirrorChanged(doc: any): void;
|
|
51
|
+
/**
|
|
52
|
+
* View is ready to listen to changes. Register observers.
|
|
53
|
+
* @param {any} prosemirrorView
|
|
54
|
+
*/
|
|
55
|
+
initView(prosemirrorView: EditorView): void;
|
|
56
|
+
destroy(): void;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* @private
|
|
60
|
+
* @param {Y.XmlElement} el
|
|
61
|
+
* @param {any} schema
|
|
62
|
+
* @param {ProsemirrorMapping} mapping
|
|
63
|
+
* @param {Y.Snapshot} [snapshot]
|
|
64
|
+
* @param {Y.Snapshot} [prevSnapshot]
|
|
65
|
+
* @param {function('removed' | 'added', Y.ID):any} [computeYChange]
|
|
66
|
+
* @return {PModel.Node | null} Returns node if node could be created. Otherwise it deletes the yjs type and returns null
|
|
67
|
+
*/
|
|
68
|
+
export declare const createNodeFromYElement: (el: Y.XmlElement, schema: any, mapping: ProsemirrorMapping, snapshot: Y.Snapshot, prevSnapshot: Y.Snapshot, computeYChange: (arg0: "removed" | "added", arg1: Y.ID) => any) => PModel.Node | null;
|
|
69
|
+
/**
|
|
70
|
+
* Update a yDom node by syncing the current content of the prosemirror node.
|
|
71
|
+
*
|
|
72
|
+
* This is a y-prosemirror internal feature that you can use at your own risk.
|
|
73
|
+
*
|
|
74
|
+
* @private
|
|
75
|
+
* @unstable
|
|
76
|
+
*
|
|
77
|
+
* @param {{transact: Function}} y
|
|
78
|
+
* @param {Y.XmlFragment} yDomFragment
|
|
79
|
+
* @param {any} pNode
|
|
80
|
+
* @param {ProsemirrorMapping} mapping
|
|
81
|
+
*/
|
|
82
|
+
export declare const updateYFragment: (y: any, yDomFragment: Y.XmlFragment, pNode: any, mapping: ProsemirrorMapping) => void;
|
|
83
|
+
//# sourceMappingURL=SyncPlugin.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SyncPlugin.d.ts","sourceRoot":"","sources":["../src/SyncPlugin.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,MAAM,MAAM,mBAAmB,CAAC;AAQ5C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AAUzB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,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