New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@portabletext/editor

Package Overview
Dependencies
Maintainers
9
Versions
127
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@portabletext/editor - npm Package Compare versions

Comparing version 1.0.10 to 1.0.11

src/editor/__tests__/insert-block.test.tsx

14

package.json
{
"name": "@portabletext/editor",
"version": "1.0.10",
"version": "1.0.11",
"description": "Portable Text Editor made in React",

@@ -56,12 +56,12 @@ "keywords": [

"@portabletext/toolkit": "^2.0.15",
"@sanity/block-tools": "^3.52.2",
"@sanity/block-tools": "^3.52.4",
"@sanity/diff-match-patch": "^3.1.1",
"@sanity/eslint-config-i18n": "^1.1.0",
"@sanity/eslint-config-studio": "^4.0.0",
"@sanity/pkg-utils": "^6.10.6",
"@sanity/schema": "^3.52.2",
"@sanity/pkg-utils": "^6.10.8",
"@sanity/schema": "^3.52.4",
"@sanity/test": "0.0.1-alpha.1",
"@sanity/types": "^3.52.2",
"@sanity/types": "^3.52.4",
"@sanity/ui": "^2.8.8",
"@sanity/util": "^3.52.2",
"@sanity/util": "^3.52.4",
"@testing-library/react": "^13.4.0",

@@ -103,3 +103,3 @@ "@types/debug": "^4.1.5",

"tsx": "^4.16.2",
"typescript": "^5.5.3",
"typescript": "5.5.4",
"vite": "^4.5.3"

@@ -106,0 +106,0 @@ },

@@ -163,5 +163,2 @@ import {

insertBlock: (type: SchemaType, value?: {[prop: string]: any}): Path => {
if (!editor.selection) {
throw new Error('The editor has no selection')
}
const block = toSlateValue(

@@ -177,3 +174,34 @@ [

)[0] as unknown as Node
const [focusBlock] = Array.from(
if (!editor.selection) {
const lastBlock = Array.from(
Editor.nodes(editor, {
match: (n) => !Editor.isEditor(n),
at: [],
reverse: true,
}),
)[0]
// If there is no selection, let's just insert the new block at the
// end of the document
Editor.insertNode(editor, block)
if (lastBlock && isEqualToEmptyEditor([lastBlock[0]], types)) {
// And if the last block was an empty text block, let's remove
// that too
Transforms.removeNodes(editor, {at: lastBlock[1]})
}
editor.onChange()
return (
toPortableTextRange(
fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)),
editor.selection,
types,
)?.focus.path ?? []
)
}
const focusBlock = Array.from(
Editor.nodes(editor, {

@@ -183,13 +211,12 @@ at: editor.selection.focus.path.slice(0, 1),

}),
)[0] || [undefined]
)[0]
const isEmptyTextBlock = focusBlock && isEqualToEmptyEditor([focusBlock], types)
Editor.insertNode(editor, block)
if (isEmptyTextBlock) {
// If the text block is empty, remove it before inserting the new block.
Transforms.removeNodes(editor, {at: editor.selection})
if (focusBlock && isEqualToEmptyEditor([focusBlock[0]], types)) {
Transforms.removeNodes(editor, {at: focusBlock[1]})
}
Editor.insertNode(editor, block)
editor.onChange()
return (

@@ -314,2 +341,6 @@ toPortableTextRange(

if (spans.length === 0) {
return false
}
if (

@@ -316,0 +347,0 @@ spans.some(

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

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

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