@portabletext/editor 2.12.2 → 2.12.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
1
  import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.cjs";
2
- import * as react22 from "react";
2
+ import * as react12 from "react";
3
3
  import React from "react";
4
4
  /**
5
5
  * @beta
@@ -181,7 +181,7 @@ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
181
181
  */
182
182
  declare function MarkdownPlugin(props: {
183
183
  config: MarkdownPluginConfig;
184
- }): react22.JSX.Element;
184
+ }): react12.JSX.Element;
185
185
  /**
186
186
  * @beta
187
187
  * Restrict the editor to one line. The plugin takes care of blocking
@@ -192,5 +192,5 @@ declare function MarkdownPlugin(props: {
192
192
  *
193
193
  * @deprecated Install the plugin from `@portabletext/plugin-one-line`
194
194
  */
195
- declare function OneLinePlugin(): react22.JSX.Element;
195
+ declare function OneLinePlugin(): react12.JSX.Element;
196
196
  export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
@@ -1,5 +1,5 @@
1
1
  import { Behavior, Editor, EditorEmittedEvent, EditorSchema } from "../_chunks-dts/behavior.types.action.js";
2
- import * as react12 from "react";
2
+ import * as react22 from "react";
3
3
  import React from "react";
4
4
  /**
5
5
  * @beta
@@ -181,7 +181,7 @@ type MarkdownPluginConfig = MarkdownBehaviorsConfig & {
181
181
  */
182
182
  declare function MarkdownPlugin(props: {
183
183
  config: MarkdownPluginConfig;
184
- }): react12.JSX.Element;
184
+ }): react22.JSX.Element;
185
185
  /**
186
186
  * @beta
187
187
  * Restrict the editor to one line. The plugin takes care of blocking
@@ -192,5 +192,5 @@ declare function MarkdownPlugin(props: {
192
192
  *
193
193
  * @deprecated Install the plugin from `@portabletext/plugin-one-line`
194
194
  */
195
- declare function OneLinePlugin(): react12.JSX.Element;
195
+ declare function OneLinePlugin(): react22.JSX.Element;
196
196
  export { BehaviorPlugin, DecoratorShortcutPlugin, EditorRefPlugin, EventListenerPlugin, MarkdownPlugin, type MarkdownPluginConfig, OneLinePlugin };
@@ -1,5 +1,5 @@
1
1
  import { BlockOffset, BlockPath, ChildPath, EditorContext, EditorSelection, EditorSelectionPoint } from "../_chunks-dts/behavior.types.action.js";
2
- import * as _sanity_types8 from "@sanity/types";
2
+ import * as _sanity_types9 from "@sanity/types";
3
3
  import { KeyedSegment, PortableTextBlock, PortableTextTextBlock } from "@sanity/types";
4
4
  import { isSpan, isTextBlock } from "@portabletext/schema";
5
5
  /**
@@ -143,7 +143,7 @@ declare function mergeTextBlocks({
143
143
  context: Pick<EditorContext, 'keyGenerator' | 'schema'>;
144
144
  targetBlock: PortableTextTextBlock;
145
145
  incomingBlock: PortableTextTextBlock;
146
- }): PortableTextTextBlock<_sanity_types8.PortableTextObject | _sanity_types8.PortableTextSpan>;
146
+ }): PortableTextTextBlock<_sanity_types9.PortableTextObject | _sanity_types9.PortableTextSpan>;
147
147
  /**
148
148
  * @public
149
149
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "2.12.2",
3
+ "version": "2.12.3",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -85,10 +85,10 @@
85
85
  "slate-dom": "^0.118.1",
86
86
  "slate-react": "0.117.4",
87
87
  "xstate": "^5.22.0",
88
- "@portabletext/block-tools": "^3.5.6",
88
+ "@portabletext/schema": "^1.2.0",
89
+ "@portabletext/block-tools": "^3.5.7",
89
90
  "@portabletext/keyboard-shortcuts": "^1.1.1",
90
- "@portabletext/patches": "^1.1.8",
91
- "@portabletext/schema": "^1.2.0"
91
+ "@portabletext/patches": "^1.1.8"
92
92
  },
93
93
  "devDependencies": {
94
94
  "@sanity/diff-match-patch": "^3.2.0",
@@ -116,12 +116,12 @@
116
116
  "vite": "^7.1.3",
117
117
  "vitest": "^3.2.4",
118
118
  "vitest-browser-react": "^1.0.1",
119
- "@portabletext/sanity-bridge": "1.1.10",
119
+ "@portabletext/sanity-bridge": "1.1.11",
120
120
  "@portabletext/test": "^0.0.0",
121
121
  "racejar": "1.3.0"
122
122
  },
123
123
  "peerDependencies": {
124
- "@portabletext/sanity-bridge": "^1.1.10",
124
+ "@portabletext/sanity-bridge": "^1.1.11",
125
125
  "@sanity/schema": "^4.9.0",
126
126
  "@sanity/types": "^4.9.0",
127
127
  "react": "^18.3 || ^19",
@@ -942,28 +942,8 @@ export const PortableTextEditable = forwardRef<
942
942
  } else if (forwardedRef) {
943
943
  forwardedRef.current = node
944
944
  }
945
-
946
- if (node) {
947
- // Observe mutations (child list and subtree) to this component's DOM,
948
- // and make sure the editor selection is valid when that happens.
949
- const mutationObserver = new MutationObserver(() => {
950
- validateSelection(slateEditor, node)
951
- })
952
-
953
- mutationObserver.observe(node, {
954
- attributeOldValue: false,
955
- attributes: false,
956
- characterData: false,
957
- childList: true,
958
- subtree: true,
959
- })
960
-
961
- return () => {
962
- mutationObserver.disconnect()
963
- }
964
- }
965
945
  },
966
- [forwardedRef, slateEditor],
946
+ [forwardedRef],
967
947
  )
968
948
 
969
949
  if (!portableTextEditor) {
@@ -1007,72 +987,3 @@ export const PortableTextEditable = forwardRef<
1007
987
  })
1008
988
 
1009
989
  PortableTextEditable.displayName = 'ForwardRef(PortableTextEditable)'
1010
-
1011
- // This function will handle unexpected DOM changes inside the Editable rendering,
1012
- // and make sure that we can maintain a stable slateEditor.selection when that happens.
1013
- //
1014
- // For example, if this Editable is rendered inside something that might re-render
1015
- // this component (hidden contexts) while the user is still actively changing the
1016
- // contentEditable, this could interfere with the intermediate DOM selection,
1017
- // which again could be picked up by ReactEditor's event listeners.
1018
- // If that range is invalid at that point, the slate.editorSelection could be
1019
- // set either wrong, or invalid, to which slateEditor will throw exceptions
1020
- // that are impossible to recover properly from or result in a wrong selection.
1021
- //
1022
- // Also the other way around, when the ReactEditor will try to create a DOM Range
1023
- // from the current slateEditor.selection, it may throw unrecoverable errors
1024
- // if the current editor.selection is invalid according to the DOM.
1025
- // If this is the case, default to selecting the top of the document, if the
1026
- // user already had a selection.
1027
- function validateSelection(slateEditor: Editor, activeElement: HTMLDivElement) {
1028
- if (!slateEditor.selection) {
1029
- return
1030
- }
1031
-
1032
- let root: Document | ShadowRoot | undefined
1033
-
1034
- try {
1035
- root = ReactEditor.findDocumentOrShadowRoot(slateEditor)
1036
- } catch {}
1037
-
1038
- if (!root) {
1039
- // The editor has most likely been unmounted
1040
- return
1041
- }
1042
-
1043
- // Return if the editor isn't the active element
1044
- if (activeElement !== root.activeElement) {
1045
- return
1046
- }
1047
- const window = ReactEditor.getWindow(slateEditor)
1048
- const domSelection = window.getSelection()
1049
- if (!domSelection || domSelection.rangeCount === 0) {
1050
- return
1051
- }
1052
- const existingDOMRange = domSelection.getRangeAt(0)
1053
- try {
1054
- const newDOMRange = ReactEditor.toDOMRange(
1055
- slateEditor,
1056
- slateEditor.selection,
1057
- )
1058
- if (
1059
- newDOMRange.startOffset !== existingDOMRange.startOffset ||
1060
- newDOMRange.endOffset !== existingDOMRange.endOffset
1061
- ) {
1062
- debug('DOM range out of sync, validating selection')
1063
- // Remove all ranges temporary
1064
- domSelection?.removeAllRanges()
1065
- // Set the correct range
1066
- domSelection.addRange(newDOMRange)
1067
- }
1068
- } catch {
1069
- debug(`Could not resolve selection, selecting top document`)
1070
- // Deselect the editor
1071
- Transforms.deselect(slateEditor)
1072
- // Select top document if there is a top block to select
1073
- if (slateEditor.children.length > 0) {
1074
- Transforms.select(slateEditor, [0, 0])
1075
- }
1076
- slateEditor.onChange()
1077
- }
1078
- }
@@ -61,14 +61,7 @@ export const stepDefinitions = [
61
61
  }),
62
62
 
63
63
  Given('the editor is focused', async (context: Context) => {
64
- context.editor.send({
65
- type: 'focus',
66
- })
67
-
68
- await vi.waitFor(() => {
69
- const selection = context.editor.getSnapshot().context.selection
70
- expect(selection).not.toBeNull()
71
- })
64
+ await userEvent.click(context.locator)
72
65
  }),
73
66
 
74
67
  Given(