BitBindle.ProseMirror
2.0.0
See the version list below for details.
dotnet add package BitBindle.ProseMirror --version 2.0.0
NuGet\Install-Package BitBindle.ProseMirror -Version 2.0.0
<PackageReference Include="BitBindle.ProseMirror" Version="2.0.0" />
<PackageVersion Include="BitBindle.ProseMirror" Version="2.0.0" />
<PackageReference Include="BitBindle.ProseMirror" />
paket add BitBindle.ProseMirror --version 2.0.0
#r "nuget: BitBindle.ProseMirror, 2.0.0"
#:package BitBindle.ProseMirror@2.0.0
#addin nuget:?package=BitBindle.ProseMirror&version=2.0.0
#tool nuget:?package=BitBindle.ProseMirror&version=2.0.0
ProseMirror.Net
A direct translation of the core ProseMirror packages from TypeScript to C#. Use it to work with ProseMirror documents in .NET:
- Document and step DTOs for JSON serialization and deserialization
- Building and updating documents server-side
- Server-side schema validation
- Building collaborative editing backends
Translated packages:
prosemirror-modelprosemirror-transformprosemirror-test-builderprosemirror-schema-basicprosemirror-schema-list
It also includes a commit-based collab authority, a faster take on prosemirror-collab; see
src/Collab/README.md.
This repository is a fork of stepwisehq/prosemirror-dotnet.
Getting Started
The BitBindle.ProseMirror package is on nuget.org. To install it, run this command:
dotnet add package BitBindle.ProseMirror
The package ID differs from the ID of the original package (StepWise.ProseMirror). The assembly name and the namespaces stay the same. A project cannot reference both packages, because they contain the same assembly name.
Basic Usage
using StepWise.Prose.Model;
var schemaSpec = new SchemaSpec() {
Nodes = new()
{
["doc"] = new() { Content = "paragraph+" },
["paragraph"] = new() { Content = "text*" },
["text"] = new() { }
},
Marks = new()
};
var schema = new Schema(schemaSpec);
var doc = schema.Node("doc", null, [
schema.Node("paragraph", null, [
schema.Text("Hello World")
], null)
], null);
Console.WriteLine(doc.ToString()); // doc(paragraph("Hello World"))
Test Builder & Transform
using StepWise.Prose.Model;
using StepWise.Prose.TestBuilder;
using StepWise.Prose.Transformation;
using static StepWise.Prose.TestBuilder.Builder;
Node node = doc(p("Hello <a>"));
var tr = new Transform(node);
tr.ReplaceWith(node.Tag()["a"], node.Tag()["a"], schema.Text("World"));
Console.WriteLine(tr.Doc.ToString()); // doc(paragraph("Hello World"))
Deserializing Steps
using StepWise.Prose.Model;
using StepWise.Prose.TestBuilder;
using StepWise.Prose.Transformation;
using static StepWise.Prose.TestBuilder.Builder;
Node node = doc(p("Hello <a>"));
var stepJsonString = """{"stepType":"replace","from":7,"to":7,"slice":{"content":[{"type":"text","text":"World","marks":[]}]}}""";
var step = Step.FromJSON(Builder.schema, StepDto.FromJson(stepJsonString));
var tr = new Transform(node);
tr.Step(step);
Console.WriteLine(tr.Doc.ToString()); // doc(paragraph("Hello World"))
Deserializing Docs (Nodes)
using StepWise.Prose.Model;
using StepWise.Prose.TestBuilder;
var docJsonString = """{"type":"doc","content":[{"type":"paragraph","content":[{"type":"text","text":"Hello World","marks":[]}],"marks":[]}],"marks":[]}""";
var doc = Node.FromJSON(Builder.schema, NodeDto.FromJson(docJsonString));
Console.WriteLine(doc.ToString()); // doc(paragraph("Hello World"))
Upgrading from 1.x
2.0 has no package dependencies and targets .NET 10. The JSON it reads and writes is unchanged, so documents and steps stored or sent by 1.x still work. These APIs changed:
- Requires .NET 10 (1.x targeted .NET 8).
- JSON DTOs use plain nullable properties instead of DotNext's
Optional<T>.NodeDto.Attrs,Content,Text,Marks,MarkDto.Attrsand the replace step DTOs'Slicearenullwhen absent;Structureis abool?. Replace.HasValuewithis not null, and.Valuewith the property itself. Attribute dictionaries areDictionary<string, JsonNode?>. AttributeSpec.Defaultis anAttributeDefaultinstead ofOptional<JsonNode>.Default = null,Default = new(1)andDefault = JsonValue.Create(5)work as before;IsUndefinedmeans the attribute is required.OrderedDictionaryinSchemaSpec,BasicSchemaandListSchemais now the .NET one,System.Collections.Generic.OrderedDictionary<TKey, TValue>.StepWise.Prose.Collections.OrderedDictionaryis gone; use the indexer,GetAtandSetAtin place ofGetValue,SetValueandGetItem.- No more
OneOfparameters.Schema.Node,Schema.Mark,Node.RangeHasMarkandTransform.RemoveNodeMarkhave overloads for each type they accept, so calls passing astring,NodeType,MarkorMarkTypecompile unchanged. ResolvedPos.Pathis aList<ResolvedPos.PathEntry>with one(Node, Index, Offset)entry per depth, instead of a flat list of nodes and numbers.- Internals no longer public:
StepMap._map,Mapping._mapandContentMatch.WrapCache. - Test builder: builder children are a
ChildSpecstruct, the builders fromBuilder.Builderstakeparams object[], andBuilder.TagSlotis gone (node.Tag()works as before). - A hand-built
ReplaceStepDtowithoutStructureno longer writes"structure": false, matching ProseMirror.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- No dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.