New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@tiptap/extension-collaboration

Package Overview
Dependencies
Maintainers
5
Versions
191
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tiptap/extension-collaboration - npm Package Compare versions

Comparing version

to
3.0.0-next.1

dist/index.d.cts

206

dist/index.js

@@ -1,113 +0,109 @@

import { Extension } from '@tiptap/core';
import { yUndoPluginKey, undo, redo, yUndoPlugin, ySyncPlugin, ySyncPluginKey } from 'y-prosemirror';
/**
* This extension allows you to collaborate with others in real-time.
* @see https://tiptap.dev/api/extensions/collaboration
*/
const Collaboration = Extension.create({
name: 'collaboration',
priority: 1000,
addOptions() {
return {
document: null,
field: 'default',
fragment: null,
};
},
onCreate() {
if (this.editor.extensionManager.extensions.find(extension => extension.name === 'history')) {
console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-history".');
// src/collaboration.ts
import { Extension } from "@tiptap/core";
import {
redo,
undo,
ySyncPlugin,
yUndoPlugin,
yUndoPluginKey
} from "y-prosemirror";
var Collaboration = Extension.create({
name: "collaboration",
priority: 1e3,
addOptions() {
return {
document: null,
field: "default",
fragment: null
};
},
onCreate() {
if (this.editor.extensionManager.extensions.find((extension) => extension.name === "history")) {
console.warn('[tiptap warn]: "@tiptap/extension-collaboration" comes with its own history support and is not compatible with "@tiptap/extension-history".');
}
},
addCommands() {
return {
undo: () => ({ tr, state, dispatch }) => {
tr.setMeta("preventDispatch", true);
const undoManager = yUndoPluginKey.getState(state).undoManager;
if (undoManager.undoStack.length === 0) {
return false;
}
},
addCommands() {
return {
undo: () => ({ tr, state, dispatch }) => {
tr.setMeta('preventDispatch', true);
const undoManager = yUndoPluginKey.getState(state).undoManager;
if (undoManager.undoStack.length === 0) {
return false;
}
if (!dispatch) {
return true;
}
return undo(state);
},
redo: () => ({ tr, state, dispatch }) => {
tr.setMeta('preventDispatch', true);
const undoManager = yUndoPluginKey.getState(state).undoManager;
if (undoManager.redoStack.length === 0) {
return false;
}
if (!dispatch) {
return true;
}
return redo(state);
},
if (!dispatch) {
return true;
}
return undo(state);
},
redo: () => ({ tr, state, dispatch }) => {
tr.setMeta("preventDispatch", true);
const undoManager = yUndoPluginKey.getState(state).undoManager;
if (undoManager.redoStack.length === 0) {
return false;
}
if (!dispatch) {
return true;
}
return redo(state);
}
};
},
addKeyboardShortcuts() {
return {
"Mod-z": () => this.editor.commands.undo(),
"Mod-y": () => this.editor.commands.redo(),
"Shift-Mod-z": () => this.editor.commands.redo()
};
},
addProseMirrorPlugins() {
const fragment = this.options.fragment ? this.options.fragment : this.options.document.getXmlFragment(this.options.field);
const yUndoPluginInstance = yUndoPlugin();
const originalUndoPluginView = yUndoPluginInstance.spec.view;
yUndoPluginInstance.spec.view = (view) => {
const { undoManager } = yUndoPluginKey.getState(view.state);
if (undoManager.restore) {
undoManager.restore();
undoManager.restore = () => {
};
},
addKeyboardShortcuts() {
return {
'Mod-z': () => this.editor.commands.undo(),
'Mod-y': () => this.editor.commands.redo(),
'Shift-Mod-z': () => this.editor.commands.redo(),
};
},
addProseMirrorPlugins() {
const fragment = this.options.fragment
? this.options.fragment
: this.options.document.getXmlFragment(this.options.field);
// Quick fix until there is an official implementation (thanks to @hamflx).
// See https://github.com/yjs/y-prosemirror/issues/114 and https://github.com/yjs/y-prosemirror/issues/102
const yUndoPluginInstance = yUndoPlugin();
const originalUndoPluginView = yUndoPluginInstance.spec.view;
yUndoPluginInstance.spec.view = (view) => {
const { undoManager } = yUndoPluginKey.getState(view.state);
if (undoManager.restore) {
undoManager.restore();
// eslint-disable-next-line
undoManager.restore = () => { };
}
const viewRet = originalUndoPluginView ? originalUndoPluginView(view) : void 0;
return {
destroy: () => {
const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager);
const observers = undoManager._observers;
undoManager.restore = () => {
if (hasUndoManSelf) {
undoManager.trackedOrigins.add(undoManager);
}
const viewRet = originalUndoPluginView ? originalUndoPluginView(view) : undefined;
return {
destroy: () => {
const hasUndoManSelf = undoManager.trackedOrigins.has(undoManager);
// eslint-disable-next-line
const observers = undoManager._observers;
undoManager.restore = () => {
if (hasUndoManSelf) {
undoManager.trackedOrigins.add(undoManager);
}
undoManager.doc.on('afterTransaction', undoManager.afterTransactionHandler);
// eslint-disable-next-line
undoManager._observers = observers;
};
if (viewRet === null || viewRet === void 0 ? void 0 : viewRet.destroy) {
viewRet.destroy();
}
},
};
};
const ySyncPluginOptions = {
...(this.options.ySyncOptions ? { ...this.options.ySyncOptions } : {}),
...(this.options.onFirstRender ? { ...this.options.onFirstRender } : {}),
};
const ySyncPluginInstance = ySyncPlugin(fragment, ySyncPluginOptions);
return [ySyncPluginInstance, yUndoPluginInstance];
},
undoManager.doc.on("afterTransaction", undoManager.afterTransactionHandler);
undoManager._observers = observers;
};
if (viewRet == null ? void 0 : viewRet.destroy) {
viewRet.destroy();
}
}
};
};
const ySyncPluginOptions = {
...this.options.ySyncOptions,
onFirstRender: this.options.onFirstRender
};
const ySyncPluginInstance = ySyncPlugin(fragment, ySyncPluginOptions);
return [ySyncPluginInstance, yUndoPluginInstance];
}
});
/**
* Checks if a transaction was originated from a Yjs change.
* @param {Transaction} transaction - The transaction to check.
* @returns {boolean} - True if the transaction was originated from a Yjs change, false otherwise.
* @example
* const transaction = new Transaction(doc)
* const isOrigin = isChangeOrigin(transaction) // returns false
*/
// src/helpers/isChangeOrigin.ts
import { ySyncPluginKey } from "y-prosemirror";
function isChangeOrigin(transaction) {
return !!transaction.getMeta(ySyncPluginKey);
return !!transaction.getMeta(ySyncPluginKey);
}
export { Collaboration, Collaboration as default, isChangeOrigin };
//# sourceMappingURL=index.js.map
// src/index.ts
var src_default = Collaboration;
export {
Collaboration,
src_default as default,
isChangeOrigin
};
//# sourceMappingURL=index.js.map
{
"name": "@tiptap/extension-collaboration",
"description": "collaboration extension for tiptap",
"version": "3.0.0-next.0",
"version": "3.0.0-next.1",
"homepage": "https://tiptap.dev",

@@ -18,3 +18,3 @@ "keywords": [

".": {
"types": "./dist/packages/extension-collaboration/src/index.d.ts",
"types": "./dist/index.d.ts",
"import": "./dist/index.js",

@@ -26,4 +26,3 @@ "require": "./dist/index.cjs"

"module": "dist/index.js",
"umd": "dist/index.umd.js",
"types": "dist/packages/extension-collaboration/src/index.d.ts",
"types": "dist/index.d.ts",
"files": [

@@ -34,9 +33,9 @@ "src",

"devDependencies": {
"@tiptap/core": "^3.0.0-next.0",
"@tiptap/pm": "^3.0.0-next.0",
"@tiptap/core": "^3.0.0-next.1",
"@tiptap/pm": "^3.0.0-next.1",
"y-prosemirror": "^1.2.9"
},
"peerDependencies": {
"@tiptap/core": "^3.0.0-next.0",
"@tiptap/pm": "^3.0.0-next.0",
"@tiptap/core": "^3.0.0-next.1",
"@tiptap/pm": "^3.0.0-next.1",
"y-prosemirror": "^1.2.6"

@@ -50,5 +49,4 @@ },

"scripts": {
"clean": "rm -rf dist",
"build": "npm run clean && rollup -c"
"build": "tsup"
}
}

@@ -170,4 +170,4 @@ import { Extension } from '@tiptap/core'

const ySyncPluginOptions: YSyncOpts = {
...(this.options.ySyncOptions ? { ...this.options.ySyncOptions } : {}),
...(this.options.onFirstRender ? { ...this.options.onFirstRender } : {}),
...this.options.ySyncOptions,
onFirstRender: this.options.onFirstRender,
}

@@ -174,0 +174,0 @@

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet