@portabletext/editor
Advanced tools
Comparing version 1.33.0 to 1.33.1
@@ -36,2 +36,9 @@ import { c } from "react-compiler-runtime"; | ||
EditorRefPlugin.displayName = "EditorRefPlugin"; | ||
const asteriskPairRegex = "(?<!\\*)\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*(?!\\*)", underscorePairRegex = "(?<!_)_(?!\\s)([^_\\n]+?)(?<!\\s)_(?!_)", italicRegex = new RegExp(`(${asteriskPairRegex}|${underscorePairRegex})$`), doubleAsteriskPairRegex = "(?<!\\*)\\*\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*\\*(?!\\*)", doubleUnderscorePairRegex = "(?<!_)__(?!\\s)([^_\\n]+?)(?<!\\s)__(?!_)", boldRegex = new RegExp(`(${doubleAsteriskPairRegex}|${doubleUnderscorePairRegex})$`); | ||
function getTextToItalic(text) { | ||
return text.match(italicRegex)?.at(0); | ||
} | ||
function getTextToBold(text) { | ||
return text.match(boldRegex)?.at(0); | ||
} | ||
function useMarkdownEmphasisBehaviors(props) { | ||
@@ -56,3 +63,3 @@ const $ = c(10), editor = useEditor(); | ||
} | ||
const italicRegex = new RegExp("(?<!\\*)\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*(?!\\*)|(?<!_)_(?!\\s)([^_\\n]+?)(?<!\\s)_(?!_)$"), boldRegex = new RegExp("(?<!\\*)\\*\\*(?!\\s)([^*\\n]+?)(?<!\\s)\\*\\*(?!\\*)|(?<!_)__(?!\\s)([^_\\n]+?)(?<!\\s)__(?!_)$"), emphasisListener = ({ | ||
const emphasisListener = ({ | ||
sendBack, | ||
@@ -82,3 +89,3 @@ input | ||
context | ||
}), textToItalic = `${textBefore}${event.text}`.match(italicRegex)?.at(0); | ||
}), textToItalic = getTextToItalic(`${textBefore}${event.text}`); | ||
if (textToItalic !== void 0 && italicDecorator !== void 0) { | ||
@@ -120,3 +127,3 @@ const prefixOffsets = { | ||
} | ||
const textToBold = `${textBefore}${event.text}`.match(boldRegex)?.at(0); | ||
const textToBold = getTextToBold(`${textBefore}${event.text}`); | ||
if (textToBold !== void 0 && boldDecorator !== void 0) { | ||
@@ -123,0 +130,0 @@ const prefixOffsets = { |
{ | ||
"name": "@portabletext/editor", | ||
"version": "1.33.0", | ||
"version": "1.33.1", | ||
"description": "Portable Text Editor made in React", | ||
@@ -82,3 +82,3 @@ "keywords": [ | ||
"xstate": "^5.19.2", | ||
"@portabletext/block-tools": "1.1.6", | ||
"@portabletext/block-tools": "1.1.7", | ||
"@portabletext/patches": "1.1.3" | ||
@@ -90,4 +90,4 @@ }, | ||
"@sanity/pkg-utils": "^7.0.4", | ||
"@sanity/schema": "^3.74.1", | ||
"@sanity/types": "^3.74.1", | ||
"@sanity/schema": "^3.75.0", | ||
"@sanity/types": "^3.75.0", | ||
"@testing-library/jest-dom": "^6.6.3", | ||
@@ -120,4 +120,4 @@ "@testing-library/react": "^16.2.0", | ||
"peerDependencies": { | ||
"@sanity/schema": "^3.74.1", | ||
"@sanity/types": "^3.74.1", | ||
"@sanity/schema": "^3.75.0", | ||
"@sanity/types": "^3.75.0", | ||
"react": "^16.9 || ^17 || ^18 || ^19", | ||
@@ -124,0 +124,0 @@ "rxjs": "^7.8.1" |
@@ -12,2 +12,6 @@ import {useActorRef} from '@xstate/react' | ||
import {useEditor} from '../editor/editor-provider' | ||
import { | ||
getTextToBold, | ||
getTextToItalic, | ||
} from '../internal-utils/get-text-to-emphasize' | ||
import type {EditorSchema} from '../selectors' | ||
@@ -47,7 +51,2 @@ import * as selectors from '../selectors' | ||
const italicRegex = | ||
/(?<!\*)\*(?!\s)([^*\n]+?)(?<!\s)\*(?!\*)|(?<!_)_(?!\s)([^_\n]+?)(?<!\s)_(?!_)$/ | ||
const boldRegex = | ||
/(?<!\*)\*\*(?!\s)([^*\n]+?)(?<!\s)\*\*(?!\*)|(?<!_)__(?!\s)([^_\n]+?)(?<!\s)__(?!_)$/ | ||
type MarkdownEmphasisEvent = | ||
@@ -104,5 +103,3 @@ | { | ||
const textToItalic = `${textBefore}${event.text}` | ||
.match(italicRegex) | ||
?.at(0) | ||
const textToItalic = getTextToItalic(`${textBefore}${event.text}`) | ||
@@ -152,3 +149,3 @@ if (textToItalic !== undefined && italicDecorator !== undefined) { | ||
const textToBold = `${textBefore}${event.text}`.match(boldRegex)?.at(0) | ||
const textToBold = getTextToBold(`${textBefore}${event.text}`) | ||
@@ -155,0 +152,0 @@ if (textToBold !== undefined && boldDecorator !== undefined) { |
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
6110728
272
93840
+ Added@portabletext/block-tools@1.1.7(transitive)
- Removed@portabletext/block-tools@1.1.6(transitive)