1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2026-01-03 23:42:28 +03:00

Lexical: Updated URL handling, added mouse handling

- Removed URL protocol allow-list to allow any as per old editor.
- Added mouse handling, so that clicks below many last hard-to-escape
  block types will add an empty new paragraph for easy escaping &
  editing.
This commit is contained in:
Dan Brown
2025-07-25 13:58:48 +01:00
parent 865e5aecc9
commit c54101c603
5 changed files with 133 additions and 22 deletions

View File

@@ -48,14 +48,6 @@ export type SerializedLinkNode = Spread<
type LinkHTMLElementType = HTMLAnchorElement | HTMLSpanElement;
const SUPPORTED_URL_PROTOCOLS = new Set([
'http:',
'https:',
'mailto:',
'sms:',
'tel:',
]);
/** @noInheritDoc */
export class LinkNode extends ElementNode {
/** @internal */
@@ -90,7 +82,7 @@ export class LinkNode extends ElementNode {
createDOM(config: EditorConfig): LinkHTMLElementType {
const element = document.createElement('a');
element.href = this.sanitizeUrl(this.__url);
element.href = this.__url;
if (this.__target !== null) {
element.target = this.__target;
}
@@ -166,19 +158,6 @@ export class LinkNode extends ElementNode {
return node;
}
sanitizeUrl(url: string): string {
try {
const parsedUrl = new URL(url);
// eslint-disable-next-line no-script-url
if (!SUPPORTED_URL_PROTOCOLS.has(parsedUrl.protocol)) {
return 'about:blank';
}
} catch {
return url;
}
return url;
}
exportJSON(): SerializedLinkNode | SerializedAutoLinkNode {
return {
...super.exportJSON(),