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

loro-prosemirror

Package Overview
Dependencies
Maintainers
0
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

loro-prosemirror - npm Package Compare versions

Comparing version 0.0.7 to 0.1.0

14

CHANGELOG.md

@@ -5,2 +5,16 @@ # Changelog

## [0.1.0](https://github.com/loro-dev/loro-prosemirror/compare/v0.0.8...v0.1.0) (2024-10-25)
### Features
* support loro-crdt v1 ([901f50d](https://github.com/loro-dev/loro-prosemirror/commit/901f50d829da354de50846bd7f24bbd135f6485f))
## [0.0.8](https://github.com/loro-dev/loro-prosemirror/compare/v0.0.7...v0.0.8) (2024-08-22)
### Continuous Integration
* add release workflow ([#14](https://github.com/loro-dev/loro-prosemirror/issues/14)) ([5437a33](https://github.com/loro-dev/loro-prosemirror/commit/5437a33752dd26e675a1928ebcaa9eabbc2de634))
### [0.0.7](https://github.com/loro-dev/prosemirror/compare/v0.0.6...v0.0.7) (2024-08-22)

@@ -7,0 +21,0 @@

8

dist/index.d.ts

@@ -1,2 +0,2 @@

import { Loro, LoroMap, ContainerID, LoroText, LoroList, Awareness, PeerID, Cursor, UndoManager } from 'loro-crdt';
import { LoroDoc, LoroMap, ContainerID, LoroText, LoroList, Subscription, Awareness, PeerID, Cursor, Loro, UndoManager } from 'loro-crdt';
import { EditorState, PluginKey, Plugin, Selection, Command } from 'prosemirror-state';

@@ -12,3 +12,3 @@ import { EditorView, DecorationAttrs, DecorationSet } from 'prosemirror-view';

};
type LoroDocType = Loro<{
type LoroDocType = LoroDoc<{
doc: LoroMap<LoroNodeContainerType>;

@@ -34,5 +34,5 @@ }>;

mapping: LoroNodeMapping;
snapshot?: Loro | null;
snapshot?: LoroDocType | null;
view?: EditorView;
docSubscription?: number | null;
docSubscription?: Subscription | null;
}

@@ -39,0 +39,0 @@ declare const LoroSyncPlugin: (props: LoroSyncPluginProps) => Plugin;

'use strict';
var prosemirrorModel = require('prosemirror-model');
var prosemirrorState = require('prosemirror-state');
var prosemirrorModel = require('prosemirror-model');
var diff = require('lib0/diff');

@@ -26,5 +26,5 @@ var _function = require('lib0/function');

if (isInit) {
doc.commit("sys:init");
doc.commit({ origin: "sys:init" });
} else {
doc.commit("loroSyncPlugin");
doc.commit({ origin: "loroSyncPlugin" });
}

@@ -380,2 +380,19 @@ }

const LORO_TEXT_STYLE_CACHE = /* @__PURE__ */ new WeakSet();
function getLoroTextStyle(schema) {
return Object.fromEntries(
Object.entries(schema.marks).map(([markName, markType]) => [
markName,
{ expand: markType.spec.inclusive ? "after" : "none" }
])
);
}
function configLoroTextStyle(doc, schema) {
if (LORO_TEXT_STYLE_CACHE.has(doc)) {
return;
}
LORO_TEXT_STYLE_CACHE.add(doc);
doc.configTextStyle(getLoroTextStyle(schema));
}
const loroSyncPluginKey = new prosemirrorState.PluginKey("loro-sync");

@@ -392,7 +409,10 @@ const LoroSyncPlugin = (props) => {

state: {
init: (config, editorState) => ({
doc: props.doc,
mapping: props.mapping ?? /* @__PURE__ */ new Map(),
changedBy: "local"
}),
init: (config, editorState) => {
configLoroTextStyle(props.doc, editorState.schema);
return {
doc: props.doc,
mapping: props.mapping ?? /* @__PURE__ */ new Map(),
changedBy: "local"
};
},
apply: (tr, state, oldEditorState, newEditorState) => {

@@ -413,3 +433,3 @@ const meta = tr.getMeta(

state = { ...state, ...meta.state };
state.doc.commit("sys:init");
state.doc.commit({ origin: "sys:init" });
break;

@@ -444,3 +464,3 @@ }

if (docSubscription != null) {
state.doc.unsubscribe(docSubscription);
docSubscription();
}

@@ -786,2 +806,3 @@ docSubscription = state.doc.subscribe((event) => updateNodeOnLoroEvent(view, event));

init: (config, editorState) => {
configLoroTextStyle(props.doc, editorState.schema);
undoManager.addExcludeOriginPrefix("sys:init");

@@ -788,0 +809,0 @@ return {

{
"name": "loro-prosemirror",
"version": "0.0.7",
"version": "0.1.0",
"description": "Prosemirror Binding for Loro",

@@ -27,3 +27,3 @@ "main": "dist/index.js",

"peerDependencies": {
"loro-crdt": "^0.16.3",
"loro-crdt": "^1.0.7",
"prosemirror-model": "^1.18.1",

@@ -30,0 +30,0 @@ "prosemirror-state": "^1.4.1",

@@ -17,5 +17,5 @@ # Prosemirror Binding for Loro

} from "loro-prosemirror";
import { Loro } from "loro-crdt";
import { LoroDoc } from "loro-crdt";
const doc = new Loro();
const doc = new LoroDoc();
const awareness = new CursorAwareness(doc.peerIdStr);

@@ -22,0 +22,0 @@ const plugins = [

import { simpleDiff } from "lib0/diff";
import { equalityDeep } from "lib0/function";
import type { ContainerID } from 'loro-crdt';
import type { ContainerID, LoroDoc } from 'loro-crdt';
import {

@@ -26,3 +26,3 @@ type Delta,

export type LoroDocType = Loro<{
export type LoroDocType = LoroDoc<{
doc: LoroMap<LoroNodeContainerType>

@@ -83,5 +83,5 @@ }>;

if (isInit) {
doc.commit("sys:init")
doc.commit({ origin: "sys:init" });
} else {
doc.commit("loroSyncPlugin");
doc.commit({ origin: "loroSyncPlugin" });
}

@@ -88,0 +88,0 @@ }

@@ -1,10 +0,10 @@

import { Loro, type LoroEventBatch } from "loro-crdt";
import type { LoroEventBatch, Subscription } from "loro-crdt";
import { Fragment, Slice } from "prosemirror-model";
import {
EditorState,
Plugin,
PluginKey,
type StateField,
EditorState,
} from "prosemirror-state";
import { EditorView } from "prosemirror-view";
import { Slice, Fragment } from "prosemirror-model";
import {

@@ -41,5 +41,5 @@ type LoroDocType,

mapping: LoroNodeMapping;
snapshot?: Loro | null;
snapshot?: LoroDocType | null;
view?: EditorView;
docSubscription?: number | null;
docSubscription?: Subscription | null;
}

@@ -81,3 +81,3 @@

state = { ...state, ...meta.state };
state.doc.commit("sys:init");
state.doc.commit({ origin: "sys:init" });
break;

@@ -114,5 +114,6 @@ default:

let docSubscription = state.docSubscription;
if (docSubscription != null) {
state.doc.unsubscribe(docSubscription);
docSubscription()
}

@@ -119,0 +120,0 @@ docSubscription = state.doc.subscribe((event) => updateNodeOnLoroEvent(view, event));

@@ -1,16 +0,13 @@

import { describe, assert, expect, test } from "vitest";
import { describe, expect, test } from "vitest";
import { Node, Schema, type NodeSpec, type MarkSpec } from "prosemirror-model";
import { EditorState } from "prosemirror-state";
import { Loro, LoroText } from "loro-crdt";
import { LoroDoc, LoroText } from "loro-crdt";
import {
type LoroDocType,
type LoroNodeMapping,
ROOT_DOC_KEY,
clearChangedNodes,
createNodeFromLoroObj,
getLoroMapAttributes,
getLoroMapChildren,
updateLoroToPmState,
type LoroDocType,
type LoroNodeMapping,
} from "../src/lib";

@@ -23,4 +20,4 @@

insertLoroText,
oneMs,
setupLoroMap,
oneMs,
} from "./utils";

@@ -200,3 +197,3 @@

const editorState = createEditorState(schema, examplePmContent.doc);
const loroDoc: LoroDocType = new Loro();
const loroDoc: LoroDocType = new LoroDoc();
const mapping: LoroNodeMapping = new Map();

@@ -208,3 +205,3 @@ updateLoroToPmState(loroDoc, mapping, editorState);

test("doc syncs changes correctly", () => {
const loroDoc: LoroDocType = new Loro();
const loroDoc: LoroDocType = new LoroDoc();
const mapping: LoroNodeMapping = new Map();

@@ -399,3 +396,3 @@

const _editorState = createEditorState(schema, examplePmContent.doc);
const loroDoc: LoroDocType = new Loro();
const loroDoc: LoroDocType = new LoroDoc();
const mapping: LoroNodeMapping = new Map();

@@ -407,3 +404,3 @@ updateLoroToPmState(loroDoc, mapping, _editorState);

loroDoc.getMap(ROOT_DOC_KEY),
mapping,
mapping
);

@@ -415,3 +412,3 @@ const editorState = createEditorState(schema, examplePmContent.doc);

test("node syncs changes correctly", async () => {
const loroDoc: LoroDocType = new Loro();
const loroDoc: LoroDocType = new LoroDoc();
const mapping: LoroNodeMapping = new Map();

@@ -501,3 +498,3 @@

getLoroMapChildren(loroInnerDoc),
"bulletList",
"bulletList"
);

@@ -507,3 +504,3 @@ const bullet1 = insertLoroMap(getLoroMapChildren(bulletList), "listItem");

getLoroMapChildren(bullet1),
"paragraph",
"paragraph"
);

@@ -516,3 +513,3 @@ const bullet1Text = insertLoroText(getLoroMapChildren(bullet1Paragraph));

getLoroMapChildren(bullet2),
"paragraph",
"paragraph"
);

@@ -519,0 +516,0 @@ const bullet2Text = insertLoroText(getLoroMapChildren(bullet2Paragraph));

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