@tiptap/y-tiptap 3.0.0-beta.2 → 3.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.
package/README.md CHANGED
@@ -4,6 +4,14 @@
4
4
 
5
5
  This binding maps a Y.XmlFragment to the ProseMirror state.
6
6
 
7
+ ## Why was this package forked from [y-prosemirror](https://github.com/yjs/y-prosemirror)?
8
+
9
+ We forked y-prosemirror to create a Tiptap-specific package with changes we needed for Tiptap-related features. These modifications were too specific to be merged upstream or would have added maintenance overhead for the y-prosemirror maintainers.
10
+
11
+ Where feasible, we contribute improvements and fixes back to y-prosemirror to support the broader ecosystem.
12
+
13
+ This package is designed for use with Tiptap and is not intended as a general-purpose Yjs binding for ProseMirror.
14
+
7
15
  ## Features
8
16
 
9
17
  * Sync ProseMirror state
@@ -16,7 +24,7 @@ This binding maps a Y.XmlFragment to the ProseMirror state.
16
24
  ```js
17
25
  import { ySyncPlugin, yCursorPlugin, yUndoPlugin, undo, redo, initProseMirrorDoc } from '@tiptap/y-tiptap'
18
26
  import { exampleSetup } from 'prosemirror-example-setup'
19
- import { keymap } from '@tiptap/pm/keymap'
27
+ import { keymap } from 'prosemirror-keymap'
20
28
  ..
21
29
 
22
30
  const type = ydocument.get('prosemirror', Y.XmlFragment)
@@ -0,0 +1,117 @@
1
+ /**
2
+ * Utility method to convert a Prosemirror Doc Node into a Y.Doc.
3
+ *
4
+ * This can be used when importing existing content to Y.Doc for the first time,
5
+ * note that this should not be used to rehydrate a Y.Doc from a database once
6
+ * collaboration has begun as all history will be lost
7
+ *
8
+ * @param {Node} doc
9
+ * @param {string} xmlFragment
10
+ * @return {Y.Doc}
11
+ */
12
+ export function prosemirrorToYDoc(doc: Node, xmlFragment?: string): Y.Doc;
13
+ /**
14
+ * Utility method to update an empty Y.XmlFragment with content from a Prosemirror Doc Node.
15
+ *
16
+ * This can be used when importing existing content to Y.Doc for the first time,
17
+ * note that this should not be used to rehydrate a Y.Doc from a database once
18
+ * collaboration has begun as all history will be lost
19
+ *
20
+ * Note: The Y.XmlFragment does not need to be part of a Y.Doc document at the time that this
21
+ * method is called, but it must be added before any other operations are performed on it.
22
+ *
23
+ * @param {Node} doc prosemirror document.
24
+ * @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
25
+ * populated from the prosemirror state; otherwise a new XmlFragment will be created.
26
+ * @return {Y.XmlFragment}
27
+ */
28
+ export function prosemirrorToYXmlFragment(doc: Node, xmlFragment?: Y.XmlFragment): Y.XmlFragment;
29
+ /**
30
+ * Utility method to convert Prosemirror compatible JSON into a Y.Doc.
31
+ *
32
+ * This can be used when importing existing content to Y.Doc for the first time,
33
+ * note that this should not be used to rehydrate a Y.Doc from a database once
34
+ * collaboration has begun as all history will be lost
35
+ *
36
+ * @param {Schema} schema
37
+ * @param {any} state
38
+ * @param {string} xmlFragment
39
+ * @return {Y.Doc}
40
+ */
41
+ export function prosemirrorJSONToYDoc(schema: Schema, state: any, xmlFragment?: string): Y.Doc;
42
+ /**
43
+ * Utility method to convert Prosemirror compatible JSON to a Y.XmlFragment
44
+ *
45
+ * This can be used when importing existing content to Y.Doc for the first time,
46
+ * note that this should not be used to rehydrate a Y.Doc from a database once
47
+ * collaboration has begun as all history will be lost
48
+ *
49
+ * @param {Schema} schema
50
+ * @param {any} state
51
+ * @param {Y.XmlFragment} [xmlFragment] If supplied, an xml fragment to be
52
+ * populated from the prosemirror state; otherwise a new XmlFragment will be created.
53
+ * @return {Y.XmlFragment}
54
+ */
55
+ export function prosemirrorJSONToYXmlFragment(schema: Schema, state: any, xmlFragment?: Y.XmlFragment): Y.XmlFragment;
56
+ /**
57
+ * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
58
+ *
59
+ * Utility method to convert a Y.Doc to a Prosemirror Doc node.
60
+ *
61
+ * @param {Schema} schema
62
+ * @param {Y.Doc} ydoc
63
+ * @return {Node}
64
+ */
65
+ export function yDocToProsemirror(schema: Schema, ydoc: Y.Doc): Node;
66
+ /**
67
+ *
68
+ * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
69
+ *
70
+ * Utility method to convert a Y.XmlFragment to a Prosemirror Doc node.
71
+ *
72
+ * @param {Schema} schema
73
+ * @param {Y.XmlFragment} xmlFragment
74
+ * @return {Node}
75
+ */
76
+ export function yXmlFragmentToProsemirror(schema: Schema, xmlFragment: Y.XmlFragment): Node;
77
+ /**
78
+ *
79
+ * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
80
+ *
81
+ * Utility method to convert a Y.Doc to Prosemirror compatible JSON.
82
+ *
83
+ * @param {Y.Doc} ydoc
84
+ * @param {string} xmlFragment
85
+ * @return {Record<string, any>}
86
+ */
87
+ export function yDocToProsemirrorJSON(ydoc: Y.Doc, xmlFragment?: string): Record<string, any>;
88
+ /**
89
+ * @deprecated Use `yXmlFragmentToProseMirrorRootNode` instead
90
+ *
91
+ * Utility method to convert a Y.Doc to Prosemirror compatible JSON.
92
+ *
93
+ * @param {Y.XmlFragment} xmlFragment The fragment, which must be part of a Y.Doc.
94
+ * @return {Record<string, any>}
95
+ */
96
+ export function yXmlFragmentToProsemirrorJSON(xmlFragment: Y.XmlFragment): Record<string, any>;
97
+ export function setMeta(view: any, key: any, value: any): void;
98
+ export function absolutePositionToRelativePosition(pos: number, type: Y.XmlFragment, mapping: ProsemirrorMapping): any;
99
+ export function relativePositionToAbsolutePosition(y: Y.Doc, documentType: Y.XmlFragment, relPos: any, mapping: ProsemirrorMapping): null | number;
100
+ export function yXmlFragmentToProseMirrorFragment(yXmlFragment: Y.XmlFragment, schema: Schema): Fragment;
101
+ export function yXmlFragmentToProseMirrorRootNode(yXmlFragment: Y.XmlFragment, schema: Schema): Node;
102
+ export function initProseMirrorDoc(yXmlFragment: Y.XmlFragment, schema: Schema): {
103
+ doc: Node;
104
+ meta: {
105
+ mapping: Map<any, any>;
106
+ isOMark: Map<any, any>;
107
+ };
108
+ mapping: Map<any, any>;
109
+ };
110
+ /**
111
+ * Either a node if type is YXmlElement or an Array of text nodes if YXmlText
112
+ */
113
+ export type ProsemirrorMapping = Map<Y.AbstractType<any>, Node | Array<Node>>;
114
+ import { Node } from 'prosemirror-model';
115
+ import * as Y from 'yjs';
116
+ import { Schema } from 'prosemirror-model';
117
+ import { Fragment } from 'prosemirror-model';
@@ -0,0 +1,17 @@
1
+ export function defaultAwarenessStateFilter(currentClientId: number, userClientId: number, _user: any): boolean;
2
+ export function defaultCursorBuilder(user: any): HTMLElement;
3
+ export function defaultSelectionBuilder(user: any): import('prosemirror-view').DecorationAttrs;
4
+ export function createDecorations(state: any, awareness: Awareness, awarenessFilter: (arg0: number, arg1: number, arg2: any) => boolean, createCursor: (user: {
5
+ name: string;
6
+ color: string;
7
+ }, clientId: number) => Element, createSelection: (user: {
8
+ name: string;
9
+ color: string;
10
+ }, clientId: number) => import('prosemirror-view').DecorationAttrs): any;
11
+ export function yCursorPlugin(awareness: Awareness, { awarenessStateFilter, cursorBuilder, selectionBuilder, getSelection }?: {
12
+ awarenessStateFilter?: (arg0: any, arg1: any, arg2: any) => boolean;
13
+ cursorBuilder?: (user: any, clientId: number) => HTMLElement;
14
+ selectionBuilder?: (user: any, clientId: number) => import('prosemirror-view').DecorationAttrs;
15
+ getSelection?: (arg0: any) => any;
16
+ }, cursorStateField?: string): any;
17
+ import { Awareness } from "y-protocols/awareness";
@@ -0,0 +1,19 @@
1
+ /**
2
+ * The unique prosemirror plugin key for syncPlugin
3
+ *
4
+ * @public
5
+ */
6
+ export const ySyncPluginKey: PluginKey<any>;
7
+ /**
8
+ * The unique prosemirror plugin key for undoPlugin
9
+ *
10
+ * @public
11
+ */
12
+ export const yUndoPluginKey: PluginKey<any>;
13
+ /**
14
+ * The unique prosemirror plugin key for cursorPlugin
15
+ *
16
+ * @public
17
+ */
18
+ export const yCursorPluginKey: PluginKey<any>;
19
+ import { PluginKey } from 'prosemirror-state';
@@ -0,0 +1,125 @@
1
+ export function createEmptyMeta(): {
2
+ mapping: Map<any, any>;
3
+ isOMark: Map<any, any>;
4
+ };
5
+ export function isVisible(item: Y.Item, snapshot?: Y.Snapshot): boolean;
6
+ export function ySyncPlugin(yXmlFragment: Y.XmlFragment, { colors, colorMapping, permanentUserData, onFirstRender, mapping }?: YSyncOpts): any;
7
+ export function getRelativeSelection(pmbinding: ProsemirrorBinding, state: import('prosemirror-state').EditorState): {
8
+ type: any;
9
+ anchor: any;
10
+ head: any;
11
+ };
12
+ /**
13
+ * Binding for prosemirror.
14
+ *
15
+ * @protected
16
+ */
17
+ export class ProsemirrorBinding {
18
+ /**
19
+ * @param {Y.XmlFragment} yXmlFragment The bind source
20
+ * @param {ProsemirrorMapping} mapping
21
+ */
22
+ constructor(yXmlFragment: Y.XmlFragment, mapping?: ProsemirrorMapping);
23
+ type: Y.XmlFragment;
24
+ /**
25
+ * this will be set once the view is created
26
+ * @type {any}
27
+ */
28
+ prosemirrorView: any;
29
+ mux: import("lib0/mutex").mutex;
30
+ mapping: ProsemirrorMapping;
31
+ /**
32
+ * Is overlapping mark - i.e. mark does not exclude itself.
33
+ *
34
+ * @type {Map<import('prosemirror-model').MarkType, boolean>}
35
+ */
36
+ isOMark: Map<import('prosemirror-model').MarkType, boolean>;
37
+ _observeFunction: any;
38
+ /**
39
+ * @type {Y.Doc}
40
+ */
41
+ doc: Y.Doc;
42
+ /**
43
+ * current selection as relative positions in the Yjs model
44
+ */
45
+ beforeTransactionSelection: {
46
+ type: any;
47
+ anchor: any;
48
+ head: any;
49
+ };
50
+ beforeAllTransactions: () => void;
51
+ afterAllTransactions: () => void;
52
+ _domSelectionInView: boolean;
53
+ /**
54
+ * Create a transaction for changing the prosemirror state.
55
+ *
56
+ * @returns
57
+ */
58
+ get _tr(): any;
59
+ _isLocalCursorInView(): boolean;
60
+ _isDomSelectionInView(): boolean;
61
+ /**
62
+ * @param {Y.Snapshot} snapshot
63
+ * @param {Y.Snapshot} prevSnapshot
64
+ */
65
+ renderSnapshot(snapshot: Y.Snapshot, prevSnapshot: Y.Snapshot): void;
66
+ unrenderSnapshot(): void;
67
+ _forceRerender(): void;
68
+ /**
69
+ * @param {Y.Snapshot|Uint8Array} snapshot
70
+ * @param {Y.Snapshot|Uint8Array} prevSnapshot
71
+ * @param {Object} pluginState
72
+ */
73
+ _renderSnapshot(snapshot: Y.Snapshot | Uint8Array, prevSnapshot: Y.Snapshot | Uint8Array, pluginState: any): void;
74
+ /**
75
+ * @param {Array<Y.YEvent<any>>} events
76
+ * @param {Y.Transaction} transaction
77
+ */
78
+ _typeChanged(events: Array<Y.YEvent<any>>, transaction: Y.Transaction): void;
79
+ /**
80
+ * @param {import('prosemirror-model').Node} doc
81
+ */
82
+ _prosemirrorChanged(doc: import('prosemirror-model').Node): void;
83
+ /**
84
+ * View is ready to listen to changes. Register observers.
85
+ * @param {any} prosemirrorView
86
+ */
87
+ initView(prosemirrorView: any): void;
88
+ destroy(): void;
89
+ }
90
+ export function createNodeFromYElement(el: Y.XmlElement, schema: any, meta: BindingMetadata, snapshot?: Y.Snapshot, prevSnapshot?: Y.Snapshot, computeYChange?: (arg0: 'removed' | 'added', arg1: Y.ID) => any): PModel.Node | null;
91
+ export function yattr2markname(attrName: string): string;
92
+ export function attributesToMarks(attrs: {
93
+ [x: string]: any;
94
+ }, schema: import('prosemirror-model').Schema): PModel.Mark[];
95
+ export function updateYFragment(y: {
96
+ transact: Function;
97
+ }, yDomFragment: Y.XmlFragment, pNode: any, meta: BindingMetadata): void;
98
+ export type BindingMetadata = {
99
+ mapping: ProsemirrorMapping;
100
+ /**
101
+ * - is overlapping mark
102
+ */
103
+ isOMark: Map<import('prosemirror-model').MarkType, boolean>;
104
+ };
105
+ /**
106
+ * Either a node if type is YXmlElement or an Array of text nodes if YXmlText
107
+ */
108
+ export type ProsemirrorMapping = Map<Y.AbstractType<any>, PModel.Node | Array<PModel.Node>>;
109
+ export type ColorDef = {
110
+ light: string;
111
+ dark: string;
112
+ };
113
+ export type YSyncOpts = {
114
+ colors?: Array<ColorDef>;
115
+ colorMapping?: Map<string, ColorDef>;
116
+ permanentUserData?: Y.PermanentUserData | null;
117
+ mapping?: ProsemirrorMapping;
118
+ /**
119
+ * Fired when the content from Yjs is initially rendered to ProseMirror
120
+ */
121
+ onFirstRender?: Function;
122
+ };
123
+ export type NormalizedPNodeContent = Array<Array<PModel.Node> | PModel.Node>;
124
+ import * as Y from 'yjs';
125
+ import * as PModel from 'prosemirror-model';
@@ -0,0 +1,15 @@
1
+ export function undo(state: any): boolean;
2
+ export function redo(state: any): boolean;
3
+ export const defaultProtectedNodes: Set<string>;
4
+ export function defaultDeleteFilter(item: any, protectedNodes: any): boolean;
5
+ export function yUndoPlugin({ protectedNodes, trackedOrigins, undoManager }?: {
6
+ protectedNodes?: Set<string>;
7
+ trackedOrigins?: any[];
8
+ undoManager?: any;
9
+ }): Plugin<{
10
+ undoManager: any;
11
+ prevSel: any;
12
+ hasUndoOps: boolean;
13
+ hasRedoOps: boolean;
14
+ }>;
15
+ import { Plugin } from 'prosemirror-state';
@@ -0,0 +1 @@
1
+ export function hashOfJSON(json: any): string;
@@ -0,0 +1,5 @@
1
+ export * from "./plugins/cursor-plugin.js";
2
+ export * from "./plugins/undo-plugin.js";
3
+ export * from "./plugins/keys.js";
4
+ export { ySyncPlugin, isVisible, getRelativeSelection, ProsemirrorBinding, updateYFragment } from "./plugins/sync-plugin.js";
5
+ export { absolutePositionToRelativePosition, relativePositionToAbsolutePosition, setMeta, prosemirrorJSONToYDoc, yDocToProsemirrorJSON, yDocToProsemirror, prosemirrorToYDoc, prosemirrorJSONToYXmlFragment, yXmlFragmentToProsemirrorJSON, yXmlFragmentToProsemirror, prosemirrorToYXmlFragment, yXmlFragmentToProseMirrorRootNode, yXmlFragmentToProseMirrorFragment, initProseMirrorDoc } from "./lib.js";
package/dist/y-tiptap.cjs CHANGED
@@ -13,7 +13,6 @@ var object = require('lib0/object');
13
13
  var set = require('lib0/set');
14
14
  var diff = require('lib0/diff');
15
15
  var error = require('lib0/error');
16
- var state = require('@tiptap/pm/state');
17
16
  var random = require('lib0/random');
18
17
  var environment = require('lib0/environment');
19
18
  var dom = require('lib0/dom');
@@ -59,21 +58,21 @@ var buf__namespace = /*#__PURE__*/_interopNamespace(buf);
59
58
  *
60
59
  * @public
61
60
  */
62
- const ySyncPluginKey = new state.PluginKey('y-sync');
61
+ const ySyncPluginKey = new prosemirrorState.PluginKey('y-sync');
63
62
 
64
63
  /**
65
64
  * The unique prosemirror plugin key for undoPlugin
66
65
  *
67
66
  * @public
68
67
  */
69
- const yUndoPluginKey = new state.PluginKey('y-undo');
68
+ const yUndoPluginKey = new prosemirrorState.PluginKey('y-undo');
70
69
 
71
70
  /**
72
71
  * The unique prosemirror plugin key for cursorPlugin
73
72
  *
74
73
  * @public
75
74
  */
76
- const yCursorPluginKey = new state.PluginKey('yjs-cursor');
75
+ const yCursorPluginKey = new prosemirrorState.PluginKey('yjs-cursor');
77
76
 
78
77
  /**
79
78
  * Custom function to transform sha256 hash to N byte
@@ -2088,7 +2087,7 @@ const defaultDeleteFilter = (item, protectedNodes) => !(item instanceof Y.Item)
2088
2087
  (item.content.type instanceof Y.XmlElement && protectedNodes.has(item.content.type.nodeName))) ||
2089
2088
  item.content.type._length === 0;
2090
2089
 
2091
- const yUndoPlugin = ({ protectedNodes = defaultProtectedNodes, trackedOrigins = [], undoManager = null } = {}) => new state.Plugin({
2090
+ const yUndoPlugin = ({ protectedNodes = defaultProtectedNodes, trackedOrigins = [], undoManager = null } = {}) => new prosemirrorState.Plugin({
2092
2091
  key: yUndoPluginKey,
2093
2092
  state: {
2094
2093
  init: (initargs, state) => {