Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@liveblocks/node-lexical

Package Overview
Dependencies
Maintainers
5
Versions
80
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liveblocks/node-lexical - npm Package Compare versions

Comparing version 1.12.0-lexical6 to 2.0.0-alpha2

23

dist/index.d.ts
import { Liveblocks } from '@liveblocks/node';
import { Klass, LexicalNode, LexicalNodeReplacement, LexicalEditor, EditorState } from 'lexical';
import { Klass, LexicalNode, LexicalNodeReplacement, EditorState, LexicalEditor, SerializedEditorState, SerializedLexicalNode } from 'lexical';
export { $createParagraphNode, $createTextNode, $getRoot } from 'lexical';
declare function getEditor(client: Liveblocks, roomId: string, nodes: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>): Promise<LexicalEditor>;
declare function getTextContent(client: Liveblocks, roomId: string, nodes: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>): Promise<string>;
declare function getEditorState(client: Liveblocks, roomId: string, nodes: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>): Promise<EditorState>;
declare function modifyDocument(client: Liveblocks, roomId: string, nodes: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>, modifyFn: (editor: LexicalEditor) => void): Promise<void>;
declare type LiveblocksLexicalOptions = {
roomId: string;
nodes?: ReadonlyArray<Klass<LexicalNode> | LexicalNodeReplacement>;
client: Liveblocks;
};
declare type LiveblocksDocumentApi = {
refresh: () => Promise<void>;
update: (modifyFn: () => void) => Promise<void>;
getTextContent: () => string;
getEditorState: () => EditorState;
getLexicalEditor: () => LexicalEditor;
toJSON: () => SerializedEditorState<SerializedLexicalNode>;
toMarkdown: () => string;
};
declare function withLexicalDocument<T>({ roomId, nodes, client }: LiveblocksLexicalOptions, callback: (api: LiveblocksDocumentApi) => Promise<T> | T): Promise<T>;
export { getEditor, getEditorState, getTextContent, modifyDocument };
export { type LiveblocksDocumentApi, type LiveblocksLexicalOptions, withLexicalDocument };

@@ -1,32 +0,17 @@

"use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/index.ts
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/index.ts
var _headless = require('@lexical/headless');
var _markdown = require('@lexical/markdown');
var _yjs = require('@lexical/yjs');
var _core = require('@liveblocks/core');
var _lexical = require('lexical');
var _yjs3 = require('yjs');
// src/collab.ts
var _yjs = require('yjs');
// src/headless.ts
var _headless = require('@lexical/headless');
var _yjs3 = require('@lexical/yjs');
function withHeadlessCollaborationEditor(nodes, callback) {
const editor = _headless.createHeadlessEditor.call(void 0, {
nodes
});
const id = "root";
const doc = new (0, _yjs.Doc)();
const docMap = /* @__PURE__ */ new Map([[id, doc]]);
const provider = createNoOpProvider();
const binding = _yjs3.createBinding.call(void 0, editor, provider, id, doc, docMap);
const unsubscribe = registerCollaborationListeners(editor, provider, binding);
const res = callback(editor, binding, provider);
unsubscribe();
return res;
}
function registerCollaborationListeners(editor, provider, binding) {

@@ -43,3 +28,3 @@ const unsubscribeUpdateListener = editor.registerUpdateListener(

if (tags.has("skip-collab") === false) {
_yjs3.syncLexicalUpdateToYjs.call(void 0,
_yjs.syncLexicalUpdateToYjs.call(void 0,
binding,

@@ -59,3 +44,3 @@ provider,

if (transaction.origin !== binding) {
_yjs3.syncYjsChangesToLexical.call(void 0, binding, provider, events, false);
_yjs.syncYjsChangesToLexical.call(void 0, binding, provider, events, false);
}

@@ -123,6 +108,2 @@ };

var ThreadMarkNode = class _ThreadMarkNode extends _lexical.ElementNode {
constructor(ids, key) {
super(key);
this.__ids = ids || [];
}
// The ids of the threads that this mark is associated with

@@ -156,2 +137,6 @@ static getType() {

}
constructor(ids, key) {
super(key);
this.__ids = ids || [];
}
canInsertTextBefore() {

@@ -188,3 +173,3 @@ return false;

var PKG_NAME = "@liveblocks/node-lexical";
var PKG_VERSION = "1.12.0-lexical6";
var PKG_VERSION = "2.0.0-alpha2";
var PKG_FORMAT = "cjs";

@@ -196,24 +181,41 @@

var LIVEBLOCKS_NODES = [ThreadMarkNode, MentionNode];
async function getEditor(client, roomId, nodes) {
const doc = await client.getYjsDocumentAsBinaryUpdate(roomId);
const update = new Uint8Array(doc);
return withHeadlessCollaborationEditor(
[...LIVEBLOCKS_NODES, ...nodes],
(editor, binding) => {
_yjs.applyUpdate.call(void 0, binding.doc, update);
async function withLexicalDocument({ roomId, nodes, client }, callback) {
const update = new Uint8Array(
await client.getYjsDocumentAsBinaryUpdate(roomId)
);
const editor = _headless.createHeadlessEditor.call(void 0, {
nodes: [...LIVEBLOCKS_NODES, ..._nullishCoalesce(nodes, () => ( []))]
});
const id = "root";
const doc = new (0, _yjs3.Doc)();
const docMap = /* @__PURE__ */ new Map([[id, doc]]);
const provider = createNoOpProvider();
const binding = _yjs.createBinding.call(void 0, editor, provider, id, doc, docMap);
const unsubscribe = registerCollaborationListeners(editor, provider, binding);
_yjs3.applyUpdate.call(void 0, binding.doc, update);
editor.update(() => {
}, { discrete: true });
const val = await callback({
refresh: async () => {
const latest = new Uint8Array(
await client.getYjsDocumentAsBinaryUpdate(roomId)
);
_yjs3.applyUpdate.call(void 0, binding.doc, latest);
editor.update(() => {
}, { discrete: true });
return editor;
}
);
}
async function getTextContent(client, roomId, nodes) {
const doc = await client.getYjsDocumentAsBinaryUpdate(roomId);
const update = new Uint8Array(doc);
return withHeadlessCollaborationEditor(
[...LIVEBLOCKS_NODES, ...nodes],
(editor, binding) => {
_yjs.applyUpdate.call(void 0, binding.doc, update);
},
update: async (modifyFn) => {
editor.update(() => {
}, { discrete: true });
const beforeVector = _yjs3.encodeStateVector.call(void 0, binding.doc);
editor.update(
() => {
modifyFn();
},
{ discrete: true }
);
const diffUpdate = _yjs3.encodeStateAsUpdate.call(void 0, binding.doc, beforeVector);
return client.sendYjsBinaryUpdate(roomId, diffUpdate);
},
getTextContent: () => {
let content = "";

@@ -224,39 +226,23 @@ editor.getEditorState().read(() => {

return content;
}
);
}
async function getEditorState(client, roomId, nodes) {
const doc = await client.getYjsDocumentAsBinaryUpdate(roomId);
const update = new Uint8Array(doc);
return withHeadlessCollaborationEditor(
[...LIVEBLOCKS_NODES, ...nodes],
(editor, binding) => {
_yjs.applyUpdate.call(void 0, binding.doc, update);
editor.update(() => {
}, { discrete: true });
},
toJSON: () => {
return editor.getEditorState().toJSON();
},
toMarkdown: () => {
let markdown = "";
editor.getEditorState().read(() => {
markdown = _markdown.$convertToMarkdownString.call(void 0, _markdown.TRANSFORMERS);
});
return markdown;
},
getEditorState: () => {
return editor.getEditorState();
},
getLexicalEditor: () => {
return editor;
}
);
});
unsubscribe();
return val;
}
async function modifyDocument(client, roomId, nodes, modifyFn) {
const doc = await client.getYjsDocumentAsBinaryUpdate(roomId);
const update = new Uint8Array(doc);
await withHeadlessCollaborationEditor(
[...LIVEBLOCKS_NODES, ...nodes],
(editor, binding) => {
_yjs.applyUpdate.call(void 0, binding.doc, update);
editor.update(() => {
}, { discrete: true });
const beforeVector = _yjs.encodeStateVectorFromUpdate.call(void 0, update);
editor.update(
() => {
modifyFn(editor);
},
{ discrete: true }
);
const afterUpdate = _yjs.encodeStateAsUpdate.call(void 0, binding.doc, beforeVector);
return client.sendYjsBinaryUpdate(roomId, afterUpdate);
}
);
}

@@ -267,6 +253,3 @@

exports.$createParagraphNode = _lexical.$createParagraphNode; exports.$createTextNode = _lexical.$createTextNode; exports.$getRoot = _lexical.$getRoot; exports.getEditor = getEditor; exports.getEditorState = getEditorState; exports.getTextContent = getTextContent; exports.modifyDocument = modifyDocument;
exports.$createParagraphNode = _lexical.$createParagraphNode; exports.$createTextNode = _lexical.$createTextNode; exports.$getRoot = _lexical.$getRoot; exports.withLexicalDocument = withLexicalDocument;
//# sourceMappingURL=index.js.map
{
"name": "@liveblocks/node-lexical",
"version": "1.12.0-lexical6",
"version": "2.0.0-alpha2",
"description": "A server-side utility that lets you modify lexical documents hosted in Liveblocks.",
"license": "Apache-2.0",
"type": "commonjs",
"main": "./dist/index.js",

@@ -36,11 +37,12 @@ "types": "./dist/index.d.ts",

"dependencies": {
"@liveblocks/core": "1.12.0-lexical6",
"@liveblocks/node": "1.12.0-lexical6",
"@liveblocks/core": "2.0.0-alpha2",
"@liveblocks/node": "2.0.0-alpha2",
"yjs": "^13.6.15"
},
"peerDependencies": {
"@lexical/headless": "0.14.5",
"@lexical/selection": "0.14.3",
"@lexical/yjs": "0.14.5",
"lexical": "0.14.5"
"@lexical/headless": "0.16.0",
"@lexical/selection": "0.16.0",
"@lexical/yjs": "0.16.0",
"@lexical/markdown": "0.16.0",
"lexical": "0.16.0"
},

@@ -47,0 +49,0 @@ "devDependencies": {

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc