slate-paste-linkify
Advanced tools
Comparing version 0.6.2 to 0.7.0
@@ -7,5 +7,12 @@ # Changelog | ||
### `0.7.0` — October 10, 2018 | ||
- Change to use commands and queries instead of previous options. | ||
- Update for `slate@0.42`. | ||
--- | ||
### `0.6.0` — August 6, 2018 | ||
- Update for `slate@0.37.0`. | ||
- Update for `slate@0.37`. | ||
@@ -16,3 +23,3 @@ --- | ||
- Update for `slate@0.29.0`. | ||
- Update for `slate@0.29`. | ||
@@ -23,3 +30,3 @@ --- | ||
- Update for `slate-react@0.6.0`. | ||
- Update for `slate-react@0.6`. | ||
@@ -30,3 +37,3 @@ --- | ||
- Update for `slate@0.22.0`. | ||
- Update for `slate@0.22`. | ||
@@ -37,3 +44,3 @@ --- | ||
- Update for `slate@0.8.0`. | ||
- Update for `slate@0.8`. | ||
@@ -40,0 +47,0 @@ --- |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('slate-react')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'slate-react'], factory) : | ||
(factory((global.SlatePasteLinkify = {}),global.SlateReact)); | ||
}(this, (function (exports,slateReact) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(factory((global.SlatePasteLinkify = {}))); | ||
}(this, (function (exports) { 'use strict'; | ||
@@ -30,175 +30,43 @@ /** | ||
/** | ||
* Export. | ||
*/ | ||
var toNoCase_1 = toNoCase; | ||
/** | ||
* Test whether a string is camel-case. | ||
*/ | ||
var hasSpace = /\s/; | ||
var hasSeparator = /(_|-|\.|:)/; | ||
var hasCamel = /([a-z][A-Z]|[A-Z][a-z])/; | ||
/** | ||
* Remove any starting case from a `string`, like camel or snake, but keep | ||
* spaces and punctuation that may be important otherwise. | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
*/ | ||
function toNoCase(string) { | ||
if (hasSpace.test(string)) return string.toLowerCase() | ||
if (hasSeparator.test(string)) return (unseparate(string) || string).toLowerCase() | ||
if (hasCamel.test(string)) return uncamelize(string).toLowerCase() | ||
return string.toLowerCase() | ||
} | ||
/** | ||
* Separator splitter. | ||
*/ | ||
var separatorSplitter = /[\W_]+(.|$)/g; | ||
/** | ||
* Un-separate a `string`. | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
*/ | ||
function unseparate(string) { | ||
return string.replace(separatorSplitter, function (m, next) { | ||
return next ? ' ' + next : '' | ||
}) | ||
} | ||
/** | ||
* Camelcase splitter. | ||
*/ | ||
var camelSplitter = /(.)([A-Z]+)/g; | ||
/** | ||
* Un-camelcase a `string`. | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
*/ | ||
function uncamelize(string) { | ||
return string.replace(camelSplitter, function (m, previous, uppers) { | ||
return previous + ' ' + uppers.toLowerCase().split('').join(' ') | ||
}) | ||
} | ||
/** | ||
* Export. | ||
*/ | ||
var toSpaceCase_1 = toSpaceCase; | ||
/** | ||
* Convert a `string` to space case. | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
*/ | ||
function toSpaceCase(string) { | ||
return toNoCase_1(string).replace(/[\W_]+(.|$)/g, function (matches, match) { | ||
return match ? ' ' + match : '' | ||
}).trim() | ||
} | ||
/** | ||
* Export. | ||
*/ | ||
var toPascalCase_1 = toPascalCase; | ||
/** | ||
* Convert a `string` to pascal case. | ||
* | ||
* @param {String} string | ||
* @return {String} | ||
*/ | ||
function toPascalCase(string) { | ||
return toSpaceCase_1(string).replace(/(?:^|\s)(\w)/g, function (matches, letter) { | ||
return letter.toUpperCase() | ||
}) | ||
} | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
* A Slate plugin to add soft breaks on return. | ||
* | ||
* @param {Object} options | ||
* @property {String} type | ||
* @property {String} hrefProperty | ||
* @property {String} collapseTo | ||
* @return {Object} | ||
*/ | ||
function PasteLinkify() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var _options$type = options.type, | ||
type = _options$type === undefined ? 'link' : _options$type, | ||
_options$hrefProperty = options.hrefProperty, | ||
hrefProperty = _options$hrefProperty === undefined ? 'href' : _options$hrefProperty; | ||
var _options$isActiveQuer = options.isActiveQuery, | ||
isActiveQuery = _options$isActiveQuer === undefined ? 'isLinkActive' : _options$isActiveQuer, | ||
_options$wrapCommand = options.wrapCommand, | ||
wrapCommand = _options$wrapCommand === undefined ? 'wrapLink' : _options$wrapCommand, | ||
_options$unwrapComman = options.unwrapCommand, | ||
unwrapCommand = _options$unwrapComman === undefined ? 'unwrapLink' : _options$unwrapComman; | ||
function hasLinks(value) { | ||
return value.inlines.some(function (inline) { | ||
return inline.type == type; | ||
}); | ||
} | ||
function unwrapLink(change) { | ||
change.unwrapInline(type); | ||
} | ||
function wrapLink(change, href) { | ||
change.wrapInline({ | ||
type: type, | ||
data: _defineProperty({}, hrefProperty, href) | ||
}); | ||
} | ||
return { | ||
onPaste: function onPaste(event, change) { | ||
var transfer = slateReact.getEventTransfer(event); | ||
onCommand: function onCommand(command, change, next) { | ||
var type = command.type, | ||
args = command.args; | ||
var value = change.value; | ||
var selection = value.selection; | ||
var text = transfer.text; | ||
var isCollapsed = selection.isCollapsed, | ||
start = selection.start; | ||
var url = void 0; | ||
if (transfer.type !== 'text' && transfer.type !== 'html') { | ||
return; | ||
} | ||
if (type === 'insertText' && isUrl_1(url = args[0]) || type === 'insertFragment' && isUrl_1(url = args[0].text)) { | ||
// If there is already a link active, unwrap it so that we don't end up | ||
// with a confusing overlapping inline situation. | ||
if (change.query(isActiveQuery, value)) { | ||
change.command(unwrapCommand); | ||
} | ||
if (!isUrl_1(text)) { | ||
// If the selection is collapsed, we need to allow the default inserting | ||
// to occur instead of just wrapping the existing text in a link. | ||
if (isCollapsed) { | ||
next(); | ||
change.moveAnchorTo(start.offset).moveFocusTo(start.offset + url.length); | ||
} | ||
// Wrap the selection in a link, and collapse to the end of it. | ||
change.command(wrapCommand, url).moveToEnd(); | ||
return; | ||
} | ||
if (selection.isCollapsed) { | ||
var startOffset = selection.startOffset; | ||
change.insertText(text).moveAnchorTo(startOffset).moveFocusTo(startOffset + text.length); | ||
} else if (hasLinks(value)) { | ||
change.call(unwrapLink); | ||
} | ||
change.call(wrapLink, text); | ||
if (options.collapseTo) { | ||
change['moveTo' + toPascalCase_1(options.collapseTo)](); | ||
} | ||
return change; | ||
next(); | ||
} | ||
@@ -205,0 +73,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("slate-react")):"function"==typeof define&&define.amd?define(["exports","slate-react"],t):t(e.SlatePasteLinkify={},e.SlateReact)}(this,function(e,t){"use strict";var n=function(e){return r.test(e)},r=/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/;var o=function(e){return a.test(e)?e.toLowerCase():i.test(e)?(function(e){return e.replace(c,function(e,t){return t?" "+t:""})}(e)||e).toLowerCase():u.test(e)?function(e){return e.replace(l,function(e,t,n){return t+" "+n.toLowerCase().split("").join(" ")})}(e).toLowerCase():e.toLowerCase()},a=/\s/,i=/(_|-|\.|:)/,u=/([a-z][A-Z]|[A-Z][a-z])/;var c=/[\W_]+(.|$)/g;var l=/(.)([A-Z]+)/g;var s=function(e){return o(e).replace(/[\W_]+(.|$)/g,function(e,t){return t?" "+t:""}).trim()};var f=function(e){return s(e).replace(/(?:^|\s)(\w)/g,function(e,t){return t.toUpperCase()})};e.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},r=e.type,o=void 0===r?"link":r,a=e.hrefProperty,i=void 0===a?"href":a;function u(e){e.unwrapInline(o)}function c(e,t){var n,r,a;e.wrapInline({type:o,data:(n={},r=i,a=t,r in n?Object.defineProperty(n,r,{value:a,enumerable:!0,configurable:!0,writable:!0}):n[r]=a,n)})}return{onPaste:function(r,a){var i=t.getEventTransfer(r),l=a.value,s=l.selection,p=i.text;if(("text"===i.type||"html"===i.type)&&n(p)){if(s.isCollapsed){var v=s.startOffset;a.insertText(p).moveAnchorTo(v).moveFocusTo(v+p.length)}else(function(e){return e.inlines.some(function(e){return e.type==o})})(l)&&a.call(u);return a.call(c,p),e.collapseTo&&a["moveTo"+f(e.collapseTo)](),a}}}},Object.defineProperty(e,"__esModule",{value:!0})}); | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t(e.SlatePasteLinkify={})}(this,function(e){"use strict";var t=function(e){return o.test(e)},o=/^(?:\w+:)?\/\/([^\s\.]+\.\S{2}|localhost[\:?\d]*)\S*$/;e.default=function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},o=e.isActiveQuery,n=void 0===o?"isLinkActive":o,i=e.wrapCommand,r=void 0===i?"wrapLink":i,d=e.unwrapCommand,a=void 0===d?"unwrapLink":d;return{onCommand:function(e,o,i){var d=e.type,s=e.args,f=o.value,u=f.selection,c=u.isCollapsed,m=u.start,v=void 0;if("insertText"===d&&t(v=s[0])||"insertFragment"===d&&t(v=s[0].text))return o.query(n,f)&&o.command(a),c&&(i(),o.moveAnchorTo(m.offset).moveFocusTo(m.offset+v.length)),void o.command(r,v).moveToEnd();i()}}},Object.defineProperty(e,"__esModule",{value:!0})}); |
import isUrl from 'is-url'; | ||
import toPascal from 'to-pascal-case'; | ||
import { getEventTransfer } from 'slate-react'; | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
* A Slate plugin to add soft breaks on return. | ||
* | ||
* @param {Object} options | ||
* @property {String} type | ||
* @property {String} hrefProperty | ||
* @property {String} collapseTo | ||
* @return {Object} | ||
*/ | ||
function PasteLinkify() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var _options$type = options.type, | ||
type = _options$type === undefined ? 'link' : _options$type, | ||
_options$hrefProperty = options.hrefProperty, | ||
hrefProperty = _options$hrefProperty === undefined ? 'href' : _options$hrefProperty; | ||
var _options$isActiveQuer = options.isActiveQuery, | ||
isActiveQuery = _options$isActiveQuer === undefined ? 'isLinkActive' : _options$isActiveQuer, | ||
_options$wrapCommand = options.wrapCommand, | ||
wrapCommand = _options$wrapCommand === undefined ? 'wrapLink' : _options$wrapCommand, | ||
_options$unwrapComman = options.unwrapCommand, | ||
unwrapCommand = _options$unwrapComman === undefined ? 'unwrapLink' : _options$unwrapComman; | ||
function hasLinks(value) { | ||
return value.inlines.some(function (inline) { | ||
return inline.type == type; | ||
}); | ||
} | ||
function unwrapLink(change) { | ||
change.unwrapInline(type); | ||
} | ||
function wrapLink(change, href) { | ||
change.wrapInline({ | ||
type: type, | ||
data: _defineProperty({}, hrefProperty, href) | ||
}); | ||
} | ||
return { | ||
onPaste: function onPaste(event, change) { | ||
var transfer = getEventTransfer(event); | ||
onCommand: function onCommand(command, change, next) { | ||
var type = command.type, | ||
args = command.args; | ||
var value = change.value; | ||
var selection = value.selection; | ||
var text = transfer.text; | ||
var isCollapsed = selection.isCollapsed, | ||
start = selection.start; | ||
var url = void 0; | ||
if (transfer.type !== 'text' && transfer.type !== 'html') { | ||
return; | ||
} | ||
if (type === 'insertText' && isUrl(url = args[0]) || type === 'insertFragment' && isUrl(url = args[0].text)) { | ||
// If there is already a link active, unwrap it so that we don't end up | ||
// with a confusing overlapping inline situation. | ||
if (change.query(isActiveQuery, value)) { | ||
change.command(unwrapCommand); | ||
} | ||
if (!isUrl(text)) { | ||
// If the selection is collapsed, we need to allow the default inserting | ||
// to occur instead of just wrapping the existing text in a link. | ||
if (isCollapsed) { | ||
next(); | ||
change.moveAnchorTo(start.offset).moveFocusTo(start.offset + url.length); | ||
} | ||
// Wrap the selection in a link, and collapse to the end of it. | ||
change.command(wrapCommand, url).moveToEnd(); | ||
return; | ||
} | ||
if (selection.isCollapsed) { | ||
var startOffset = selection.startOffset; | ||
change.insertText(text).moveAnchorTo(startOffset).moveFocusTo(startOffset + text.length); | ||
} else if (hasLinks(value)) { | ||
change.call(unwrapLink); | ||
} | ||
change.call(wrapLink, text); | ||
if (options.collapseTo) { | ||
change['moveTo' + toPascal(options.collapseTo)](); | ||
} | ||
return change; | ||
next(); | ||
} | ||
@@ -74,0 +45,0 @@ }; |
@@ -8,73 +8,44 @@ 'use strict'; | ||
var isUrl = _interopDefault(require('is-url')); | ||
var toPascal = _interopDefault(require('to-pascal-case')); | ||
var slateReact = require('slate-react'); | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
/** | ||
* A Slate plugin to add soft breaks on return. | ||
* | ||
* @param {Object} options | ||
* @property {String} type | ||
* @property {String} hrefProperty | ||
* @property {String} collapseTo | ||
* @return {Object} | ||
*/ | ||
function PasteLinkify() { | ||
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var _options$type = options.type, | ||
type = _options$type === undefined ? 'link' : _options$type, | ||
_options$hrefProperty = options.hrefProperty, | ||
hrefProperty = _options$hrefProperty === undefined ? 'href' : _options$hrefProperty; | ||
var _options$isActiveQuer = options.isActiveQuery, | ||
isActiveQuery = _options$isActiveQuer === undefined ? 'isLinkActive' : _options$isActiveQuer, | ||
_options$wrapCommand = options.wrapCommand, | ||
wrapCommand = _options$wrapCommand === undefined ? 'wrapLink' : _options$wrapCommand, | ||
_options$unwrapComman = options.unwrapCommand, | ||
unwrapCommand = _options$unwrapComman === undefined ? 'unwrapLink' : _options$unwrapComman; | ||
function hasLinks(value) { | ||
return value.inlines.some(function (inline) { | ||
return inline.type == type; | ||
}); | ||
} | ||
function unwrapLink(change) { | ||
change.unwrapInline(type); | ||
} | ||
function wrapLink(change, href) { | ||
change.wrapInline({ | ||
type: type, | ||
data: _defineProperty({}, hrefProperty, href) | ||
}); | ||
} | ||
return { | ||
onPaste: function onPaste(event, change) { | ||
var transfer = slateReact.getEventTransfer(event); | ||
onCommand: function onCommand(command, change, next) { | ||
var type = command.type, | ||
args = command.args; | ||
var value = change.value; | ||
var selection = value.selection; | ||
var text = transfer.text; | ||
var isCollapsed = selection.isCollapsed, | ||
start = selection.start; | ||
var url = void 0; | ||
if (transfer.type !== 'text' && transfer.type !== 'html') { | ||
return; | ||
} | ||
if (type === 'insertText' && isUrl(url = args[0]) || type === 'insertFragment' && isUrl(url = args[0].text)) { | ||
// If there is already a link active, unwrap it so that we don't end up | ||
// with a confusing overlapping inline situation. | ||
if (change.query(isActiveQuery, value)) { | ||
change.command(unwrapCommand); | ||
} | ||
if (!isUrl(text)) { | ||
// If the selection is collapsed, we need to allow the default inserting | ||
// to occur instead of just wrapping the existing text in a link. | ||
if (isCollapsed) { | ||
next(); | ||
change.moveAnchorTo(start.offset).moveFocusTo(start.offset + url.length); | ||
} | ||
// Wrap the selection in a link, and collapse to the end of it. | ||
change.command(wrapCommand, url).moveToEnd(); | ||
return; | ||
} | ||
if (selection.isCollapsed) { | ||
var startOffset = selection.startOffset; | ||
change.insertText(text).moveAnchorTo(startOffset).moveFocusTo(startOffset + text.length); | ||
} else if (hasLinks(value)) { | ||
change.call(unwrapLink); | ||
} | ||
change.call(wrapLink, text); | ||
if (options.collapseTo) { | ||
change['moveTo' + toPascal(options.collapseTo)](); | ||
} | ||
return change; | ||
next(); | ||
} | ||
@@ -81,0 +52,0 @@ }; |
{ | ||
"name": "slate-paste-linkify", | ||
"description": "A Slate plugin that wraps a selection in an inline link element when a URL is pasted from the clipboard.", | ||
"version": "0.6.2", | ||
"version": "0.7.0", | ||
"license": "MIT", | ||
@@ -16,8 +16,7 @@ "repository": "git://github.com/ianstormtaylor/slate-plugins.git", | ||
"dependencies": { | ||
"is-url": "^1.2.2", | ||
"to-pascal-case": "^1.0.0" | ||
"is-url": "^1.2.2" | ||
}, | ||
"peerDependencies": { | ||
"slate": ">=0.37.0", | ||
"slate-react": ">=0.15.0" | ||
"slate": ">=0.42.2", | ||
"slate-react": ">=0.19.2" | ||
}, | ||
@@ -24,0 +23,0 @@ "keywords": [ |
@@ -13,5 +13,3 @@ ### `slate-paste-linkify` | ||
const plugins = [ | ||
PasteLinkify({ | ||
type: 'link' | ||
}) | ||
PasteLinkify() | ||
] | ||
@@ -26,6 +24,8 @@ | ||
| Option | Type | Description | | ||
| --------------------- | -------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | | ||
| **`type`** (required) | `String` | The type of the inline element to create. | | ||
| **`hrefProperty`** | `String` | The key of the data property to store the link's `href` in. Defaults to `'href'`. | | ||
| **`collapseTo`** | `String` | The edge to collapse the selection to after pasting the link, either: `'start'`, `'end'`, `'anchor'`, `'focus'`. If this option is not passed, the selection will stay expanded. | | ||
This plugin works by taking in options that specify link-related commands and queries to execute when it detects that the user is trying to insert a link (by pasting or drag-dropping). This way you can define the exact behavior you want in the commands, but delegate the detection of links being inserted to the plugin. | ||
| Option | Type | Description | | ||
| ----------------------------------------------- | -------- | -------------------------------------------------------------------------------------------------------------------- | | ||
| **`isActiveQuery`** (default: `'isLinkActive'`) | `String` | The name of the query that checks whether the current selection has a link in it to unwrap. | | ||
| **`wrapCommand`** (default: `'wrapLink'`) | `String` | The name of the command that wraps the selection in a link. It will be passed the `url` of the link as its argument. | | ||
| **`unwrapCommand`** (default: `'unwrapLink'`) | `String` | The name of the command that unwraps a link in the current selection. | |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
3
2
15389
149
- Removedto-pascal-case@^1.0.0
- Removed@juggle/resize-observer@3.4.0(transitive)
- Removed@types/is-hotkey@0.1.10(transitive)
- Removed@types/lodash@4.17.1(transitive)
- Removedcompute-scroll-into-view@3.1.0(transitive)
- Removeddirection@1.0.4(transitive)
- Removedis-hotkey@0.2.0(transitive)
- Removedjs-tokens@4.0.0(transitive)
- Removedlodash@4.17.21(transitive)
- Removedloose-envify@1.4.0(transitive)
- Removedreact@18.3.1(transitive)
- Removedreact-dom@18.3.1(transitive)
- Removedscheduler@0.23.2(transitive)
- Removedscroll-into-view-if-needed@3.1.0(transitive)
- Removedslate-react@0.102.0(transitive)
- Removedtiny-invariant@1.3.1(transitive)
- Removedto-no-case@1.0.2(transitive)
- Removedto-pascal-case@1.0.0(transitive)
- Removedto-space-case@1.0.0(transitive)