@udecode/slate
Advanced tools
Comparing version 21.0.0 to 21.3.0
@@ -1251,5 +1251,94 @@ import { createEditor, Editor, Element, Range, Text, Transforms, Path, Point, Node } from 'slate'; | ||
/** | ||
* Add marks to each node of a range. | ||
*/ | ||
const addRangeMarks = (editor, props, { | ||
at = editor.selection | ||
} = {}) => { | ||
if (at) { | ||
if (Path.isPath(at)) { | ||
at = getRange(editor, at); | ||
} | ||
const match = (node, path) => { | ||
if (!Text.isText(node)) { | ||
return false; // marks can only be applied to text | ||
} | ||
const parentEntry = Editor.parent(editor, path); | ||
if (!parentEntry) return false; | ||
const [parentNode] = parentEntry; | ||
return !editor.isVoid(parentNode) || editor.markableVoid(parentNode); | ||
}; | ||
const isExpandedRange = Range.isExpanded(at); | ||
let markAcceptingVoidSelected = false; | ||
if (!isExpandedRange) { | ||
const selectedEntry = Editor.node(editor, at); | ||
if (!selectedEntry) return; | ||
const [selectedNode, selectedPath] = selectedEntry; | ||
if (selectedNode && match(selectedNode, selectedPath)) { | ||
const parentEntry = Editor.parent(editor, selectedPath); | ||
if (!parentEntry) return; | ||
const [parentNode] = parentEntry; | ||
markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode); | ||
} | ||
} | ||
if (isExpandedRange || markAcceptingVoidSelected) { | ||
Transforms.setNodes(editor, props, { | ||
match, | ||
split: true, | ||
voids: true, | ||
at | ||
}); | ||
} // else { | ||
// const marks = { | ||
// ...(Editor.marks(editor as any) || {}), | ||
// [key]: value, | ||
// }; | ||
// | ||
// editor.marks = marks; | ||
// if (!FLUSHING.get(editor as any)) { | ||
// editor.onChange(); | ||
// } | ||
// } | ||
} | ||
}; | ||
const setElements = (editor, props, options) => setNodes(editor, props, options); | ||
export { addMark, collapseSelection, createPathRef, createPointRef, createRangeRef, createTEditor, deleteBackward, deleteForward, deleteFragment, deleteMerge, deleteText, deselect, elementMatches, findNode, getAboveNode, getCommonNode, getEdgePoints, getEditorString, getEndPoint, getFirstNode, getFragment, getLastNode, getLeafNode, getLevels, getMarks, getNextNode, getNode, getNodeAncestor, getNodeAncestors, getNodeChild, getNodeChildren, getNodeDescendant, getNodeDescendants, getNodeElements, getNodeEntries, getNodeEntry, getNodeFirstNode, getNodeFragment, getNodeLastNode, getNodeLeaf, getNodeLevels, getNodeParent, getNodeProps, getNodeString, getNodeTexts, getNodes, getParentNode, getPath, getPathRefs, getPoint, getPointAfter, getPointBefore, getPointRefs, getPositions, getPreviousNode, getQueryOptions, getRange, getRangeRefs, getStartPoint, getTEditor, getVoidNode, hasBlocks, hasInlines, hasNode, hasSingleChild, hasTexts, insertBreak, insertFragment, insertNode, insertNodes, insertText, isAncestor, isBlock, isCollapsed, isDescendant, isEdgePoint, isEditor, isEditorNormalizing, isElement, isElementEmpty, isElementList, isEndPoint, isExpanded, isHistoryEditor, isHistoryMerging, isHistorySaving, isInline, isNode, isNodeList, isStartPoint, isText, isTextList, isVoid, liftNodes, match, mergeNodes, moveNodes, moveSelection, nodeMatches, normalizeEditor, queryNode, removeEditorMark, removeNodes, select, setElements, setNodes, setPoint, setSelection, someNode, splitNodes, textEquals, textMatches, unhangRange, unsetNodes, unwrapNodes, withoutMergingHistory, withoutNormalizing, withoutSavingHistory, wrapNodes }; | ||
/** | ||
* Unhang the range of length 1 so both edges are in the same text node. | ||
*/ | ||
const unhangCharacterRange = (editor, at) => { | ||
let [start, end] = Range.edges(at); | ||
if (!Path.equals(start.path, end.path)) { | ||
if (end.offset === 0) { | ||
const pointAfter = getPointAfter(editor, start); | ||
if (pointAfter) { | ||
end = pointAfter; | ||
} | ||
} else { | ||
const pointBefore = getPointBefore(editor, end); | ||
if (pointBefore) { | ||
start = pointBefore; | ||
} | ||
} | ||
} | ||
return { | ||
anchor: start, | ||
focus: end | ||
}; | ||
}; | ||
export { addMark, addRangeMarks, collapseSelection, createPathRef, createPointRef, createRangeRef, createTEditor, deleteBackward, deleteForward, deleteFragment, deleteMerge, deleteText, deselect, elementMatches, findNode, getAboveNode, getCommonNode, getEdgePoints, getEditorString, getEndPoint, getFirstNode, getFragment, getLastNode, getLeafNode, getLevels, getMarks, getNextNode, getNode, getNodeAncestor, getNodeAncestors, getNodeChild, getNodeChildren, getNodeDescendant, getNodeDescendants, getNodeElements, getNodeEntries, getNodeEntry, getNodeFirstNode, getNodeFragment, getNodeLastNode, getNodeLeaf, getNodeLevels, getNodeParent, getNodeProps, getNodeString, getNodeTexts, getNodes, getParentNode, getPath, getPathRefs, getPoint, getPointAfter, getPointBefore, getPointRefs, getPositions, getPreviousNode, getQueryOptions, getRange, getRangeRefs, getStartPoint, getTEditor, getVoidNode, hasBlocks, hasInlines, hasNode, hasSingleChild, hasTexts, insertBreak, insertFragment, insertNode, insertNodes, insertText, isAncestor, isBlock, isCollapsed, isDescendant, isEdgePoint, isEditor, isEditorNormalizing, isElement, isElementEmpty, isElementList, isEndPoint, isExpanded, isHistoryEditor, isHistoryMerging, isHistorySaving, isInline, isNode, isNodeList, isStartPoint, isText, isTextList, isVoid, liftNodes, match, mergeNodes, moveNodes, moveSelection, nodeMatches, normalizeEditor, queryNode, removeEditorMark, removeNodes, select, setElements, setNodes, setPoint, setSelection, someNode, splitNodes, textEquals, textMatches, unhangCharacterRange, unhangRange, unsetNodes, unwrapNodes, withoutMergingHistory, withoutNormalizing, withoutSavingHistory, wrapNodes }; | ||
//# sourceMappingURL=index.es.js.map |
@@ -1255,5 +1255,95 @@ 'use strict'; | ||
/** | ||
* Add marks to each node of a range. | ||
*/ | ||
const addRangeMarks = (editor, props, { | ||
at = editor.selection | ||
} = {}) => { | ||
if (at) { | ||
if (slate.Path.isPath(at)) { | ||
at = getRange(editor, at); | ||
} | ||
const match = (node, path) => { | ||
if (!slate.Text.isText(node)) { | ||
return false; // marks can only be applied to text | ||
} | ||
const parentEntry = slate.Editor.parent(editor, path); | ||
if (!parentEntry) return false; | ||
const [parentNode] = parentEntry; | ||
return !editor.isVoid(parentNode) || editor.markableVoid(parentNode); | ||
}; | ||
const isExpandedRange = slate.Range.isExpanded(at); | ||
let markAcceptingVoidSelected = false; | ||
if (!isExpandedRange) { | ||
const selectedEntry = slate.Editor.node(editor, at); | ||
if (!selectedEntry) return; | ||
const [selectedNode, selectedPath] = selectedEntry; | ||
if (selectedNode && match(selectedNode, selectedPath)) { | ||
const parentEntry = slate.Editor.parent(editor, selectedPath); | ||
if (!parentEntry) return; | ||
const [parentNode] = parentEntry; | ||
markAcceptingVoidSelected = parentNode && editor.markableVoid(parentNode); | ||
} | ||
} | ||
if (isExpandedRange || markAcceptingVoidSelected) { | ||
slate.Transforms.setNodes(editor, props, { | ||
match, | ||
split: true, | ||
voids: true, | ||
at | ||
}); | ||
} // else { | ||
// const marks = { | ||
// ...(Editor.marks(editor as any) || {}), | ||
// [key]: value, | ||
// }; | ||
// | ||
// editor.marks = marks; | ||
// if (!FLUSHING.get(editor as any)) { | ||
// editor.onChange(); | ||
// } | ||
// } | ||
} | ||
}; | ||
const setElements = (editor, props, options) => setNodes(editor, props, options); | ||
/** | ||
* Unhang the range of length 1 so both edges are in the same text node. | ||
*/ | ||
const unhangCharacterRange = (editor, at) => { | ||
let [start, end] = slate.Range.edges(at); | ||
if (!slate.Path.equals(start.path, end.path)) { | ||
if (end.offset === 0) { | ||
const pointAfter = getPointAfter(editor, start); | ||
if (pointAfter) { | ||
end = pointAfter; | ||
} | ||
} else { | ||
const pointBefore = getPointBefore(editor, end); | ||
if (pointBefore) { | ||
start = pointBefore; | ||
} | ||
} | ||
} | ||
return { | ||
anchor: start, | ||
focus: end | ||
}; | ||
}; | ||
exports.addMark = addMark; | ||
exports.addRangeMarks = addRangeMarks; | ||
exports.collapseSelection = collapseSelection; | ||
@@ -1370,2 +1460,3 @@ exports.createPathRef = createPathRef; | ||
exports.textMatches = textMatches; | ||
exports.unhangCharacterRange = unhangCharacterRange; | ||
exports.unhangRange = unhangRange; | ||
@@ -1372,0 +1463,0 @@ exports.unsetNodes = unsetNodes; |
/** | ||
* @file Automatically generated by barrelsby. | ||
*/ | ||
export * from './addRangeMarks'; | ||
export * from './setElements'; | ||
export * from './unhangCharacterRange'; | ||
//# sourceMappingURL=index.d.ts.map |
{ | ||
"name": "@udecode/slate", | ||
"version": "21.0.0", | ||
"version": "21.3.0", | ||
"description": "Slate extension", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
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
423478
296
3840