prosemirror-paste-rules
Advanced tools
Comparing version 0.0.0-pr920.1 to 0.0.0-pr922.1
@@ -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 { |
@@ -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-pr920.1", | ||
"version": "0.0.0-pr922.1", | ||
"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-pr920.1", | ||
"@remirror/core-helpers": "0.0.0-pr920.1", | ||
"escape-string-regexp": "^4.0.0", | ||
"type-fest": "^0.21.3" | ||
"@remirror/core-constants": "0.0.0-pr922.1", | ||
"@remirror/core-helpers": "0.0.0-pr922.1", | ||
"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": { |
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
97016
10
2346
+ Added@remirror/core-constants@0.0.0-pr922.1(transitive)
+ Added@remirror/core-helpers@0.0.0-pr922.1(transitive)
+ Added@remirror/types@0.0.0-pr922.1(transitive)
+ Addedtype-fest@1.4.0(transitive)
- Removedtype-fest@^0.21.3
- Removed@remirror/core-constants@0.0.0-pr920.1(transitive)
- Removed@remirror/core-helpers@0.0.0-pr920.1(transitive)
- Removedtype-fest@0.21.3(transitive)