@portabletext/editor 3.3.0 → 3.3.2

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.
Files changed (46) hide show
  1. package/lib/_chunks-dts/index.d.ts +1705 -69
  2. package/lib/_chunks-es/use-editor.js +8 -4
  3. package/lib/_chunks-es/use-editor.js.map +1 -1
  4. package/lib/index.d.ts +1 -1
  5. package/lib/index.js +9047 -511
  6. package/lib/index.js.map +1 -1
  7. package/lib/plugins/index.d.ts +1 -1
  8. package/package.json +4 -4
  9. package/src/behaviors/behavior.perform-event.ts +1 -1
  10. package/src/editor/PortableTextEditor.tsx +3 -1
  11. package/src/editor/create-editor.ts +2 -1
  12. package/src/editor/create-slate-editor.tsx +1 -1
  13. package/src/editor/editor-dom.ts +1 -1
  14. package/src/editor/editor-machine.ts +1 -1
  15. package/src/editor/editor-selector.ts +1 -1
  16. package/src/editor/editor-snapshot.ts +2 -1
  17. package/src/editor/mutation-machine.ts +1 -1
  18. package/src/editor/plugins/createWithEditableAPI.ts +3 -4
  19. package/src/editor/plugins/createWithHotKeys.ts +1 -1
  20. package/src/editor/plugins/createWithObjectKeys.ts +1 -1
  21. package/src/editor/plugins/createWithPatches.ts +5 -3
  22. package/src/editor/plugins/createWithPortableTextMarkModel.ts +1 -1
  23. package/src/editor/plugins/createWithSchemaTypes.ts +1 -1
  24. package/src/editor/plugins/slate-plugin.update-selection.ts +1 -1
  25. package/src/editor/plugins/slate-plugin.update-value.ts +1 -1
  26. package/src/editor/plugins/with-plugins.ts +1 -1
  27. package/src/editor/range-decorations-machine.ts +2 -1
  28. package/src/editor/sync-machine.ts +10 -7
  29. package/src/editor/validate-selection-machine.ts +1 -1
  30. package/src/history/slate-plugin.history.ts +1 -1
  31. package/src/history/transform-operation.ts +1 -1
  32. package/src/internal-utils/apply-operation-to-portable-text.ts +10 -1
  33. package/src/internal-utils/applyPatch.ts +1 -1
  34. package/src/internal-utils/event-position.ts +45 -5
  35. package/src/internal-utils/global-scope.ts +12 -4
  36. package/src/internal-utils/sibling-utils.ts +1 -1
  37. package/src/internal-utils/slate-utils.test.tsx +1 -1
  38. package/src/internal-utils/slate-utils.ts +2 -1
  39. package/src/operations/behavior.operation.delete.ts +1 -1
  40. package/src/operations/behavior.operation.insert.block.ts +2 -1
  41. package/src/operations/behavior.operations.ts +1 -1
  42. package/src/plugins/plugin.internal.slate-editor-ref.tsx +1 -1
  43. package/src/priority/priority.sort.ts +3 -1
  44. package/src/types/editor.ts +1 -51
  45. package/src/types/slate-editor.ts +50 -0
  46. package/src/types/slate.ts +1 -1
@@ -1,9 +1,13 @@
1
1
  import React, { createContext } from "react";
2
2
  function getGlobalScope() {
3
- if (typeof globalThis < "u") return globalThis;
4
- if (typeof window < "u") return window;
5
- if (typeof self < "u") return self;
6
- if (typeof global < "u") return global;
3
+ if (typeof globalThis < "u")
4
+ return globalThis;
5
+ if (typeof window < "u")
6
+ return window;
7
+ if (typeof self < "u")
8
+ return self;
9
+ if (typeof global < "u")
10
+ return global;
7
11
  throw new Error("@portabletext/editor: could not locate global scope");
8
12
  }
9
13
  const globalScope = getGlobalScope();
@@ -1 +1 @@
1
- {"version":3,"file":"use-editor.js","sources":["../../src/internal-utils/global-scope.ts","../../src/internal-utils/globally-scoped-context.ts","../../src/editor/editor-context.tsx","../../src/editor/use-editor.ts"],"sourcesContent":["/**\n * Gets the global scope instance in a given environment.\n *\n * The strategy is to return the most modern, and if not, the most common:\n * - The `globalThis` variable is the modern approach to accessing the global scope\n * - The `window` variable is the global scope in a web browser\n * - The `self` variable is the global scope in workers and others\n * - The `global` variable is the global scope in Node.js\n */\nfunction getGlobalScope() {\n if (typeof globalThis !== 'undefined') return globalThis\n if (typeof window !== 'undefined') return window\n if (typeof self !== 'undefined') return self\n if (typeof global !== 'undefined') return global\n\n throw new Error('@portabletext/editor: could not locate global scope')\n}\n\nexport const globalScope = getGlobalScope() as any\n","import {createContext, type Context} from 'react'\nimport {globalScope} from './global-scope'\n\n/**\n * As `@portabletext/editor` is declared as a dependency, and may be\n * duplicated, sometimes across major versions it's critical that vital\n * React Contexts are shared even when there is a duplicate.\n *\n * We have to support a Sanity Plugin being able to call hooks like\n * `useEditor`, and then read the context setup by `sanity`, which calls\n * `EditorProvider`, even if the provider and hook are different instances in\n * memory.\n *\n * For this reason it's vital that all changes to globally scoped providers\n * remain fully backwards compatible.\n */\nexport function createGloballyScopedContext<\n ContextType,\n const T extends ContextType = ContextType,\n>(\n /**\n * Enforce that all Symbol.for keys used for globally scoped contexts have a predictable prefix\n */\n key: `@portabletext/editor/context/${string}`,\n defaultValue: T,\n): Context<ContextType> {\n const symbol = Symbol.for(key)\n\n /**\n * Prevent errors about re-renders on React SSR on Next.js App Router\n */\n if (typeof document === 'undefined') {\n return createContext<ContextType>(defaultValue)\n }\n\n globalScope[symbol] = globalScope[symbol] ?? createContext<T>(defaultValue)\n\n return globalScope[symbol]\n}\n","import type {Editor} from '../editor'\nimport {createGloballyScopedContext} from '../internal-utils/globally-scoped-context'\n\nexport const EditorContext = createGloballyScopedContext<Editor | null>(\n '@portabletext/editor/context/editor',\n null,\n)\n","import React from 'react'\nimport {EditorContext} from './editor-context'\n\n/**\n * @public\n * Get the current editor context from the `EditorProvider`.\n * Must be used inside the `EditorProvider` component.\n * @returns The current editor object.\n * @example\n * ```tsx\n * import { useEditor } from '@portabletext/editor'\n *\n * function MyComponent() {\n * const editor = useEditor()\n * }\n * ```\n * @group Hooks\n */\nexport function useEditor() {\n const editor = React.useContext(EditorContext)\n\n if (!editor) {\n throw new Error('No Editor set. Use EditorProvider to set one.')\n }\n\n return editor\n}\n"],"names":["getGlobalScope","globalThis","window","self","global","Error","globalScope","createGloballyScopedContext","key","defaultValue","symbol","Symbol","for","document","createContext","EditorContext","useEditor","editor","React","useContext"],"mappings":";AASA,SAASA,iBAAiB;AACxB,MAAI,OAAOC,aAAe,IAAa,QAAOA;AAC9C,MAAI,OAAOC,SAAW,IAAa,QAAOA;AAC1C,MAAI,OAAOC,OAAS,IAAa,QAAOA;AACxC,MAAI,OAAOC,SAAW,IAAa,QAAOA;AAE1C,QAAM,IAAIC,MAAM,qDAAqD;AACvE;AAEO,MAAMC,cAAcN,eAAAA;ACFpB,SAASO,4BAOdC,KACAC,cACsB;AACtB,QAAMC,SAASC,OAAOC,IAAIJ,GAAG;AAK7B,SAAI,OAAOK,WAAa,MACfC,cAA2BL,YAAY,KAGhDH,YAAYI,MAAM,IAAIJ,YAAYI,MAAM,KAAKI,cAAiBL,YAAY,GAEnEH,YAAYI,MAAM;AAC3B;ACnCO,MAAMK,gBAAgBR,4BAC3B,uCACA,IACF;ACYO,SAAAS,YAAA;AACL,QAAAC,SAAeC,MAAKC,WAAYJ,aAAa;AAE7C,MAAI,CAACE;AACH,UAAM,IAAIZ,MAAM,+CAA+C;AAChE,SAEMY;AAAM;"}
1
+ {"version":3,"file":"use-editor.js","sources":["../../src/internal-utils/global-scope.ts","../../src/internal-utils/globally-scoped-context.ts","../../src/editor/editor-context.tsx","../../src/editor/use-editor.ts"],"sourcesContent":["/**\n * Gets the global scope instance in a given environment.\n *\n * The strategy is to return the most modern, and if not, the most common:\n * - The `globalThis` variable is the modern approach to accessing the global scope\n * - The `window` variable is the global scope in a web browser\n * - The `self` variable is the global scope in workers and others\n * - The `global` variable is the global scope in Node.js\n */\nfunction getGlobalScope() {\n if (typeof globalThis !== 'undefined') {\n return globalThis\n }\n if (typeof window !== 'undefined') {\n return window\n }\n if (typeof self !== 'undefined') {\n return self\n }\n if (typeof global !== 'undefined') {\n return global\n }\n\n throw new Error('@portabletext/editor: could not locate global scope')\n}\n\nexport const globalScope = getGlobalScope() as any\n","import {createContext, type Context} from 'react'\nimport {globalScope} from './global-scope'\n\n/**\n * As `@portabletext/editor` is declared as a dependency, and may be\n * duplicated, sometimes across major versions it's critical that vital\n * React Contexts are shared even when there is a duplicate.\n *\n * We have to support a Sanity Plugin being able to call hooks like\n * `useEditor`, and then read the context setup by `sanity`, which calls\n * `EditorProvider`, even if the provider and hook are different instances in\n * memory.\n *\n * For this reason it's vital that all changes to globally scoped providers\n * remain fully backwards compatible.\n */\nexport function createGloballyScopedContext<\n ContextType,\n const T extends ContextType = ContextType,\n>(\n /**\n * Enforce that all Symbol.for keys used for globally scoped contexts have a predictable prefix\n */\n key: `@portabletext/editor/context/${string}`,\n defaultValue: T,\n): Context<ContextType> {\n const symbol = Symbol.for(key)\n\n /**\n * Prevent errors about re-renders on React SSR on Next.js App Router\n */\n if (typeof document === 'undefined') {\n return createContext<ContextType>(defaultValue)\n }\n\n globalScope[symbol] = globalScope[symbol] ?? createContext<T>(defaultValue)\n\n return globalScope[symbol]\n}\n","import type {Editor} from '../editor'\nimport {createGloballyScopedContext} from '../internal-utils/globally-scoped-context'\n\nexport const EditorContext = createGloballyScopedContext<Editor | null>(\n '@portabletext/editor/context/editor',\n null,\n)\n","import React from 'react'\nimport {EditorContext} from './editor-context'\n\n/**\n * @public\n * Get the current editor context from the `EditorProvider`.\n * Must be used inside the `EditorProvider` component.\n * @returns The current editor object.\n * @example\n * ```tsx\n * import { useEditor } from '@portabletext/editor'\n *\n * function MyComponent() {\n * const editor = useEditor()\n * }\n * ```\n * @group Hooks\n */\nexport function useEditor() {\n const editor = React.useContext(EditorContext)\n\n if (!editor) {\n throw new Error('No Editor set. Use EditorProvider to set one.')\n }\n\n return editor\n}\n"],"names":["getGlobalScope","globalThis","window","self","global","Error","globalScope","createGloballyScopedContext","key","defaultValue","symbol","Symbol","for","document","createContext","EditorContext","useEditor","editor","React","useContext"],"mappings":";AASA,SAASA,iBAAiB;AACxB,MAAI,OAAOC,aAAe;AACxB,WAAOA;AAET,MAAI,OAAOC,SAAW;AACpB,WAAOA;AAET,MAAI,OAAOC,OAAS;AAClB,WAAOA;AAET,MAAI,OAAOC,SAAW;AACpB,WAAOA;AAGT,QAAM,IAAIC,MAAM,qDAAqD;AACvE;AAEO,MAAMC,cAAcN,eAAAA;ACVpB,SAASO,4BAOdC,KACAC,cACsB;AACtB,QAAMC,SAASC,OAAOC,IAAIJ,GAAG;AAK7B,SAAI,OAAOK,WAAa,MACfC,cAA2BL,YAAY,KAGhDH,YAAYI,MAAM,IAAIJ,YAAYI,MAAM,KAAKI,cAAiBL,YAAY,GAEnEH,YAAYI,MAAM;AAC3B;ACnCO,MAAMK,gBAAgBR,4BAC3B,uCACA,IACF;ACYO,SAAAS,YAAA;AACL,QAAAC,SAAeC,MAAKC,WAAYJ,aAAa;AAE7C,MAAI,CAACE;AACH,UAAM,IAAIZ,MAAM,+CAA+C;AAChE,SAEMY;AAAM;"}
package/lib/index.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { $ as BlockAnnotationRenderProps, $t as EditorSchema, A as PortableTextTextBlock, At as ReadyChange, B as EditorSelector, Bt as ScrollSelectionIntoViewFunction, C as ListDefinition, Ct as OnPasteResultOrPromise, D as PortableTextChild, Dt as PortableTextMemberSchemaTypes, E as PortableTextBlock, Et as PatchObservable, F as BlockOffset, Ft as RenderDecoratorFunction, G as EditorConfig, Gt as AnnotationPath, H as EditorProvider, Ht as UndoChange, I as useEditor, It as RenderEditableFunction, Jt as PortableTextEditable, K as EditorEvent, Kt as BlockPath, L as defaultKeyGenerator, Lt as RenderListItemFunction, M as StyleDefinition, Mt as RenderAnnotationFunction, N as StyleSchemaType, Nt as RenderBlockFunction, O as PortableTextObject, Ot as RangeDecoration, P as defineSchema, Pt as RenderChildFunction, Q as AddedAnnotationPaths, Qt as PortableTextEditorProps, R as usePortableTextEditorSelection, Rt as RenderPlaceholderFunction, S as InlineObjectSchemaType, St as OnPasteResult, T as Patch, Tt as PatchChange, U as EditorProviderProps, Ut as UnsetChange, V as useEditorSelector, Vt as SelectionChange, W as Editor, Wt as ValueChange, X as EditorContext, Xt as HotkeyOptions, Yt as PortableTextEditableProps, Z as EditorSnapshot, Zt as PortableTextEditor, _ as BlockObjectSchemaType, _t as LoadingChange, at as BlurChange, b as FieldDefinition, bt as OnCopyFn, ct as EditableAPIDeleteOptions, dt as EditorSelection, en as EditorEmittedEvent, et as BlockChildRenderProps, f as PatchesEvent, ft as EditorSelectionPoint, g as BlockObjectDefinition, gt as InvalidValueResolution, h as BaseDefinition, ht as InvalidValue, it as BlockStyleRenderProps, j as SchemaDefinition, jt as RedoChange, k as PortableTextSpan, kt as RangeDecorationOnMovedDetails, lt as EditorChange, m as AnnotationSchemaType, mt as FocusChange, nt as BlockListItemRenderProps, ot as ConnectionChange, p as AnnotationDefinition, pt as ErrorChange, qt as ChildPath, rt as BlockRenderProps, st as EditableAPI, tn as MutationEvent, tt as BlockDecoratorRenderProps, ut as EditorChanges, v as DecoratorDefinition, vt as MutationChange, w as ListSchemaType, wt as PasteData, x as InlineObjectDefinition, xt as OnPasteFn, y as DecoratorSchemaType, yt as OnBeforeInputFn, z as usePortableTextEditor, zt as RenderStyleFunction } from "./_chunks-dts/index.js";
1
+ import { $ as BlockAnnotationRenderProps, $t as EditorEmittedEvent, A as PortableTextTextBlock, At as ReadyChange, B as EditorSelector, Bt as ScrollSelectionIntoViewFunction, C as ListDefinition, Ct as OnPasteResultOrPromise, D as PortableTextChild, Dt as PortableTextMemberSchemaTypes, E as PortableTextBlock, Et as PatchObservable, F as BlockOffset, Ft as RenderDecoratorFunction, G as EditorConfig, Gt as AnnotationPath, H as EditorProvider, Ht as UndoChange, I as useEditor, It as RenderEditableFunction, Jt as PortableTextEditable, K as EditorEvent, Kt as BlockPath, L as defaultKeyGenerator, Lt as RenderListItemFunction, M as StyleDefinition, Mt as RenderAnnotationFunction, N as StyleSchemaType, Nt as RenderBlockFunction, O as PortableTextObject, Ot as RangeDecoration, P as defineSchema, Pt as RenderChildFunction, Q as AddedAnnotationPaths, Qt as PortableTextEditorProps, R as usePortableTextEditorSelection, Rt as RenderPlaceholderFunction, S as InlineObjectSchemaType, St as OnPasteResult, T as Patch, Tt as PatchChange, U as EditorProviderProps, Ut as UnsetChange, V as useEditorSelector, Vt as SelectionChange, W as Editor, Wt as ValueChange, X as EditorContext, Xt as HotkeyOptions, Yt as PortableTextEditableProps, Z as EditorSnapshot, Zt as PortableTextEditor, _ as BlockObjectSchemaType, _t as LoadingChange, at as BlurChange, b as FieldDefinition, bt as OnCopyFn, ct as EditableAPIDeleteOptions, dt as EditorSelection, en as MutationEvent, et as BlockChildRenderProps, f as PatchesEvent, ft as EditorSelectionPoint, g as BlockObjectDefinition, gt as InvalidValueResolution, h as BaseDefinition, ht as InvalidValue, it as BlockStyleRenderProps, j as SchemaDefinition, jt as RedoChange, k as PortableTextSpan, kt as RangeDecorationOnMovedDetails, lt as EditorChange, m as AnnotationSchemaType, mt as FocusChange, nt as BlockListItemRenderProps, ot as ConnectionChange, p as AnnotationDefinition, pt as ErrorChange, qt as ChildPath, rt as BlockRenderProps, st as EditableAPI, tn as EditorSchema, tt as BlockDecoratorRenderProps, ut as EditorChanges, v as DecoratorDefinition, vt as MutationChange, w as ListSchemaType, wt as PasteData, x as InlineObjectDefinition, xt as OnPasteFn, y as DecoratorSchemaType, yt as OnBeforeInputFn, z as usePortableTextEditor, zt as RenderStyleFunction } from "./_chunks-dts/index.js";
2
2
  export { AddedAnnotationPaths, AnnotationDefinition, AnnotationPath, AnnotationSchemaType, BaseDefinition, BlockAnnotationRenderProps, BlockChildRenderProps, BlockDecoratorRenderProps, BlockListItemRenderProps, BlockObjectDefinition, BlockObjectSchemaType, BlockOffset, BlockPath, BlockRenderProps, BlockStyleRenderProps, BlurChange, ChildPath, ConnectionChange, DecoratorDefinition, DecoratorSchemaType, EditableAPI, EditableAPIDeleteOptions, Editor, EditorChange, EditorChanges, EditorConfig, EditorContext, EditorEmittedEvent, EditorEvent, EditorProvider, EditorProviderProps, EditorSchema, EditorSelection, EditorSelectionPoint, EditorSelector, EditorSnapshot, ErrorChange, FieldDefinition, FocusChange, HotkeyOptions, InlineObjectDefinition, InlineObjectSchemaType, InvalidValue, InvalidValueResolution, ListDefinition, ListSchemaType, LoadingChange, MutationChange, MutationEvent, OnBeforeInputFn, OnCopyFn, OnPasteFn, OnPasteResult, OnPasteResultOrPromise, PasteData, Patch, PatchChange, PatchObservable, PatchesEvent, PortableTextBlock, PortableTextChild, PortableTextEditable, PortableTextEditableProps, PortableTextEditor, PortableTextEditorProps, PortableTextMemberSchemaTypes, PortableTextObject, PortableTextSpan, PortableTextTextBlock, RangeDecoration, RangeDecorationOnMovedDetails, ReadyChange, RedoChange, RenderAnnotationFunction, RenderBlockFunction, RenderChildFunction, RenderDecoratorFunction, RenderEditableFunction, RenderListItemFunction, RenderPlaceholderFunction, RenderStyleFunction, SchemaDefinition, ScrollSelectionIntoViewFunction, SelectionChange, StyleDefinition, StyleSchemaType, UndoChange, UnsetChange, ValueChange, defineSchema, defaultKeyGenerator as keyGenerator, useEditor, useEditorSelector, usePortableTextEditor, usePortableTextEditorSelection };