sibiraj-s / ngx-editor

🖋️ Rich Text Editor for angular using ProseMirror
https://sibiraj-s.github.io/ngx-editor/
MIT License
458 stars 191 forks source link

[Bug]: Pasting a hyperlink in the editor with disabled 'link' mark causes JS error #584

Open Makaopior opened 2 weeks ago

Makaopior commented 2 weeks ago

What happened?

Create Editor using custom schema with disabled hyperlinks. That is, Editor should disallow creating <a> elements.

const nodes = {
  doc: basicNodes.doc,
  paragraph: basicNodes.paragraph,
  text: basicNodes.text,
  image: basicNodes.image,
  hard_break: basicNodes.hard_break,
  list_item: basicNodes.list_item,
  ordered_list: basicNodes.ordered_list,
  bullet_list: basicNodes.bullet_list,
};

const marks = {
  em: basicMarks.em,
  strong: basicMarks.strong,
  u: basicMarks.u,
  text_color: basicMarks.text_color,
  // link: basicMarks.link      <-- disallowed links
};

const ngxEditorSchema = new Schema({
  nodes,
  marks,
});

// ...

  this.editor = new Editor({
    history: true,
    schema: ngxEditorSchema,
  });

Copy-paste an arbitrary HTML-formatted content including a hyperlink. For example, this area: image

Expected: The hyperlink part becomes plain text. No errors raised.

Actual The hyperlink part indeed becomes plain text, but JS error appears in the console. image

Version

v17.5.4

Angular Version

v17.3.12

What browsers are you seeing the problem on?

Chrome

Link to reproduce

https://stackblitz.com/edit/ngx-editor-ekfbzm?file=src%2Fapp%2Fapp.component.ts

Relevant log output

preview-587cd39a5889a.js:2 ERROR TypeError: Cannot read properties of undefined (reading 'create')
    at eval (link.ts:35:6)
    at Fragment.forEach (index.cjs:344:21)
    at linkify (link.ts:17:9)
    at eval (link.ts:44:21)
    at Fragment.forEach (index.cjs:344:21)
    at linkify (link.ts:17:9)
    at Plugin.transformPasted (stringUtil.ts:1:53)
    at eval (index.cjs:3105:17)
    at EditorView.someProp (index.cjs:5684:60)
    at parseFromClipboard (index.cjs:3104:10)

Willing to submit a PR?

None