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

prosemirror-paste-rules

Package Overview
Dependencies
Maintainers
1
Versions
212
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

prosemirror-paste-rules - npm Package Compare versions

Comparing version 0.0.0-pr706.17 to 0.0.0-pr706.18

15

dist/declarations/src/paste-rules-plugin.d.ts

@@ -44,3 +44,3 @@ import { MarkType, NodeType } from 'prosemirror-model';

* The names of marks for which this paste rule can be ignored. This means
* that if the matched content contains this mark it will be ignored..
* that if the matched content contains this mark it will be ignored.
*/

@@ -57,5 +57,7 @@ ignoredMarks?: string[];

/**
* A helper function for setting the attributes for a transformation .
* A helper function for setting the attributes for a transformation.
*
* The second parameter is `true` when the attributes are retrieved for a replacement.
*/
getAttributes?: Record<string, unknown> | ((match: string[]) => Record<string, unknown> | undefined);
getAttributes?: Record<string, unknown> | ((match: string[], isReplacement: boolean) => Record<string, unknown> | undefined);
}

@@ -74,2 +76,9 @@ /**

markType: MarkType;
/**
* Set to `true` to replace the selection. When the regex matches for the
* selected text.
*
* Can be a function which receives the text that will be replaced.
*/
replaceSelection?: boolean | ((replacedText: string) => boolean);
}

@@ -76,0 +85,0 @@ export interface NodePasteRule extends BaseContentPasteRule {

41

dist/prosemirror-paste-rules.browser.cjs.js

@@ -65,3 +65,3 @@ 'use strict';

for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _rule$ignoredNodes, _rule$ignoredMarks;
var _rule$ignoredNodes, _rule$ignoredMarks, _slice$content$firstC, _slice$content$firstC2;

@@ -76,2 +76,25 @@ var rule = _step2.value;

var textContent = (_slice$content$firstC = (_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.textContent) !== null && _slice$content$firstC !== void 0 ? _slice$content$firstC : '';
var canBeReplaced = !_view.state.selection.empty && slice.content.childCount === 1 && textContent;
var _match = coreHelpers.findMatches(textContent, rule.regexp)[0];
if (canBeReplaced && _match && rule.type === 'mark' && rule.replaceSelection) {
var _view$state$selection = _view.state.selection,
from = _view$state$selection.from,
to = _view$state$selection.to;
var textSlice = _view.state.doc.slice(from, to);
var textNode = textSlice.content.firstChild;
if (textNode !== null && textNode !== void 0 && textNode.isText && (typeof rule.replaceSelection !== 'boolean' ? rule.replaceSelection(textNode.textContent) : rule.replaceSelection)) {
var getAttributes = rule.getAttributes,
markType = rule.markType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(_match, true) : getAttributes; // const nodeWithMark = textNode.mark([markType.create(attributes), ...textNode.marks]);
// return new Slice(nodeWithMark.content, slice.openStart, slice.openEnd);
return new prosemirrorModel.Slice(prosemirrorModel.Fragment.fromArray([textNode.mark([markType.create(attributes), ...textNode.marks])]), $pos.depth, $pos.depth);
}
}
slice = new prosemirrorModel.Slice(regexPasteRuleHandler(slice.content, rule, _view.state.schema), slice.openStart, slice.openEnd);

@@ -277,7 +300,7 @@ }

for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var _match = _step5.value;
var _match2 = _step5.value;
// The captured value from the regex.
var capturedValue = _match[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match);
var fullValue = _match[0];
var capturedValue = _match2[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2);
var fullValue = _match2[0];

@@ -290,3 +313,3 @@ if ( // This helps prevent matches which are only whitespace from triggering

var start = _match.index;
var start = _match2.index;
var end = start + fullValue.length;

@@ -320,3 +343,3 @@

textNode,
match: _match,
match: _match2,
schema

@@ -354,3 +377,3 @@ });

markType = rule.markType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(textNode.mark([markType.create(attributes), ...textNode.marks]));

@@ -370,3 +393,3 @@ }

nodeType = rule.nodeType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(nodeType.create(attributes, textNode));

@@ -373,0 +396,0 @@ }

@@ -5,3 +5,3 @@ import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';

import { ExtensionPriority } from '@remirror/core-constants';
import { sort, includes, findMatches, isString, range, isFunction } from '@remirror/core-helpers';
import { sort, includes, findMatches, isFunction, isString, range } from '@remirror/core-helpers';

@@ -62,3 +62,3 @@ /**

for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _rule$ignoredNodes, _rule$ignoredMarks;
var _rule$ignoredNodes, _rule$ignoredMarks, _slice$content$firstC, _slice$content$firstC2;

@@ -73,2 +73,25 @@ var rule = _step2.value;

var textContent = (_slice$content$firstC = (_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.textContent) !== null && _slice$content$firstC !== void 0 ? _slice$content$firstC : '';
var canBeReplaced = !_view.state.selection.empty && slice.content.childCount === 1 && textContent;
var _match = findMatches(textContent, rule.regexp)[0];
if (canBeReplaced && _match && rule.type === 'mark' && rule.replaceSelection) {
var _view$state$selection = _view.state.selection,
from = _view$state$selection.from,
to = _view$state$selection.to;
var textSlice = _view.state.doc.slice(from, to);
var textNode = textSlice.content.firstChild;
if (textNode !== null && textNode !== void 0 && textNode.isText && (typeof rule.replaceSelection !== 'boolean' ? rule.replaceSelection(textNode.textContent) : rule.replaceSelection)) {
var getAttributes = rule.getAttributes,
markType = rule.markType;
var attributes = isFunction(getAttributes) ? getAttributes(_match, true) : getAttributes; // const nodeWithMark = textNode.mark([markType.create(attributes), ...textNode.marks]);
// return new Slice(nodeWithMark.content, slice.openStart, slice.openEnd);
return new Slice(Fragment.fromArray([textNode.mark([markType.create(attributes), ...textNode.marks])]), $pos.depth, $pos.depth);
}
}
slice = new Slice(regexPasteRuleHandler(slice.content, rule, _view.state.schema), slice.openStart, slice.openEnd);

@@ -274,7 +297,7 @@ }

for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var _match = _step5.value;
var _match2 = _step5.value;
// The captured value from the regex.
var capturedValue = _match[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match);
var fullValue = _match[0];
var capturedValue = _match2[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2);
var fullValue = _match2[0];

@@ -287,3 +310,3 @@ if ( // This helps prevent matches which are only whitespace from triggering

var start = _match.index;
var start = _match2.index;
var end = start + fullValue.length;

@@ -317,3 +340,3 @@

textNode,
match: _match,
match: _match2,
schema

@@ -351,3 +374,3 @@ });

markType = rule.markType;
var attributes = isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(textNode.mark([markType.create(attributes), ...textNode.marks]));

@@ -367,3 +390,3 @@ }

nodeType = rule.nodeType;
var attributes = isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(nodeType.create(attributes, textNode));

@@ -370,0 +393,0 @@ }

@@ -65,3 +65,3 @@ 'use strict';

for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _rule$ignoredNodes, _rule$ignoredMarks;
var _rule$ignoredNodes, _rule$ignoredMarks, _slice$content$firstC, _slice$content$firstC2;

@@ -76,2 +76,25 @@ var rule = _step2.value;

var textContent = (_slice$content$firstC = (_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.textContent) !== null && _slice$content$firstC !== void 0 ? _slice$content$firstC : '';
var canBeReplaced = !_view.state.selection.empty && slice.content.childCount === 1 && textContent;
var _match = coreHelpers.findMatches(textContent, rule.regexp)[0];
if (canBeReplaced && _match && rule.type === 'mark' && rule.replaceSelection) {
var _view$state$selection = _view.state.selection,
from = _view$state$selection.from,
to = _view$state$selection.to;
var textSlice = _view.state.doc.slice(from, to);
var textNode = textSlice.content.firstChild;
if (textNode !== null && textNode !== void 0 && textNode.isText && (typeof rule.replaceSelection !== 'boolean' ? rule.replaceSelection(textNode.textContent) : rule.replaceSelection)) {
var getAttributes = rule.getAttributes,
markType = rule.markType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(_match, true) : getAttributes; // const nodeWithMark = textNode.mark([markType.create(attributes), ...textNode.marks]);
// return new Slice(nodeWithMark.content, slice.openStart, slice.openEnd);
return new prosemirrorModel.Slice(prosemirrorModel.Fragment.fromArray([textNode.mark([markType.create(attributes), ...textNode.marks])]), $pos.depth, $pos.depth);
}
}
slice = new prosemirrorModel.Slice(regexPasteRuleHandler(slice.content, rule, _view.state.schema), slice.openStart, slice.openEnd);

@@ -277,7 +300,7 @@ }

for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var _match = _step5.value;
var _match2 = _step5.value;
// The captured value from the regex.
var capturedValue = _match[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match);
var fullValue = _match[0];
var capturedValue = _match2[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2);
var fullValue = _match2[0];

@@ -290,3 +313,3 @@ if ( // This helps prevent matches which are only whitespace from triggering

var start = _match.index;
var start = _match2.index;
var end = start + fullValue.length;

@@ -320,3 +343,3 @@

textNode,
match: _match,
match: _match2,
schema

@@ -354,3 +377,3 @@ });

markType = rule.markType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(textNode.mark([markType.create(attributes), ...textNode.marks]));

@@ -370,3 +393,3 @@ }

nodeType = rule.nodeType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(nodeType.create(attributes, textNode));

@@ -373,0 +396,0 @@ }

@@ -65,3 +65,3 @@ 'use strict';

for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _rule$ignoredNodes, _rule$ignoredMarks;
var _rule$ignoredNodes, _rule$ignoredMarks, _slice$content$firstC, _slice$content$firstC2;

@@ -76,2 +76,25 @@ var rule = _step2.value;

var textContent = (_slice$content$firstC = (_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.textContent) !== null && _slice$content$firstC !== void 0 ? _slice$content$firstC : '';
var canBeReplaced = !_view.state.selection.empty && slice.content.childCount === 1 && textContent;
var _match = coreHelpers.findMatches(textContent, rule.regexp)[0];
if (canBeReplaced && _match && rule.type === 'mark' && rule.replaceSelection) {
var _view$state$selection = _view.state.selection,
from = _view$state$selection.from,
to = _view$state$selection.to;
var textSlice = _view.state.doc.slice(from, to);
var textNode = textSlice.content.firstChild;
if (textNode !== null && textNode !== void 0 && textNode.isText && (typeof rule.replaceSelection !== 'boolean' ? rule.replaceSelection(textNode.textContent) : rule.replaceSelection)) {
var getAttributes = rule.getAttributes,
markType = rule.markType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(_match, true) : getAttributes; // const nodeWithMark = textNode.mark([markType.create(attributes), ...textNode.marks]);
// return new Slice(nodeWithMark.content, slice.openStart, slice.openEnd);
return new prosemirrorModel.Slice(prosemirrorModel.Fragment.fromArray([textNode.mark([markType.create(attributes), ...textNode.marks])]), $pos.depth, $pos.depth);
}
}
slice = new prosemirrorModel.Slice(regexPasteRuleHandler(slice.content, rule, _view.state.schema), slice.openStart, slice.openEnd);

@@ -277,7 +300,7 @@ }

for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var _match = _step5.value;
var _match2 = _step5.value;
// The captured value from the regex.
var capturedValue = _match[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match);
var fullValue = _match[0];
var capturedValue = _match2[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2);
var fullValue = _match2[0];

@@ -290,3 +313,3 @@ if ( // This helps prevent matches which are only whitespace from triggering

var start = _match.index;
var start = _match2.index;
var end = start + fullValue.length;

@@ -320,3 +343,3 @@

textNode,
match: _match,
match: _match2,
schema

@@ -354,3 +377,3 @@ });

markType = rule.markType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(textNode.mark([markType.create(attributes), ...textNode.marks]));

@@ -370,3 +393,3 @@ }

nodeType = rule.nodeType;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(nodeType.create(attributes, textNode));

@@ -373,0 +396,0 @@ }

@@ -5,3 +5,3 @@ import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper';

import { ExtensionPriority } from '@remirror/core-constants';
import { sort, includes, findMatches, isString, range, isFunction } from '@remirror/core-helpers';
import { sort, includes, findMatches, isFunction, isString, range } from '@remirror/core-helpers';

@@ -62,3 +62,3 @@ /**

for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
var _rule$ignoredNodes, _rule$ignoredMarks;
var _rule$ignoredNodes, _rule$ignoredMarks, _slice$content$firstC, _slice$content$firstC2;

@@ -73,2 +73,25 @@ var rule = _step2.value;

var textContent = (_slice$content$firstC = (_slice$content$firstC2 = slice.content.firstChild) === null || _slice$content$firstC2 === void 0 ? void 0 : _slice$content$firstC2.textContent) !== null && _slice$content$firstC !== void 0 ? _slice$content$firstC : '';
var canBeReplaced = !_view.state.selection.empty && slice.content.childCount === 1 && textContent;
var _match = findMatches(textContent, rule.regexp)[0];
if (canBeReplaced && _match && rule.type === 'mark' && rule.replaceSelection) {
var _view$state$selection = _view.state.selection,
from = _view$state$selection.from,
to = _view$state$selection.to;
var textSlice = _view.state.doc.slice(from, to);
var textNode = textSlice.content.firstChild;
if (textNode !== null && textNode !== void 0 && textNode.isText && (typeof rule.replaceSelection !== 'boolean' ? rule.replaceSelection(textNode.textContent) : rule.replaceSelection)) {
var getAttributes = rule.getAttributes,
markType = rule.markType;
var attributes = isFunction(getAttributes) ? getAttributes(_match, true) : getAttributes; // const nodeWithMark = textNode.mark([markType.create(attributes), ...textNode.marks]);
// return new Slice(nodeWithMark.content, slice.openStart, slice.openEnd);
return new Slice(Fragment.fromArray([textNode.mark([markType.create(attributes), ...textNode.marks])]), $pos.depth, $pos.depth);
}
}
slice = new Slice(regexPasteRuleHandler(slice.content, rule, _view.state.schema), slice.openStart, slice.openEnd);

@@ -274,7 +297,7 @@ }

for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
var _match = _step5.value;
var _match2 = _step5.value;
// The captured value from the regex.
var capturedValue = _match[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match);
var fullValue = _match[0];
var capturedValue = _match2[1];
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2);
var fullValue = _match2[0];

@@ -287,3 +310,3 @@ if ( // This helps prevent matches which are only whitespace from triggering

var start = _match.index;
var start = _match2.index;
var end = start + fullValue.length;

@@ -317,3 +340,3 @@

textNode,
match: _match,
match: _match2,
schema

@@ -351,3 +374,3 @@ });

markType = rule.markType;
var attributes = isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(textNode.mark([markType.create(attributes), ...textNode.marks]));

@@ -367,3 +390,3 @@ }

nodeType = rule.nodeType;
var attributes = isFunction(getAttributes) ? getAttributes(match) : getAttributes;
var attributes = isFunction(getAttributes) ? getAttributes(match, false) : getAttributes;
nodes.push(nodeType.create(attributes, textNode));

@@ -370,0 +393,0 @@ }

{
"name": "prosemirror-paste-rules",
"version": "0.0.0-pr706.17",
"version": "0.0.0-pr706.18",
"description": "Better handling of pasted content in your prosemirror editor.",

@@ -35,15 +35,14 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/prosemirror-paste-rules",

"@babel/runtime": "^7.13.10",
"@remirror/core-constants": "0.0.0-pr706.17",
"@remirror/core-helpers": "0.0.0-pr706.17",
"escape-string-regexp": "^4.0.0",
"type-fest": "^0.21.3"
"@remirror/core-constants": "0.0.0-pr706.18",
"@remirror/core-helpers": "0.0.0-pr706.18",
"escape-string-regexp": "^4.0.0"
},
"devDependencies": {
"@types/prosemirror-keymap": "^1.0.4",
"@types/prosemirror-model": "^1.11.2",
"@types/prosemirror-model": "^1.13.0",
"@types/prosemirror-state": "^1.2.6",
"@types/prosemirror-view": "^1.17.1",
"prosemirror-model": "^1.13.3",
"prosemirror-model": "^1.14.0",
"prosemirror-state": "^1.3.4",
"prosemirror-view": "^1.17.4"
"prosemirror-view": "^1.18.3"
},

@@ -50,0 +49,0 @@ "peerDependencies": {

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