prosemirror-paste-rules
Advanced tools
Comparing version 2.0.7 to 2.0.8
@@ -175,2 +175,2 @@ import { MarkType, NodeType, Fragment, Node } from 'prosemirror-model'; | ||
export { FileDropHandlerProps, FileHandlerProps, FilePasteHandlerProps, FilePasteRule, IsInCodeOptions, MarkPasteRule, NodePasteRule, PasteRule, TextPasteRule, isInCode, pasteRules }; | ||
export { type FileDropHandlerProps, type FileHandlerProps, type FilePasteHandlerProps, type FilePasteRule, type IsInCodeOptions, type MarkPasteRule, type NodePasteRule, type PasteRule, type TextPasteRule, isInCode, pasteRules }; |
@@ -33,3 +33,2 @@ // packages/prosemirror-paste-rules/src/paste-rules-plugin.ts | ||
transformPasted: (slice) => { | ||
var _a, _b, _c; | ||
const $pos = view.state.selection.$from; | ||
@@ -41,8 +40,8 @@ const nodeName = $pos.node().type.name; | ||
// The parent node is ignored. | ||
((_a = rule.ignoredNodes) == null ? void 0 : _a.includes(nodeName)) || // The current position contains ignored marks. | ||
((_b = rule.ignoredMarks) == null ? void 0 : _b.some((ignored) => markNames.has(ignored))) | ||
rule.ignoredNodes?.includes(nodeName) || // The current position contains ignored marks. | ||
rule.ignoredMarks?.some((ignored) => markNames.has(ignored)) | ||
) { | ||
continue; | ||
} | ||
const textContent = ((_c = slice.content.firstChild) == null ? void 0 : _c.textContent) ?? ""; | ||
const textContent = slice.content.firstChild?.textContent ?? ""; | ||
const canBeReplaced = !view.state.selection.empty && slice.content.childCount === 1 && textContent; | ||
@@ -82,5 +81,4 @@ const match = findMatches(textContent, rule.regexp)[0]; | ||
paste: (view2, clipboardEvent) => { | ||
var _a, _b; | ||
const event = clipboardEvent; | ||
if (!((_b = (_a = view2.props).editable) == null ? void 0 : _b.call(_a, view2.state))) { | ||
if (!view2.props.editable?.(view2.state)) { | ||
return false; | ||
@@ -111,5 +109,4 @@ } | ||
drop: (view2, dragEvent) => { | ||
var _a, _b, _c; | ||
const event = dragEvent; | ||
if (!((_b = (_a = view2.props).editable) == null ? void 0 : _b.call(_a, view2.state))) { | ||
if (!view2.props.editable?.(view2.state)) { | ||
return false; | ||
@@ -125,3 +122,3 @@ } | ||
} | ||
const pos = ((_c = view2.posAtCoords({ left: clientX, top: clientY })) == null ? void 0 : _c.pos) ?? view2.state.selection.anchor; | ||
const pos = view2.posAtCoords({ left: clientX, top: clientY })?.pos ?? view2.state.selection.anchor; | ||
for (const { fileHandler, regexp } of filePasteRules) { | ||
@@ -150,3 +147,3 @@ const files = regexp ? allFiles.filter((file) => regexp.test(file.type)) : allFiles; | ||
fragment.forEach((child) => { | ||
if ((ignoredNodes == null ? void 0 : ignoredNodes.includes(child.type.name)) || isCodeNode(child)) { | ||
if (ignoredNodes?.includes(child.type.name) || isCodeNode(child)) { | ||
nodes.push(child); | ||
@@ -157,3 +154,3 @@ return; | ||
const childResult = handler({ fragment: child.content, rule, nodes: [] }); | ||
transformed || (transformed = childResult.transformed); | ||
transformed ||= childResult.transformed; | ||
const content = Fragment.fromArray(childResult.nodes); | ||
@@ -167,3 +164,3 @@ if (child.type.validContent(content)) { | ||
} | ||
if (child.marks.some((mark) => isCodeMark(mark) || (ignoredMarks == null ? void 0 : ignoredMarks.includes(mark.type.name)))) { | ||
if (child.marks.some((mark) => isCodeMark(mark) || ignoredMarks?.includes(mark.type.name))) { | ||
nodes.push(child); | ||
@@ -180,3 +177,3 @@ return; | ||
// an update. | ||
ignoreWhitespace && (capturedValue == null ? void 0 : capturedValue.trim()) === "" || !fullValue | ||
ignoreWhitespace && capturedValue?.trim() === "" || !fullValue | ||
) { | ||
@@ -217,3 +214,3 @@ return; | ||
const mark = markType.create(attributes); | ||
const transformedCapturedValue = transformMatch == null ? void 0 : transformMatch(match); | ||
const transformedCapturedValue = transformMatch?.(match); | ||
if (transformedCapturedValue === "") { | ||
@@ -232,3 +229,3 @@ return; | ||
const { transformMatch } = rule; | ||
const transformedCapturedValue = transformMatch == null ? void 0 : transformMatch(match); | ||
const transformedCapturedValue = transformMatch?.(match); | ||
if (transformedCapturedValue === "" || transformedCapturedValue === false) { | ||
@@ -285,11 +282,8 @@ return; | ||
function isCodeNode(node) { | ||
var _a; | ||
return node.type.spec.code || ((_a = node.type.spec.group) == null ? void 0 : _a.split(" ").includes("code")); | ||
return node.type.spec.code || node.type.spec.group?.split(" ").includes("code"); | ||
} | ||
function isCodeMark(mark) { | ||
var _a; | ||
return mark.type.name === "code" || ((_a = mark.type.spec.group) == null ? void 0 : _a.split(" ").includes("code")); | ||
return mark.type.name === "code" || mark.type.spec.group?.split(" ").includes("code"); | ||
} | ||
function getDataTransferFiles(event) { | ||
var _a, _b; | ||
const { dataTransfer } = event; | ||
@@ -299,6 +293,6 @@ if (!dataTransfer) { | ||
} | ||
if (((_a = dataTransfer.files) == null ? void 0 : _a.length) > 0) { | ||
if (dataTransfer.files?.length > 0) { | ||
return [...dataTransfer.files]; | ||
} | ||
if ((_b = dataTransfer.items) == null ? void 0 : _b.length) { | ||
if (dataTransfer.items?.length) { | ||
return [...dataTransfer.items].map((item) => item.getAsFile()).filter((item) => !!item); | ||
@@ -305,0 +299,0 @@ } |
{ | ||
"name": "prosemirror-paste-rules", | ||
"version": "2.0.7", | ||
"version": "2.0.8", | ||
"description": "Better handling of pasted content in your prosemirror editor.", | ||
@@ -39,10 +39,10 @@ "homepage": "https://github.com/remirror/remirror/tree/HEAD/packages/prosemirror-paste-rules", | ||
"devDependencies": { | ||
"prosemirror-model": "^1.19.3", | ||
"prosemirror-model": "^1.22.1", | ||
"prosemirror-state": "^1.4.3", | ||
"prosemirror-view": "^1.31.7" | ||
"prosemirror-view": "^1.33.8" | ||
}, | ||
"peerDependencies": { | ||
"prosemirror-model": "^1.19.0", | ||
"prosemirror-model": "^1.22.1", | ||
"prosemirror-state": "^1.4.2", | ||
"prosemirror-view": "^1.31.2" | ||
"prosemirror-view": "^1.33.8" | ||
}, | ||
@@ -49,0 +49,0 @@ "peerDependenciesMeta": {}, |
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
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
93693
11
1283