sanity 6.6.0-next.96 → 6.6.0-next.99

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.
@@ -201,6 +201,7 @@ import getSlug from "speakingurl";
201
201
  import { defineBehavior, raise, forward } from "@portabletext/editor/behaviors";
202
202
  import { NodePlugin, BehaviorPlugin, EventListenerPlugin } from "@portabletext/editor/plugins";
203
203
  import { OneLinePlugin } from "@portabletext/plugin-one-line";
204
+ import { getEnclosingBlock, getSpan } from "@portabletext/editor/traversal";
204
205
  import { ResetIcon } from "@sanity/icons/Reset";
205
206
  import { HelpCircleIcon } from "@sanity/icons/HelpCircle";
206
207
  import { PortableText as PortableText$1, toPlainText as toPlainText$1 } from "@portabletext/react";
@@ -281,7 +282,6 @@ import { ItalicIcon } from "@sanity/icons/Italic";
281
282
  import { OlistIcon } from "@sanity/icons/Olist";
282
283
  import { StrikethroughIcon } from "@sanity/icons/Strikethrough";
283
284
  import { UnderlineIcon } from "@sanity/icons/Underline";
284
- import { getEnclosingBlock, getSpan } from "@portabletext/editor/traversal";
285
285
  import set$2 from "lodash-es/set.js";
286
286
  import { htmlToPortableText } from "@portabletext/html";
287
287
  import { MarkdownShortcutsPlugin } from "@portabletext/plugin-markdown-shortcuts";
@@ -32737,10 +32737,16 @@ function _getValueAtPath(value, path) {
32737
32737
  function keyGenerator() {
32738
32738
  return randomKey$1(12);
32739
32739
  }
32740
+ const LegacyEditorRefPlugin = forwardRef((_, ref) => {
32741
+ const $ = c(3), portableTextEditor = usePortableTextEditor();
32742
+ let t0, t1;
32743
+ return $[0] !== portableTextEditor ? (t0 = () => portableTextEditor, t1 = [portableTextEditor], $[0] = portableTextEditor, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useImperativeHandle(ref, t0, t1), null;
32744
+ });
32745
+ LegacyEditorRefPlugin.displayName = "LegacyEditorRefPlugin";
32740
32746
  const EditorRefPlugin$1 = forwardRef((_, ref) => {
32741
- const $ = c(2), portableTextEditor = usePortableTextEditor(), portableTextEditorRef = useRef(portableTextEditor);
32747
+ const $ = c(3), editor2 = useEditor();
32742
32748
  let t0, t1;
32743
- return $[0] === /* @__PURE__ */ Symbol.for("react.memo_cache_sentinel") ? (t0 = () => portableTextEditorRef.current, t1 = [], $[0] = t0, $[1] = t1) : (t0 = $[0], t1 = $[1]), useImperativeHandle(ref, t0, t1), null;
32749
+ return $[0] !== editor2 ? (t0 = () => editor2, t1 = [editor2], $[0] = editor2, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useImperativeHandle(ref, t0, t1), null;
32744
32750
  });
32745
32751
  EditorRefPlugin$1.displayName = "EditorRefPlugin";
32746
32752
  function PortableTextInput(props2) {
@@ -32770,7 +32776,7 @@ function PortableTextInput(props2) {
32770
32776
  } = props2, {
32771
32777
  onBlur,
32772
32778
  ref: elementRef
32773
- } = elementProps, defaultEditorRef = useRef(null), editorRef = editorRefProp || defaultEditorRef, presenceCursorDecorations = usePresenceCursorDecorations(useMemo(() => ({
32779
+ } = elementProps, defaultLegacyEditorRef = useRef(null), editorRef = useRef(null), legacyEditorRef = editorRefProp || defaultLegacyEditorRef, presenceCursorDecorations = usePresenceCursorDecorations(useMemo(() => ({
32774
32780
  path: props2.path
32775
32781
  }), [props2.path])), {
32776
32782
  selectedPerspective
@@ -32819,19 +32825,16 @@ function PortableTextInput(props2) {
32819
32825
  useEffect(() => {
32820
32826
  hasFocusWithin && setIsActive(!0);
32821
32827
  }, [hasFocusWithin]);
32822
- const setFocusPathFromEditorSelection = useCallback((nextSelection) => {
32828
+ const setFocusPathFromEditorSelection = useCallback((nextSelection, snapshot2) => {
32823
32829
  const focusPath = nextSelection?.focus.path;
32824
32830
  if (!focusPath) return;
32825
- const nextFocusPath = focusPath.length === 3 && // A span path is always 3 segments long
32826
- focusPath[1] === "children" && // Is a child of a block
32827
- isKeySegment(focusPath[2]) && // Contains the key of the child
32828
- !portableTextMemberItems.some((item) => isKeySegment(focusPath[2]) && item.member.key === focusPath[2]._key) ? focusPath.concat(["text"]) : focusPath;
32831
+ const nextFocusPath = snapshot2 && getSpan(snapshot2, focusPath) ? focusPath.concat(["text"]) : focusPath;
32829
32832
  startTransition(() => {
32830
32833
  onPathFocus(nextFocusPath, {
32831
32834
  selection: nextSelection
32832
32835
  });
32833
32836
  });
32834
- }, [onPathFocus, portableTextMemberItems]), handleEditorChange = useCallback(
32837
+ }, [onPathFocus]), handleEditorChange = useCallback(
32835
32838
  // oxlint-disable-next-line react/react-compiler
32836
32839
  (change) => {
32837
32840
  switch (change.type) {
@@ -32839,7 +32842,7 @@ function PortableTextInput(props2) {
32839
32842
  onChange(toFormPatches(change.patches));
32840
32843
  break;
32841
32844
  case "selection":
32842
- setFocusPathFromEditorSelection(change.selection);
32845
+ setFocusPathFromEditorSelection(change.selection, editorRef.current?.getSnapshot() ?? null);
32843
32846
  break;
32844
32847
  case "focus":
32845
32848
  setIsActive(!0), setHasFocusWithin(!0);
@@ -32860,9 +32863,9 @@ function PortableTextInput(props2) {
32860
32863
  setReady(!0);
32861
32864
  break;
32862
32865
  }
32863
- editorRef.current && onEditorChange && onEditorChange(change, editorRef.current);
32866
+ legacyEditorRef.current && onEditorChange && onEditorChange(change, legacyEditorRef.current);
32864
32867
  },
32865
- [editorRef, onEditorChange, onChange, setFocusPathFromEditorSelection, onBlur, toast]
32868
+ [legacyEditorRef, editorRef, onEditorChange, onChange, setFocusPathFromEditorSelection, onBlur, toast]
32866
32869
  );
32867
32870
  useEffect(() => {
32868
32871
  setIgnoreValidationError(!1);
@@ -32870,8 +32873,8 @@ function PortableTextInput(props2) {
32870
32873
  const handleIgnoreInvalidValue = useCallback(() => {
32871
32874
  setIgnoreValidationError(!0);
32872
32875
  }, []), respondToInvalidContent = useMemo(() => invalidValue && invalidValue.resolution ? /* @__PURE__ */ jsx(Box, { marginBottom: 2, children: /* @__PURE__ */ jsx(InvalidValue, { onChange: handleEditorChange, onIgnore: handleIgnoreInvalidValue, resolution: invalidValue.resolution, readOnly }) }) : null, [handleEditorChange, handleIgnoreInvalidValue, invalidValue, readOnly]), handleActivate = useCallback(() => {
32873
- isActive || (setIsActive(!0), editorRef.current && PortableTextEditor.focus(editorRef.current));
32874
- }, [editorRef, isActive]), previousRangeDecorations = useRef([]), rangeDecorations = useMemo(() => {
32876
+ isActive || (setIsActive(!0), legacyEditorRef.current && PortableTextEditor.focus(legacyEditorRef.current));
32877
+ }, [legacyEditorRef, isActive]), previousRangeDecorations = useRef([]), rangeDecorations = useMemo(() => {
32875
32878
  const result = displayInlineChanges ? diffRangeDecorations : [...rangeDecorationsProp || [], ...presenceCursorDecorations], reconciled = immutableReconcile(previousRangeDecorations.current, result);
32876
32879
  return previousRangeDecorations.current = reconciled, reconciled;
32877
32880
  }, [diffRangeDecorations, displayInlineChanges, presenceCursorDecorations, rangeDecorationsProp]);
@@ -32884,6 +32887,7 @@ function PortableTextInput(props2) {
32884
32887
  schemaDefinition: sanitySchemaToPortableTextSchema(schemaType)
32885
32888
  }, children: [
32886
32889
  /* @__PURE__ */ jsx(EditorChangePlugin, { onChange: handleEditorChange, onOptimisticChange }),
32890
+ /* @__PURE__ */ jsx(LegacyEditorRefPlugin, { ref: legacyEditorRef }),
32887
32891
  /* @__PURE__ */ jsx(EditorRefPlugin$1, { ref: editorRef }),
32888
32892
  /* @__PURE__ */ jsx(PatchesPlugin, { path }),
32889
32893
  /* @__PURE__ */ jsx(UpdateReadOnlyPlugin$1, { readOnly: readOnly || !ready }),