Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
Makaopior opened this issue Nov 12, 2024 · 0 comments

Comments

@Makaopior
Copy link

Makaopior commented Nov 12, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant