@tiptap/extension-link
Advanced tools
Comparing version 2.0.0-alpha.4 to 2.0.0-alpha.5
@@ -6,2 +6,10 @@ # Change Log | ||
# [2.0.0-alpha.5](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-link@2.0.0-alpha.4...@tiptap/extension-link@2.0.0-alpha.5) (2020-12-18) | ||
**Note:** Version bump only for package @tiptap/extension-link | ||
# [2.0.0-alpha.4](https://github.com/ueberdosis/tiptap-next/compare/@tiptap/extension-link@2.0.0-alpha.3...@tiptap/extension-link@2.0.0-alpha.4) (2020-12-02) | ||
@@ -8,0 +16,0 @@ |
@@ -1,35 +0,3 @@ | ||
import { Command, Mark } from '@tiptap/core'; | ||
export interface LinkOptions { | ||
openOnClick: boolean; | ||
HTMLAttributes: { | ||
[key: string]: any; | ||
}; | ||
} | ||
export declare const pasteRegex: RegExp; | ||
export declare const pasteRegexWithBrackets: RegExp; | ||
declare const Link: Mark<LinkOptions, { | ||
/** | ||
* Set a link mark | ||
*/ | ||
setLink: (attributes?: { | ||
href?: string; | ||
target?: string; | ||
}) => Command; | ||
/** | ||
* Toggle a link mark | ||
*/ | ||
toggleLink: (attributes?: { | ||
href?: string; | ||
target?: string; | ||
}) => Command; | ||
/** | ||
* Unset a link mark | ||
*/ | ||
unsetLink: () => Command; | ||
}>; | ||
import { Link } from './link'; | ||
export * from './link'; | ||
export default Link; | ||
declare module '@tiptap/core' { | ||
interface AllExtensions { | ||
Link: typeof Link; | ||
} | ||
} |
@@ -88,2 +88,3 @@ 'use strict'; | ||
exports.Link = Link; | ||
exports.default = Link; | ||
@@ -90,0 +91,0 @@ exports.pasteRegex = pasteRegex; |
@@ -85,3 +85,3 @@ import { Mark, mergeAttributes, markPasteRule } from '@tiptap/core'; | ||
export default Link; | ||
export { pasteRegex, pasteRegexWithBrackets }; | ||
export { Link, pasteRegex, pasteRegexWithBrackets }; | ||
//# sourceMappingURL=tiptap-extension-link.esm.js.map |
@@ -87,2 +87,3 @@ (function (global, factory) { | ||
exports.Link = Link; | ||
exports.default = Link; | ||
@@ -89,0 +90,0 @@ exports.pasteRegex = pasteRegex; |
{ | ||
"name": "@tiptap/extension-link", | ||
"description": "link extension for tiptap", | ||
"version": "2.0.0-alpha.4", | ||
"version": "2.0.0-alpha.5", | ||
"homepage": "https://tiptap.dev", | ||
@@ -30,3 +30,3 @@ "keywords": [ | ||
}, | ||
"gitHead": "a884cb81de8783d0097741c1ddb97a82ea88ae0e" | ||
"gitHead": "0371cb0a5d803a44d93532aa34419ec7ffffdc24" | ||
} |
114
src/index.ts
@@ -1,115 +0,5 @@ | ||
import { | ||
Command, | ||
Mark, | ||
markPasteRule, | ||
mergeAttributes, | ||
} from '@tiptap/core' | ||
import { Plugin, PluginKey } from 'prosemirror-state' | ||
import { Link } from './link' | ||
export interface LinkOptions { | ||
openOnClick: boolean, | ||
HTMLAttributes: { | ||
[key: string]: any | ||
}, | ||
} | ||
export * from './link' | ||
export const pasteRegex = /https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)/gi | ||
export const pasteRegexWithBrackets = /(?:\()https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/()]*)(?:\))/gi | ||
const Link = Mark.create({ | ||
name: 'link', | ||
inclusive: false, | ||
defaultOptions: <LinkOptions>{ | ||
openOnClick: true, | ||
HTMLAttributes: { | ||
target: '_blank', | ||
rel: 'noopener noreferrer nofollow', | ||
}, | ||
}, | ||
addAttributes() { | ||
return { | ||
href: { | ||
default: null, | ||
}, | ||
target: { | ||
default: this.options.HTMLAttributes.target, | ||
}, | ||
} | ||
}, | ||
parseHTML() { | ||
return [ | ||
{ tag: 'a[href]' }, | ||
] | ||
}, | ||
renderHTML({ HTMLAttributes }) { | ||
return ['a', mergeAttributes(this.options.HTMLAttributes, HTMLAttributes), 0] | ||
}, | ||
addCommands() { | ||
return { | ||
/** | ||
* Set a link mark | ||
*/ | ||
setLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { | ||
return commands.setMark('link', attributes) | ||
}, | ||
/** | ||
* Toggle a link mark | ||
*/ | ||
toggleLink: (attributes: { href?: string, target?: string } = {}): Command => ({ commands }) => { | ||
return commands.toggleMark('link', attributes) | ||
}, | ||
/** | ||
* Unset a link mark | ||
*/ | ||
unsetLink: (): Command => ({ commands }) => { | ||
return commands.unsetMark('link') | ||
}, | ||
} | ||
}, | ||
addPasteRules() { | ||
return [ | ||
markPasteRule(pasteRegex, this.type, (url: string) => ({ href: url })), | ||
markPasteRule(pasteRegexWithBrackets, this.type, (url: string) => ({ href: url })), | ||
] | ||
}, | ||
addProseMirrorPlugins() { | ||
if (!this.options.openOnClick) { | ||
return [] | ||
} | ||
return [ | ||
new Plugin({ | ||
key: new PluginKey('handleClick'), | ||
props: { | ||
handleClick: (view, pos, event) => { | ||
const attrs = this.editor.getMarkAttributes('link') | ||
if (attrs.href && event.target instanceof HTMLAnchorElement) { | ||
window.open(attrs.href, attrs.target) | ||
return false | ||
} | ||
return true | ||
}, | ||
}, | ||
}), | ||
] | ||
}, | ||
}) | ||
export default Link | ||
declare module '@tiptap/core' { | ||
interface AllExtensions { | ||
Link: typeof Link, | ||
} | ||
} |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
467037
16
726