Skip to content

Commit

Permalink
More tests!
Browse files Browse the repository at this point in the history
  • Loading branch information
smoores-dev committed Aug 14, 2023
1 parent 3861fc4 commit 4eeb077
Show file tree
Hide file tree
Showing 7 changed files with 686 additions and 661 deletions.
11 changes: 10 additions & 1 deletion demo/main.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { baseKeymap, toggleMark } from "prosemirror-commands";
import { keymap } from "prosemirror-keymap";
import { Schema } from "prosemirror-model";
import { EditorState, Plugin } from "prosemirror-state";
import { EditorState, Plugin, TextSelection } from "prosemirror-state";
import { a, doc, p, strong } from "prosemirror-test-builder";
import { Decoration, DecorationSet } from "prosemirror-view";
import "prosemirror-view/style/prosemirror.css";
import React, {
Expand Down Expand Up @@ -84,6 +85,13 @@ const editorState = EditorState.create({
plugins: [keymap(baseKeymap)],
});

// const startDoc = doc(p(strong(a("foo<a>"), "bar")));

// const editorState = EditorState.create({
// doc: startDoc,
// selection: TextSelection.create(startDoc, startDoc.tag.a),
// });

const Paragraph = forwardRef(function Paragraph(
{
children,
Expand All @@ -97,6 +105,7 @@ const Paragraph = forwardRef(function Paragraph(
ref: Ref<HTMLParagraphElement>
) {
useView((view) => {
view.focus();
// eslint-disable-next-line no-console
// console.log(pos, view.coordsAtPos(pos));
});
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@nytimes/react-prosemirror",
"version": "0.2.3",
"version": "0.3.0-alpha.4",
"license": "Apache-2.0",
"type": "module",
"main": "dist/cjs/index.js",
Expand Down Expand Up @@ -39,6 +39,7 @@
"test": "jest"
},
"devDependencies": {
"@jest/globals": "^29.6.2",
"@swc/cli": "^0.1.61",
"@swc/core": "^1.3.32",
"@swc/jest": "^0.2.24",
Expand All @@ -60,6 +61,7 @@
"eslint-plugin-jest": "^27.2.1",
"eslint-plugin-react": "^7.32.2",
"eslint-plugin-react-hooks": "^4.6.0",
"expect": "^29.6.2",
"husky": "^8.0.3",
"jest": "^29.0.0",
"jest-environment-jsdom": "^29.4.1",
Expand Down
11 changes: 9 additions & 2 deletions src/components/OutputSpec.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ type Props = {
children: ReactNode;
};

export const OutputSpec = forwardRef(function OutputSpec(
const ForwardedOutputSpec = forwardRef(function OutputSpec(
{ outputSpec, children, ...initialProps }: Props,
ref
) {
Expand All @@ -19,6 +19,7 @@ export const OutputSpec = forwardRef(function OutputSpec(
"@nytimes/react-prosemirror only supports strings and arrays in toDOM"
);
}

const tagSpec = outputSpec[0] as string;
const tagName = tagSpec.replace(" ", ":");
const attrs = outputSpec[1];
Expand Down Expand Up @@ -49,7 +50,13 @@ export const OutputSpec = forwardRef(function OutputSpec(
}
return createElement(tagName, props, children);
}
content.push(<OutputSpec outputSpec={child}>{children}</OutputSpec>);
content.push(
<ForwardedOutputSpec ref={undefined} outputSpec={child}>
{children}
</ForwardedOutputSpec>
);
}
return createElement(tagName, props, ...content);
});

export { ForwardedOutputSpec as OutputSpec };
Loading

0 comments on commit 4eeb077

Please sign in to comment.