prosemirror-paste-rules
Advanced tools
Comparing version
@@ -1,2 +0,2 @@ | ||
import { MarkType, NodeType } from 'prosemirror-model'; | ||
import { Fragment, MarkType, Node as ProsemirrorNode, NodeType } from 'prosemirror-model'; | ||
import { Plugin, Selection } from 'prosemirror-state'; | ||
@@ -47,8 +47,2 @@ import type { EditorView } from 'prosemirror-view'; | ||
ignoredMarks?: string[]; | ||
/** | ||
* A function that transforms the match into the desired text value. | ||
* | ||
* Return an empty string to delete all content. | ||
*/ | ||
transformMatch?: (match: RegExpExecArray) => string | null | undefined; | ||
} | ||
@@ -92,2 +86,12 @@ interface BaseContentPasteRule extends BaseRegexPasteRule { | ||
nodeType: NodeType; | ||
/** | ||
* A function that transforms the match into the content to use when creating | ||
* a node. | ||
* | ||
* Pass `() => {}` to remove the matched text. | ||
* | ||
* If this function is undefined, then the text node cutted from the match | ||
* will be used as the content. | ||
*/ | ||
getContent?: (match: RegExpExecArray) => Fragment | ProsemirrorNode | ProsemirrorNode[] | undefined | void; | ||
} | ||
@@ -102,2 +106,8 @@ /** | ||
type: 'text'; | ||
/** | ||
* A function that transforms the match into the desired text value. | ||
* | ||
* Return an empty string to delete all content. | ||
*/ | ||
transformMatch?: (match: RegExpExecArray) => string | null | undefined; | ||
} | ||
@@ -104,0 +114,0 @@ export declare type FileHandlerProps = FilePasteHandlerProps | FileDropHandlerProps; |
@@ -262,4 +262,3 @@ 'use strict'; | ||
ignoredMarks = rule.ignoredMarks, | ||
ignoredNodes = rule.ignoredNodes, | ||
transformMatch = rule.transformMatch; | ||
ignoredNodes = rule.ignoredNodes; | ||
fragment.forEach(child => { | ||
@@ -302,3 +301,2 @@ var _child$text; | ||
var capturedValue = _match2[1]; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2); | ||
var fullValue = _match2[0]; | ||
@@ -319,18 +317,15 @@ | ||
var textNode = child.cut(start, end); // When a transformed value was provided. | ||
var textNode = child.cut(start, end); // When a capture value is provided use it. | ||
if (coreHelpers.isString(transformedCapturedValue)) { | ||
textNode = schema.text(transformedCapturedValue, textNode.marks); | ||
} // When a capture value is provided use it. | ||
else if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
@@ -389,5 +384,7 @@ | ||
var getAttributes = rule.getAttributes, | ||
nodeType = rule.nodeType; | ||
nodeType = rule.nodeType, | ||
getContent = rule.getContent; | ||
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes; | ||
nodes.push(nodeType.create(attributes, textNode)); | ||
var content = (getContent ? getContent(match) : textNode) || undefined; | ||
nodes.push(nodeType.createChecked(attributes, content)); | ||
} | ||
@@ -400,5 +397,18 @@ /** | ||
function textRuleTransformer(props) { | ||
var _ref; | ||
var nodes = props.nodes, | ||
textNode = props.textNode; | ||
nodes.push(textNode); | ||
rule = props.rule, | ||
textNode = props.textNode, | ||
match = props.match, | ||
schema = props.schema; | ||
var transformMatch = rule.transformMatch; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(match); // remove the text if transformMatch return | ||
if (transformedCapturedValue === '') { | ||
return; | ||
} | ||
var text = (_ref = transformedCapturedValue !== null && transformedCapturedValue !== void 0 ? transformedCapturedValue : textNode.text) !== null && _ref !== void 0 ? _ref : ''; | ||
nodes.push(schema.text(text, textNode.marks)); | ||
} | ||
@@ -450,5 +460,5 @@ /** | ||
function isInCode(selection) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$contained = _ref.contained, | ||
contained = _ref$contained === void 0 ? true : _ref$contained; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$contained = _ref2.contained, | ||
contained = _ref2$contained === void 0 ? true : _ref2$contained; | ||
@@ -455,0 +465,0 @@ if (selection.empty) { |
@@ -5,3 +5,3 @@ import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper'; | ||
import { ExtensionPriority } from '@remirror/core-constants'; | ||
import { sort, includes, findMatches, isFunction, isString, range } from '@remirror/core-helpers'; | ||
import { sort, includes, findMatches, isFunction, range } from '@remirror/core-helpers'; | ||
@@ -259,4 +259,3 @@ /** | ||
ignoredMarks = rule.ignoredMarks, | ||
ignoredNodes = rule.ignoredNodes, | ||
transformMatch = rule.transformMatch; | ||
ignoredNodes = rule.ignoredNodes; | ||
fragment.forEach(child => { | ||
@@ -299,3 +298,2 @@ var _child$text; | ||
var capturedValue = _match2[1]; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2); | ||
var fullValue = _match2[0]; | ||
@@ -316,18 +314,15 @@ | ||
var textNode = child.cut(start, end); // When a transformed value was provided. | ||
var textNode = child.cut(start, end); // When a capture value is provided use it. | ||
if (isString(transformedCapturedValue)) { | ||
textNode = schema.text(transformedCapturedValue, textNode.marks); | ||
} // When a capture value is provided use it. | ||
else if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
@@ -386,5 +381,7 @@ | ||
var getAttributes = rule.getAttributes, | ||
nodeType = rule.nodeType; | ||
nodeType = rule.nodeType, | ||
getContent = rule.getContent; | ||
var attributes = isFunction(getAttributes) ? getAttributes(match, false) : getAttributes; | ||
nodes.push(nodeType.create(attributes, textNode)); | ||
var content = (getContent ? getContent(match) : textNode) || undefined; | ||
nodes.push(nodeType.createChecked(attributes, content)); | ||
} | ||
@@ -397,5 +394,18 @@ /** | ||
function textRuleTransformer(props) { | ||
var _ref; | ||
var nodes = props.nodes, | ||
textNode = props.textNode; | ||
nodes.push(textNode); | ||
rule = props.rule, | ||
textNode = props.textNode, | ||
match = props.match, | ||
schema = props.schema; | ||
var transformMatch = rule.transformMatch; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(match); // remove the text if transformMatch return | ||
if (transformedCapturedValue === '') { | ||
return; | ||
} | ||
var text = (_ref = transformedCapturedValue !== null && transformedCapturedValue !== void 0 ? transformedCapturedValue : textNode.text) !== null && _ref !== void 0 ? _ref : ''; | ||
nodes.push(schema.text(text, textNode.marks)); | ||
} | ||
@@ -447,5 +457,5 @@ /** | ||
function isInCode(selection) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$contained = _ref.contained, | ||
contained = _ref$contained === void 0 ? true : _ref$contained; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$contained = _ref2.contained, | ||
contained = _ref2$contained === void 0 ? true : _ref2$contained; | ||
@@ -452,0 +462,0 @@ if (selection.empty) { |
@@ -262,4 +262,3 @@ 'use strict'; | ||
ignoredMarks = rule.ignoredMarks, | ||
ignoredNodes = rule.ignoredNodes, | ||
transformMatch = rule.transformMatch; | ||
ignoredNodes = rule.ignoredNodes; | ||
fragment.forEach(child => { | ||
@@ -302,3 +301,2 @@ var _child$text; | ||
var capturedValue = _match2[1]; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2); | ||
var fullValue = _match2[0]; | ||
@@ -319,18 +317,15 @@ | ||
var textNode = child.cut(start, end); // When a transformed value was provided. | ||
var textNode = child.cut(start, end); // When a capture value is provided use it. | ||
if (coreHelpers.isString(transformedCapturedValue)) { | ||
textNode = schema.text(transformedCapturedValue, textNode.marks); | ||
} // When a capture value is provided use it. | ||
else if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
@@ -389,5 +384,7 @@ | ||
var getAttributes = rule.getAttributes, | ||
nodeType = rule.nodeType; | ||
nodeType = rule.nodeType, | ||
getContent = rule.getContent; | ||
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes; | ||
nodes.push(nodeType.create(attributes, textNode)); | ||
var content = (getContent ? getContent(match) : textNode) || undefined; | ||
nodes.push(nodeType.createChecked(attributes, content)); | ||
} | ||
@@ -400,5 +397,18 @@ /** | ||
function textRuleTransformer(props) { | ||
var _ref; | ||
var nodes = props.nodes, | ||
textNode = props.textNode; | ||
nodes.push(textNode); | ||
rule = props.rule, | ||
textNode = props.textNode, | ||
match = props.match, | ||
schema = props.schema; | ||
var transformMatch = rule.transformMatch; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(match); // remove the text if transformMatch return | ||
if (transformedCapturedValue === '') { | ||
return; | ||
} | ||
var text = (_ref = transformedCapturedValue !== null && transformedCapturedValue !== void 0 ? transformedCapturedValue : textNode.text) !== null && _ref !== void 0 ? _ref : ''; | ||
nodes.push(schema.text(text, textNode.marks)); | ||
} | ||
@@ -450,5 +460,5 @@ /** | ||
function isInCode(selection) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$contained = _ref.contained, | ||
contained = _ref$contained === void 0 ? true : _ref$contained; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$contained = _ref2.contained, | ||
contained = _ref2$contained === void 0 ? true : _ref2$contained; | ||
@@ -455,0 +465,0 @@ if (selection.empty) { |
@@ -262,4 +262,3 @@ 'use strict'; | ||
ignoredMarks = rule.ignoredMarks, | ||
ignoredNodes = rule.ignoredNodes, | ||
transformMatch = rule.transformMatch; | ||
ignoredNodes = rule.ignoredNodes; | ||
fragment.forEach(child => { | ||
@@ -302,3 +301,2 @@ var _child$text; | ||
var capturedValue = _match2[1]; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2); | ||
var fullValue = _match2[0]; | ||
@@ -319,18 +317,15 @@ | ||
var textNode = child.cut(start, end); // When a transformed value was provided. | ||
var textNode = child.cut(start, end); // When a capture value is provided use it. | ||
if (coreHelpers.isString(transformedCapturedValue)) { | ||
textNode = schema.text(transformedCapturedValue, textNode.marks); | ||
} // When a capture value is provided use it. | ||
else if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
@@ -389,5 +384,7 @@ | ||
var getAttributes = rule.getAttributes, | ||
nodeType = rule.nodeType; | ||
nodeType = rule.nodeType, | ||
getContent = rule.getContent; | ||
var attributes = coreHelpers.isFunction(getAttributes) ? getAttributes(match, false) : getAttributes; | ||
nodes.push(nodeType.create(attributes, textNode)); | ||
var content = (getContent ? getContent(match) : textNode) || undefined; | ||
nodes.push(nodeType.createChecked(attributes, content)); | ||
} | ||
@@ -400,5 +397,18 @@ /** | ||
function textRuleTransformer(props) { | ||
var _ref; | ||
var nodes = props.nodes, | ||
textNode = props.textNode; | ||
nodes.push(textNode); | ||
rule = props.rule, | ||
textNode = props.textNode, | ||
match = props.match, | ||
schema = props.schema; | ||
var transformMatch = rule.transformMatch; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(match); // remove the text if transformMatch return | ||
if (transformedCapturedValue === '') { | ||
return; | ||
} | ||
var text = (_ref = transformedCapturedValue !== null && transformedCapturedValue !== void 0 ? transformedCapturedValue : textNode.text) !== null && _ref !== void 0 ? _ref : ''; | ||
nodes.push(schema.text(text, textNode.marks)); | ||
} | ||
@@ -450,5 +460,5 @@ /** | ||
function isInCode(selection) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$contained = _ref.contained, | ||
contained = _ref$contained === void 0 ? true : _ref$contained; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$contained = _ref2.contained, | ||
contained = _ref2$contained === void 0 ? true : _ref2$contained; | ||
@@ -455,0 +465,0 @@ if (selection.empty) { |
@@ -5,3 +5,3 @@ import _createForOfIteratorHelper from '@babel/runtime/helpers/esm/createForOfIteratorHelper'; | ||
import { ExtensionPriority } from '@remirror/core-constants'; | ||
import { sort, includes, findMatches, isFunction, isString, range } from '@remirror/core-helpers'; | ||
import { sort, includes, findMatches, isFunction, range } from '@remirror/core-helpers'; | ||
@@ -259,4 +259,3 @@ /** | ||
ignoredMarks = rule.ignoredMarks, | ||
ignoredNodes = rule.ignoredNodes, | ||
transformMatch = rule.transformMatch; | ||
ignoredNodes = rule.ignoredNodes; | ||
fragment.forEach(child => { | ||
@@ -299,3 +298,2 @@ var _child$text; | ||
var capturedValue = _match2[1]; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(_match2); | ||
var fullValue = _match2[0]; | ||
@@ -316,18 +314,15 @@ | ||
var textNode = child.cut(start, end); // When a transformed value was provided. | ||
var textNode = child.cut(start, end); // When a capture value is provided use it. | ||
if (isString(transformedCapturedValue)) { | ||
textNode = schema.text(transformedCapturedValue, textNode.marks); | ||
} // When a capture value is provided use it. | ||
else if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (fullValue && capturedValue) { | ||
var startSpaces = fullValue.search(/\S/); | ||
var textStart = start + fullValue.indexOf(capturedValue); | ||
var textEnd = textStart + capturedValue.length; | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
if (startSpaces) { | ||
nodes.push(child.cut(start, start + startSpaces)); | ||
} | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
textNode = child.cut(textStart, textEnd); | ||
} // A transformer to push the required nodes. | ||
@@ -386,5 +381,7 @@ | ||
var getAttributes = rule.getAttributes, | ||
nodeType = rule.nodeType; | ||
nodeType = rule.nodeType, | ||
getContent = rule.getContent; | ||
var attributes = isFunction(getAttributes) ? getAttributes(match, false) : getAttributes; | ||
nodes.push(nodeType.create(attributes, textNode)); | ||
var content = (getContent ? getContent(match) : textNode) || undefined; | ||
nodes.push(nodeType.createChecked(attributes, content)); | ||
} | ||
@@ -397,5 +394,18 @@ /** | ||
function textRuleTransformer(props) { | ||
var _ref; | ||
var nodes = props.nodes, | ||
textNode = props.textNode; | ||
nodes.push(textNode); | ||
rule = props.rule, | ||
textNode = props.textNode, | ||
match = props.match, | ||
schema = props.schema; | ||
var transformMatch = rule.transformMatch; | ||
var transformedCapturedValue = transformMatch === null || transformMatch === void 0 ? void 0 : transformMatch(match); // remove the text if transformMatch return | ||
if (transformedCapturedValue === '') { | ||
return; | ||
} | ||
var text = (_ref = transformedCapturedValue !== null && transformedCapturedValue !== void 0 ? transformedCapturedValue : textNode.text) !== null && _ref !== void 0 ? _ref : ''; | ||
nodes.push(schema.text(text, textNode.marks)); | ||
} | ||
@@ -447,5 +457,5 @@ /** | ||
function isInCode(selection) { | ||
var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref$contained = _ref.contained, | ||
contained = _ref$contained === void 0 ? true : _ref$contained; | ||
var _ref2 = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
_ref2$contained = _ref2.contained, | ||
contained = _ref2$contained === void 0 ? true : _ref2$contained; | ||
@@ -452,0 +462,0 @@ if (selection.empty) { |
{ | ||
"name": "prosemirror-paste-rules", | ||
"version": "0.0.0-pr959.1", | ||
"version": "0.0.0-pr960.1", | ||
"description": "Better handling of pasted content in your prosemirror editor.", | ||
@@ -35,4 +35,4 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/prosemirror-paste-rules", | ||
"@babel/runtime": "^7.13.10", | ||
"@remirror/core-constants": "0.0.0-pr959.1", | ||
"@remirror/core-helpers": "0.0.0-pr959.1", | ||
"@remirror/core-constants": "0.0.0-pr960.1", | ||
"@remirror/core-helpers": "0.0.0-pr960.1", | ||
"escape-string-regexp": "^4.0.0" | ||
@@ -39,0 +39,0 @@ }, |
98935
1.98%2391
1.92%+ Added
+ Added
+ Added
- Removed
- Removed
- Removed