hubgit / react-prosemirror

A React component for ProseMirror
https://ow1qi.csb.app/
MIT License
248 stars 51 forks source link

Own Schema does not fill storedMarks / toggle Mark not working #40

Open flokol120 opened 2 years ago

flokol120 commented 2 years ago

I was trying to create a new Schema. I just copied the default schema from react-prosemirror/packages/config-default/schema.ts to get started with something. When using this exact same schema in my own component, marks of the initialValue won't be generated. This means you cannot toggle those marks as they are not generated.

Excerpt:

import {
  plugins,
  toolbar,
  schema as defaultSchema
} from "@aeaton/react-prosemirror-config-default";
(...)
// copied from react-prosemirror/packages/config-default/schema.ts
export const schema = new Schema({
  marks: {
    bold,
    code,
    italic,
    link,
    strikethrough,
    subscript,
    superscript,
    underline
  },
  nodes: {
    text, // plain text node
    doc, // top-level node
    paragraph, // paragraph must be the first node type of the "block" group
    lineBreak,
    heading,
    blockquote,
    codeBlock,
    horizontalRule,
    list,
    listItem,
    table,
    tableRow,
    tableDataCell, // tableDataCell must be the first node type of the "tableCell" group
    tableHeaderCell
  }
});
(...)
return (
  <HtmlEditor
    schema={schema} // schema genereated with new Schema. Excact copy of react-prosemirror/packages/config-default/schema.ts (this IS NOT working)
    // schema={defaultSchema}     // default schema from prosemirror wrapper (this is working)
    plugins={plugins}
    value={initialValue}
    handleChange={setValue}
    debounce={250}
  >
    <Toolbar toolbar={toolbar} />
    <Editor autoFocus />
  </HtmlEditor>
);

Maybe this is a bug, maybe I am just missing something.

I've replicated the issue as stated above using CodeSandbox: https://codesandbox.io/s/recursing-wozniak-o8589?file=/src/App.tsx:1256-1261

If you need any more information, I am happy to provide them to you.