Detalhes do pacote

prosemirror-test-builder

prosemirror575.8kMIT1.1.1

Helpers for programatically building ProseMirror test documents

readme (leia-me)

prosemirror-test-builder

[ WEBSITE | ISSUES | FORUM | GITTER ]

This is a module used to write tests for ProseMirror. ProseMirror is a well-behaved rich semantic content editor based on contentEditable, with support for collaborative editing and custom document schemas.

This module provides helpers for building ProseMirror documents for tests. It's main file exports a basic schema with list support, and a number of functions, whose name mostly follows the corresponding HTML tag, to create nodes and marks in this schema. The prosemirror-test-builder/dist/build module exports a function that you can use to create such helpers for your own schema.

Node builder functions optionally take an attribute object as their first argument, followed by zero or more child nodes, and return a node with those attributes and children. Children should be either strings (for text nodes), existing nodes, or the result of calling a mark builder. Mark builder functions work similarly, but return an object representing a set of nodes rather than a single node.

These builders help specifying and retrieving positions in the documents that you created (to avoid needing to count tokens when writing tests). Inside of strings passed as child nodes, angle-brackets <name> syntax can be used to place a tag called name at that position. The angle-bracketed part will not appear in the result node, but is stored in the node's tag property, which is an object mapping tag names to position integers. A string which is only a tag or set of tags may appear everywhere, even in places where text nodes aren't allowed.

So if you've imported doc and p from this module, the expression doc(p("foo<a>")) will return a document containing a single paragraph, and its .tag.a will hold the number 4 (the position at the end of the paragraph).

In addition to defining a function for each mark and node name in the test schema, the module exports the following helpers:

schema: The test schema itself.

p: A builder for paragraph nodes.

pre: A builder for code block nodes.

h1: A builder for heading block nodes with the level attribute defaulting to 1.

h2: A builder for heading block nodes with the level attribute defaulting to 2.

h3: A builder for heading block nodes with the level attribute defaulting to 3.

li: A builder for list item nodes.

ol: A builder for ordered list nodes.

ul: A builder for bullet list nodes.

br: A builder for hard break nodes.

img: A builder for image nodes, with the src attribute defaulting to "img.png".

hr: A builder for horizontal rule nodes.

a: A builder for link marks.

The package also exports the following helpers:

builders(schema: Schema, names?: Object<Attrs>) → Object

Create a object of builders for a custom schema. Will return an object with a schema property and one builder for each node and mark in the schema. The second argument can be used to add custom builders—if given, it should be an object mapping names to attribute objects, which may contain a nodeType or markType property to specify which node or mark the builder by this name should create.

eq(a, b) → boolean

Calls a.eq(b). Can be useful to pass as comparison predicate when comparing ProseMirror nodes or slices.

License

This module is open source and distributed under an MIT license.

We aim to be an inclusive, welcoming community. To make that explicit, we have a code of conduct that applies to communication around the project.

changelog (log de mudanças)

1.1.1 (2023-05-17)

Bug fixes

Make the return type of `builders` include properties for schema node/mark names.

Include CommonJS type declarations in the package to please new TypeScript resolution settings.

1.1.0 (2022-05-30)

New features

Include TypeScript type declarations.

1.0.6 (2022-03-29)

Bug fixes

Make it possible to specify multiple marks of the same type for a given piece of content.

1.0.5 (2021-10-14)

Bug fixes

Go back to regular dependencies, so that the package works on NPM <7.

1.0.4 (2021-04-27)

Bug fixes

Treat ProseMirror libraries as peer dependencies, to avoid duplicate libraries when using this.

1.0.3 (2020-01-28)

Bug fixes

Rename ES module files to use a .js extension, since Webpack gets confused by .mjs

1.0.2 (2019-11-19)

Bug fixes

The file referred to in the package's module field now is compiled down to ES5.

1.0.1 (2018-01-05)

Bug fixes

Fix overly restrictive depencency version ranges.

1.0.0 (2017-10-13)

First stable release.