Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@udecode/plate-link

Package Overview
Dependencies
Maintainers
2
Versions
188
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@udecode/plate-link - npm Package Compare versions

Comparing version 7.0.2 to 8.0.0

dist/onKeyDownLink.d.ts

2

CHANGELOG.md
# @udecode/plate-link
## 8.0.0
## 7.0.2

@@ -4,0 +6,0 @@

6

dist/createLinkPlugin.d.ts

@@ -1,7 +0,7 @@

import { PlatePlugin } from '@udecode/plate-core';
import { WithLinkOptions } from './types';
import { LinkPlugin } from './types';
export declare const ELEMENT_LINK = "a";
/**
* Enables support for hyperlinks.
*/
export declare const createLinkPlugin: (options?: WithLinkOptions | undefined) => PlatePlugin;
export declare const createLinkPlugin: <T = {}>(override?: Partial<import("@udecode/plate-core").PlatePlugin<T, LinkPlugin>> | undefined, overrideByKey?: import("@udecode/plate-core").OverrideByKey<T> | undefined) => import("@udecode/plate-core").PlatePlugin<T, LinkPlugin>;
//# sourceMappingURL=createLinkPlugin.d.ts.map

@@ -5,5 +5,3 @@ /**

export * from './createLinkPlugin';
export * from './defaults';
export * from './getLinkDeserialize';
export * from './getLinkOnKeyDown';
export * from './onKeyDownLink';
export * from './types';

@@ -10,0 +8,0 @@ export * from './withLink';

@@ -1,33 +0,5 @@

import { getPlatePluginOptions, getPlatePluginType, getRenderElement, getPlatePluginTypes } from '@udecode/plate-core';
import { getNodeDeserializer, wrapNodes, isCollapsed, insertNodes, unwrapNodes, getAbove, isUrl, getRangeBefore, getText, someNode, getRangeFromBlockStart } from '@udecode/plate-common';
import { wrapNodes, getPluginType, isCollapsed, insertNodes, unwrapNodes, getAbove, getRangeBefore, getText, someNode, mockPlugin, getRangeFromBlockStart, createPluginFactory, isUrl } from '@udecode/plate-core';
import { Editor, Transforms } from 'slate';
import { withRemoveEmptyNodes } from '@udecode/plate-normalizers';
const ELEMENT_LINK = 'a';
const DEFAULTS_LINK = {
getNodeProps: ({
element
}) => ({
url: element === null || element === void 0 ? void 0 : element.url
}),
hotkey: 'mod+k'
};
const getLinkDeserialize = () => editor => {
const options = getPlatePluginOptions(editor, ELEMENT_LINK);
return {
element: getNodeDeserializer({
type: options.type,
getNode: el => ({
type: options.type,
url: el.getAttribute('href')
}),
rules: [{
nodeNames: 'A'
}],
...options.deserialize
})
};
};
function unwrapExports (x) {

@@ -306,3 +278,3 @@ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;

wrapNodes(editor, {
type: getPlatePluginType(editor, ELEMENT_LINK),
type: getPluginType(editor, ELEMENT_LINK),
url,

@@ -327,3 +299,3 @@ children: []

if (!editor.selection) return;
const type = getPlatePluginType(editor, ELEMENT_LINK);
const type = getPluginType(editor, ELEMENT_LINK);

@@ -363,3 +335,3 @@ if (!wrap && isCollapsed(editor.selection)) {

const getAndUpsertLink = async (editor, getLinkUrl) => {
const type = getPlatePluginType(editor, ELEMENT_LINK);
const type = getPluginType(editor, ELEMENT_LINK);
let prevUrl = '';

@@ -388,3 +360,3 @@ const linkNode = getAbove(editor, {

match: {
type: getPlatePluginType(editor, ELEMENT_LINK)
type: getPluginType(editor, ELEMENT_LINK)
}

@@ -403,6 +375,8 @@ });

const getLinkOnKeyDown = options => editor => e => {
const {
const onKeyDownLink = (editor, {
options: {
getLinkUrl,
hotkey
} = getPlatePluginOptions(editor, ELEMENT_LINK);
}
}) => e => {
if (!hotkey) return;

@@ -413,3 +387,3 @@

e.stopPropagation();
getAndUpsertLink(editor, options === null || options === void 0 ? void 0 : options.getLinkUrl);
getAndUpsertLink(editor, getLinkUrl);
}

@@ -425,3 +399,3 @@ };

match: {
type: getPlatePluginType(editor, ELEMENT_LINK)
type: getPluginType(editor, ELEMENT_LINK)
}

@@ -463,11 +437,9 @@ });

const withLink = ({
isUrl: isUrl$1 = isUrl,
rangeBeforeOptions = {
matchString: ' ',
skipInvalid: true,
afterMatch: true,
multiPaths: true
const withLink = (editor, {
type,
options: {
isUrl,
rangeBeforeOptions
}
} = {}) => editor => {
}) => {
const {

@@ -477,3 +449,2 @@ insertData,

} = editor;
const type = getPlatePluginType(editor, ELEMENT_LINK);

@@ -485,4 +456,7 @@ editor.insertText = text => {

if (upsertLinkIfValid(editor, {
isUrl: isUrl$1
isUrl
})) {
Transforms.move(editor, {
unit: 'offset'
});
return insertText(text);

@@ -496,3 +470,3 @@ }

if (isUrl$1(beforeWordText)) {
if (isUrl(beforeWordText)) {
upsertLink(editor, {

@@ -502,2 +476,5 @@ url: beforeWordText,

});
Transforms.move(editor, {
unit: 'offset'
});
}

@@ -514,3 +491,3 @@ }

if (text) {
if (isUrl$1(text)) {
if (isUrl(text)) {
return upsertLinkAtSelection(editor, {

@@ -540,8 +517,11 @@ url: text

editor = withRemoveEmptyNodes({
type
})(editor);
editor = withRemoveEmptyNodes(editor, mockPlugin({
options: {
types: type
}
}));
return editor;
};
const ELEMENT_LINK = 'a';
/**

@@ -551,12 +531,41 @@ * Enables support for hyperlinks.

const createLinkPlugin = options => ({
pluginKeys: ELEMENT_LINK,
renderElement: getRenderElement(ELEMENT_LINK),
deserialize: getLinkDeserialize(),
inlineTypes: getPlatePluginTypes(ELEMENT_LINK),
onKeyDown: getLinkOnKeyDown(options),
withOverrides: withLink(options)
const createLinkPlugin = createPluginFactory({
key: ELEMENT_LINK,
isElement: true,
isInline: true,
props: ({
element
}) => ({
nodeProps: {
url: element === null || element === void 0 ? void 0 : element.url
}
}),
handlers: {
onKeyDown: onKeyDownLink
},
withOverrides: withLink,
options: {
isUrl: isUrl,
rangeBeforeOptions: {
matchString: ' ',
skipInvalid: true,
afterMatch: true,
multiPaths: true
},
hotkey: 'mod+k'
},
then: (editor, {
type
}) => ({
deserializeHtml: {
getNode: el => ({
type,
url: el.getAttribute('href')
}),
validNodeName: 'A'
}
})
});
export { DEFAULTS_LINK, ELEMENT_LINK, createLinkPlugin, getAndUpsertLink, getLinkDeserialize, getLinkOnKeyDown, upsertLinkAtSelection, withLink, wrapLink };
export { ELEMENT_LINK, createLinkPlugin, getAndUpsertLink, onKeyDownLink, upsertLinkAtSelection, withLink, wrapLink };
//# sourceMappingURL=index.es.js.map

@@ -6,33 +6,5 @@ 'use strict';

var plateCore = require('@udecode/plate-core');
var plateCommon = require('@udecode/plate-common');
var slate = require('slate');
var plateNormalizers = require('@udecode/plate-normalizers');
const ELEMENT_LINK = 'a';
const DEFAULTS_LINK = {
getNodeProps: ({
element
}) => ({
url: element === null || element === void 0 ? void 0 : element.url
}),
hotkey: 'mod+k'
};
const getLinkDeserialize = () => editor => {
const options = plateCore.getPlatePluginOptions(editor, ELEMENT_LINK);
return {
element: plateCommon.getNodeDeserializer({
type: options.type,
getNode: el => ({
type: options.type,
url: el.getAttribute('href')
}),
rules: [{
nodeNames: 'A'
}],
...options.deserialize
})
};
};
function unwrapExports (x) {

@@ -310,4 +282,4 @@ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, 'default') ? x['default'] : x;

}) => {
plateCommon.wrapNodes(editor, {
type: plateCore.getPlatePluginType(editor, ELEMENT_LINK),
plateCore.wrapNodes(editor, {
type: plateCore.getPluginType(editor, ELEMENT_LINK),
url,

@@ -332,6 +304,6 @@ children: []

if (!editor.selection) return;
const type = plateCore.getPlatePluginType(editor, ELEMENT_LINK);
const type = plateCore.getPluginType(editor, ELEMENT_LINK);
if (!wrap && plateCommon.isCollapsed(editor.selection)) {
return plateCommon.insertNodes(editor, {
if (!wrap && plateCore.isCollapsed(editor.selection)) {
return plateCore.insertNodes(editor, {
type,

@@ -346,3 +318,3 @@ url,

if (wrap && plateCommon.isCollapsed(editor.selection)) {
if (wrap && plateCore.isCollapsed(editor.selection)) {
const linkLeaf = slate.Editor.leaf(editor, editor.selection);

@@ -353,3 +325,3 @@ const [, inlinePath] = linkLeaf;

plateCommon.unwrapNodes(editor, {
plateCore.unwrapNodes(editor, {
at: editor.selection,

@@ -370,5 +342,5 @@ match: {

const getAndUpsertLink = async (editor, getLinkUrl) => {
const type = plateCore.getPlatePluginType(editor, ELEMENT_LINK);
const type = plateCore.getPluginType(editor, ELEMENT_LINK);
let prevUrl = '';
const linkNode = plateCommon.getAbove(editor, {
const linkNode = plateCore.getAbove(editor, {
match: {

@@ -392,6 +364,6 @@ type

if (!url) {
linkNode && editor.selection && plateCommon.unwrapNodes(editor, {
linkNode && editor.selection && plateCore.unwrapNodes(editor, {
at: editor.selection,
match: {
type: plateCore.getPlatePluginType(editor, ELEMENT_LINK)
type: plateCore.getPluginType(editor, ELEMENT_LINK)
}

@@ -403,3 +375,3 @@ });

const shouldWrap = linkNode !== undefined && plateCommon.isCollapsed(editor.selection);
const shouldWrap = linkNode !== undefined && plateCore.isCollapsed(editor.selection);
upsertLinkAtSelection(editor, {

@@ -411,6 +383,8 @@ url,

const getLinkOnKeyDown = options => editor => e => {
const {
const onKeyDownLink = (editor, {
options: {
getLinkUrl,
hotkey
} = plateCore.getPlatePluginOptions(editor, ELEMENT_LINK);
}
}) => e => {
if (!hotkey) return;

@@ -421,3 +395,3 @@

e.stopPropagation();
getAndUpsertLink(editor, options === null || options === void 0 ? void 0 : options.getLinkUrl);
getAndUpsertLink(editor, getLinkUrl);
}

@@ -430,6 +404,6 @@ };

}) => {
plateCommon.unwrapNodes(editor, {
plateCore.unwrapNodes(editor, {
at,
match: {
type: plateCore.getPlatePluginType(editor, ELEMENT_LINK)
type: plateCore.getPluginType(editor, ELEMENT_LINK)
}

@@ -449,4 +423,4 @@ });

}) => {
const rangeFromBlockStart = plateCommon.getRangeFromBlockStart(editor);
const textFromBlockStart = plateCommon.getText(editor, rangeFromBlockStart);
const rangeFromBlockStart = plateCore.getRangeFromBlockStart(editor);
const textFromBlockStart = plateCore.getText(editor, rangeFromBlockStart);

@@ -472,11 +446,9 @@ if (rangeFromBlockStart && isUrl(textFromBlockStart)) {

const withLink = ({
isUrl = plateCommon.isUrl,
rangeBeforeOptions = {
matchString: ' ',
skipInvalid: true,
afterMatch: true,
multiPaths: true
const withLink = (editor, {
type,
options: {
isUrl,
rangeBeforeOptions
}
} = {}) => editor => {
}) => {
const {

@@ -486,6 +458,5 @@ insertData,

} = editor;
const type = plateCore.getPlatePluginType(editor, ELEMENT_LINK);
editor.insertText = text => {
if (text === ' ' && plateCommon.isCollapsed(editor.selection)) {
if (text === ' ' && plateCore.isCollapsed(editor.selection)) {
const selection = editor.selection;

@@ -496,9 +467,12 @@

})) {
slate.Transforms.move(editor, {
unit: 'offset'
});
return insertText(text);
}
const beforeWordRange = plateCommon.getRangeBefore(editor, selection, rangeBeforeOptions);
const beforeWordRange = plateCore.getRangeBefore(editor, selection, rangeBeforeOptions);
if (beforeWordRange) {
const beforeWordText = plateCommon.getText(editor, beforeWordRange);
const beforeWordText = plateCore.getText(editor, beforeWordRange);

@@ -510,2 +484,5 @@ if (isUrl(beforeWordText)) {

});
slate.Transforms.move(editor, {
unit: 'offset'
});
}

@@ -528,3 +505,3 @@ }

if (plateCommon.someNode(editor, {
if (plateCore.someNode(editor, {
match: {

@@ -548,8 +525,11 @@ type

editor = plateNormalizers.withRemoveEmptyNodes({
type
})(editor);
editor = plateNormalizers.withRemoveEmptyNodes(editor, plateCore.mockPlugin({
options: {
types: type
}
}));
return editor;
};
const ELEMENT_LINK = 'a';
/**

@@ -559,17 +539,44 @@ * Enables support for hyperlinks.

const createLinkPlugin = options => ({
pluginKeys: ELEMENT_LINK,
renderElement: plateCore.getRenderElement(ELEMENT_LINK),
deserialize: getLinkDeserialize(),
inlineTypes: plateCore.getPlatePluginTypes(ELEMENT_LINK),
onKeyDown: getLinkOnKeyDown(options),
withOverrides: withLink(options)
const createLinkPlugin = plateCore.createPluginFactory({
key: ELEMENT_LINK,
isElement: true,
isInline: true,
props: ({
element
}) => ({
nodeProps: {
url: element === null || element === void 0 ? void 0 : element.url
}
}),
handlers: {
onKeyDown: onKeyDownLink
},
withOverrides: withLink,
options: {
isUrl: plateCore.isUrl,
rangeBeforeOptions: {
matchString: ' ',
skipInvalid: true,
afterMatch: true,
multiPaths: true
},
hotkey: 'mod+k'
},
then: (editor, {
type
}) => ({
deserializeHtml: {
getNode: el => ({
type,
url: el.getAttribute('href')
}),
validNodeName: 'A'
}
})
});
exports.DEFAULTS_LINK = DEFAULTS_LINK;
exports.ELEMENT_LINK = ELEMENT_LINK;
exports.createLinkPlugin = createLinkPlugin;
exports.getAndUpsertLink = getAndUpsertLink;
exports.getLinkDeserialize = getLinkDeserialize;
exports.getLinkOnKeyDown = getLinkOnKeyDown;
exports.onKeyDownLink = onKeyDownLink;
exports.upsertLinkAtSelection = upsertLinkAtSelection;

@@ -576,0 +583,0 @@ exports.withLink = withLink;

import { PlateEditor } from '@udecode/plate-core';
import { WithLinkOptions } from '../types';
export declare const getAndUpsertLink: <T = {}>(editor: PlateEditor<T>, getLinkUrl?: WithLinkOptions['getLinkUrl']) => Promise<void>;
import { LinkPlugin } from '../types';
export declare const getAndUpsertLink: <T = {}>(editor: PlateEditor<T>, getLinkUrl?: LinkPlugin['getLinkUrl']) => Promise<void>;
//# sourceMappingURL=getAndUpsertLink.d.ts.map

@@ -7,3 +7,3 @@ import { PlateEditor } from '@udecode/plate-core';

*/
export declare const upsertLinkAtSelection: (editor: PlateEditor, { url, wrap, }: {
export declare const upsertLinkAtSelection: <T = {}>(editor: PlateEditor<T>, { url, wrap, }: {
url: string;

@@ -10,0 +10,0 @@ /**

@@ -6,3 +6,3 @@ import { PlateEditor } from '@udecode/plate-core';

*/
export declare const wrapLink: (editor: PlateEditor, { at, url }: {
export declare const wrapLink: <T = {}>(editor: PlateEditor<T>, { at, url }: {
url: string;

@@ -9,0 +9,0 @@ at?: Location | undefined;

@@ -1,6 +0,6 @@

import { RangeBeforeOptions } from '@udecode/plate-common';
import { HotkeyPlugin, RangeBeforeOptions } from '@udecode/plate-core';
export interface LinkNodeData {
url: string;
}
export interface WithLinkOptions {
export interface LinkPlugin extends HotkeyPlugin {
/**

@@ -7,0 +7,0 @@ * Allow custom config for rangeBeforeOptions.

import { WithOverride } from '@udecode/plate-core';
import { WithLinkOptions } from './types';
import { LinkPlugin } from './types';
/**

@@ -12,3 +12,3 @@ * Insert space after a url to wrap a link.

*/
export declare const withLink: ({ isUrl, rangeBeforeOptions, }?: WithLinkOptions) => WithOverride;
export declare const withLink: WithOverride<{}, LinkPlugin>;
//# sourceMappingURL=withLink.d.ts.map
{
"name": "@udecode/plate-link",
"version": "7.0.2",
"version": "8.0.0",
"description": "Link plugin for Plate",

@@ -35,5 +35,4 @@ "keywords": [

"dependencies": {
"@udecode/plate-common": "7.0.2",
"@udecode/plate-core": "7.0.2",
"@udecode/plate-normalizers": "7.0.2"
"@udecode/plate-core": "8.0.0",
"@udecode/plate-normalizers": "8.0.0"
},

@@ -40,0 +39,0 @@ "peerDependencies": {

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

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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc