mirror of
https://github.com/suitenumerique/docs
synced 2026-04-21 13:37:20 +00:00
fixup! 🐛(frontend) sanitize pasted toolbar links
This commit is contained in:
parent
598a6adc02
commit
1115fe3546
1 changed files with 4 additions and 10 deletions
|
|
@ -93,8 +93,6 @@ interface BlockNoteEditorProps {
|
|||
* BlockNote copies links in Markdown autolink format; pasting into the link
|
||||
* toolbar input keeps the brackets, producing broken hrefs.
|
||||
*/
|
||||
const stripAngleBrackets = (text: string): string =>
|
||||
text.replace(/^<(.+)>$/, '$1');
|
||||
|
||||
const handlePasteUrlBrackets = (e: React.ClipboardEvent<HTMLDivElement>) => {
|
||||
const target = e.target;
|
||||
|
|
@ -105,18 +103,14 @@ const handlePasteUrlBrackets = (e: React.ClipboardEvent<HTMLDivElement>) => {
|
|||
return;
|
||||
}
|
||||
const text = e.clipboardData?.getData('text/plain') ?? '';
|
||||
const cleaned = stripAngleBrackets(text.trim());
|
||||
const cleaned = text.replace(/^\s*<([^<>]+)>\s*$/, '$1');
|
||||
if (cleaned === text) {
|
||||
return;
|
||||
}
|
||||
e.preventDefault();
|
||||
// Use the native value setter (input/textarea) so React-controlled fields pick up the pasted value change.
|
||||
const proto =
|
||||
target instanceof HTMLInputElement
|
||||
? HTMLInputElement.prototype
|
||||
: HTMLTextAreaElement.prototype;
|
||||
const setter = Object.getOwnPropertyDescriptor(proto, 'value')?.set;
|
||||
setter?.call(target, cleaned);
|
||||
const start = target.selectionStart ?? target.value.length;
|
||||
const end = target.selectionEnd ?? target.value.length;
|
||||
target.setRangeText(cleaned, start, end, 'end');
|
||||
target.dispatchEvent(new Event('input', { bubbles: true }));
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue