pax_global_header00006660000000000000000000000064141321150330014503gustar00rootroot0000000000000052 comment=30435d101ce73b54fb1b564db943a5059267931e prosemirror-test-builder-1.0.5/000077500000000000000000000000001413211503300164725ustar00rootroot00000000000000prosemirror-test-builder-1.0.5/.gitignore000066400000000000000000000000371413211503300204620ustar00rootroot00000000000000/node_modules .tern-port /dist prosemirror-test-builder-1.0.5/.npmignore000066400000000000000000000000371413211503300204710ustar00rootroot00000000000000/node_modules .tern-port /test prosemirror-test-builder-1.0.5/CHANGELOG.md000066400000000000000000000011551413211503300203050ustar00rootroot00000000000000## 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. prosemirror-test-builder-1.0.5/LICENSE000066400000000000000000000021131413211503300174740ustar00rootroot00000000000000Copyright (C) 2015-2017 by Marijn Haverbeke and others Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. prosemirror-test-builder-1.0.5/README.md000066400000000000000000000073721413211503300177620ustar00rootroot00000000000000# prosemirror-test-builder [ [**WEBSITE**](https://prosemirror.net) | [**ISSUES**](https://github.com/prosemirror/prosemirror-test-builder/issues) | [**FORUM**](https://discuss.prosemirror.net) | [**GITTER**](https://gitter.im/ProseMirror/prosemirror) ] This is a module used to write tests for [ProseMirror](https://prosemirror.net). 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. For leaf nodes, you may also pass the builder function itself, without calling it. 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 `` 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"))` 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 `dist/build` submodule exports a single function which can be called with a schema and an optional object of renamed/configured builders to create a object of builders for a custom schema. It 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. ## 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](http://contributor-covenant.org/version/1/1/0/) that applies to communication around the project. prosemirror-test-builder-1.0.5/package.json000066400000000000000000000015151413211503300207620ustar00rootroot00000000000000{ "name": "prosemirror-test-builder", "version": "1.0.5", "description": "Helpers for programatically building ProseMirror test documents", "main": "dist/index.js", "module": "dist/index.es.js", "license": "MIT", "maintainers": [ { "name": "Marijn Haverbeke", "email": "marijnh@gmail.com", "web": "http://marijnhaverbeke.nl" } ], "repository": { "type": "git", "url": "git://github.com/prosemirror/prosemirror-test-builder.git" }, "dependencies": { "prosemirror-model": "^1.0.0", "prosemirror-schema-basic": "^1.0.0", "prosemirror-schema-list": "^1.0.0" }, "devDependencies": { "rollup": "^2.26.3", "@rollup/plugin-buble": "^0.21.3" }, "scripts": { "test": "true", "build": "rollup -c", "watch": "rollup -c -w", "prepare": "npm run build" } } prosemirror-test-builder-1.0.5/rollup.config.js000066400000000000000000000005641413211503300216160ustar00rootroot00000000000000module.exports = { input: "./src/index.js", output: [{ file: 'dist/index.js', format: 'cjs', sourcemap: true, exports: "auto" }, { file: 'dist/index.es.js', format: 'es', sourcemap: true, exports: "auto" }], plugins: [require('@rollup/plugin-buble')()], external(id) { return id[0] != "." && !require("path").isAbsolute(id) } } prosemirror-test-builder-1.0.5/src/000077500000000000000000000000001413211503300172615ustar00rootroot00000000000000prosemirror-test-builder-1.0.5/src/build.js000066400000000000000000000055121413211503300207210ustar00rootroot00000000000000import {Node} from "prosemirror-model" const noTag = Node.prototype.tag = Object.create(null) function flatten(schema, children, f) { let result = [], pos = 0, tag = noTag for (let i = 0; i < children.length; i++) { let child = children[i] if (child.tag && child.tag != Node.prototype.tag) { if (tag == noTag) tag = Object.create(null) for (let id in child.tag) tag[id] = child.tag[id] + (child.flat || child.isText ? 0 : 1) + pos } if (typeof child == "string") { let re = /<(\w+)>/g, m, at = 0, out = "" while (m = re.exec(child)) { out += child.slice(at, m.index) pos += m.index - at at = m.index + m[0].length if (tag == noTag) tag = Object.create(null) tag[m[1]] = pos } out += child.slice(at) pos += child.length - at if (out) result.push(f(schema.text(out))) } else if (child.flat) { for (let j = 0; j < child.flat.length; j++) { let node = f(child.flat[j]) pos += node.nodeSize result.push(node) } } else { let node = f(child) pos += node.nodeSize result.push(node) } } return {nodes: result, tag} } function id(x) { return x } function takeAttrs(attrs, args) { let a0 = args[0] if (!args.length || (a0 && (typeof a0 == "string" || a0 instanceof Node || a0.flat))) return attrs args.shift() if (!attrs) return a0 if (!a0) return attrs let result = {} for (let prop in attrs) result[prop] = attrs[prop] for (let prop in a0) result[prop] = a0[prop] return result } // : (string, ?Object) → (...content: [union]) → Node // Create a builder function for nodes with content. function block(type, attrs) { let result = function(...args) { let myAttrs = takeAttrs(attrs, args) let {nodes, tag} = flatten(type.schema, args, id) let node = type.create(myAttrs, nodes) if (tag != noTag) node.tag = tag return node } if (type.isLeaf) try { result.flat = [type.create(attrs)] } catch(_) {} return result } // Create a builder function for marks. function mark(type, attrs) { return function(...args) { let mark = type.create(takeAttrs(attrs, args)) let {nodes, tag} = flatten(type.schema, args, n => mark.type.isInSet(n.marks) ? n : n.mark(mark.addToSet(n.marks))) return {flat: nodes, tag} } } export default function(schema, names) { let result = {schema} for (let name in schema.nodes) result[name] = block(schema.nodes[name], {}) for (let name in schema.marks) result[name] = mark(schema.marks[name], {}) if (names) for (let name in names) { let value = names[name], typeName = value.nodeType || value.markType || name, type if (type = schema.nodes[typeName]) result[name] = block(type, value) else if (type = schema.marks[typeName]) result[name] = mark(type, value) } return result } prosemirror-test-builder-1.0.5/src/index.js000066400000000000000000000015431413211503300207310ustar00rootroot00000000000000import {schema} from "prosemirror-schema-basic" import {addListNodes} from "prosemirror-schema-list" import {Schema} from "prosemirror-model" import builders from "./build" const testSchema = new Schema({ nodes: addListNodes(schema.spec.nodes, "paragraph block*", "block"), marks: schema.spec.marks }) const out = builders(testSchema, { p: {nodeType: "paragraph"}, pre: {nodeType: "code_block"}, h1: {nodeType: "heading", level: 1}, h2: {nodeType: "heading", level: 2}, h3: {nodeType: "heading", level: 3}, li: {nodeType: "list_item"}, ul: {nodeType: "bullet_list"}, ol: {nodeType: "ordered_list"}, br: {nodeType: "hard_break"}, img: {nodeType: "image", src: "img.png"}, hr: {nodeType: "horizontal_rule"}, a: {markType: "link", href: "foo"}, }) out.eq = function eq(a, b) { return a.eq(b) } out.builders = builders export default out