Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
prosemirror-model
Advanced tools
The prosemirror-model package is a part of the ProseMirror toolkit, which provides a powerful, flexible, and customizable framework for building rich text editors. The prosemirror-model package specifically deals with the document model, which includes defining schemas, creating and manipulating documents, and working with nodes and marks.
Defining a Schema
This feature allows you to define a schema for your document. A schema specifies the types of nodes and marks that can appear in the document, as well as their attributes and how they should be serialized to and from DOM.
const { Schema } = require('prosemirror-model');
const mySchema = new Schema({
nodes: {
doc: { content: 'block+' },
paragraph: { content: 'text*', toDOM: () => ['p', 0] },
text: { inline: true }
},
marks: {
strong: { toDOM: () => ['strong', 0] }
}
});
Creating a Document
This feature allows you to create a document using the schema you defined. The document is created from a JSON representation that matches the schema.
const { Node } = require('prosemirror-model');
const doc = Node.fromJSON(mySchema, {
type: 'doc',
content: [
{ type: 'paragraph', content: [{ type: 'text', text: 'Hello, world!' }] }
]
});
Manipulating Nodes
This feature allows you to manipulate nodes within the document. You can create new nodes, copy existing nodes, and create fragments of nodes.
const { Fragment } = require('prosemirror-model');
const paragraph = mySchema.nodes.paragraph.createAndFill();
const textNode = mySchema.text('New text');
const newParagraph = paragraph.copy(Fragment.from(textNode));
Slate is another framework for building rich text editors. It provides a more flexible and less opinionated approach compared to ProseMirror. While ProseMirror uses a schema-based approach to define the document structure, Slate allows for more dynamic and custom data models.
Draft.js is a framework for building rich text editors developed by Facebook. It uses a content state model to represent the document and provides a set of immutable data structures for manipulating the content. Draft.js is more opinionated and less flexible compared to ProseMirror, but it integrates well with React.
Quill is a rich text editor that provides a simple and easy-to-use API. It is less flexible compared to ProseMirror and Slate, but it is very easy to set up and use. Quill is suitable for applications that need a basic rich text editor without much customization.
[ WEBSITE | ISSUES | FORUM | GITTER | CHANGELOG ]
ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.
This module implements ProseMirror's document model, along with the mechanisms needed to support schemas.
The project page has more information, a number of demos and the documentation.
NOTE: This project is in BETA stage. It isn't thoroughly tested,
and the API might still change across 0.x
releases. You are welcome
to use it, but don't expect it to be very stable yet.
This code is released under an MIT license. There's a forum for general discussion and support requests, and the Github bug tracker is the place to report issues.
0.18.0 (2017-02-24)
schema.nodeSpec
and schema.markSpec
have been deprecated in favor of schema.spec
. The properties still work with a warning in this release, but will be dropped in the next.
Node
objects now have a check
method which can be used to assert that they conform to the schema.
Node specs now support an atom
property, and nodes an isAtom
accessor, which is currently only used to determine whether such nodes should be directly selectable (for example when they are rendered as an uneditable node view).
The new excludes
field on mark specs can be used to control the marks that this mark may coexist with. Mark type objects also gained an excludes
method to querty this relation.
Mark specs now support a group
property, and marks can be referred to by group name in content specs.
The Schema
class now provides its whole spec under its spec
property.
The name of a schema's default top-level node is now configurable. You can use schema.topNodeType
to retrieve the top node type.
Parse rules now support a context
field that can be used to only make the rule match inside certain ancestor nodes.
FAQs
ProseMirror's document model
The npm package prosemirror-model receives a total of 1,313,478 weekly downloads. As such, prosemirror-model popularity was classified as popular.
We found that prosemirror-model demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.