@portabletext/editor 1.47.13 → 1.47.15

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.
@@ -151,7 +151,7 @@ declare type AbstractBehaviorEvent =
151
151
  }
152
152
  | {
153
153
  type: StrictExtract_2<SyntheticBehaviorEventType, 'insert.blocks'>
154
- blocks: Array<PortableTextBlock>
154
+ blocks: Array<BlockWithOptionalKey_2>
155
155
  placement: InsertPlacement_2
156
156
  }
157
157
  | {
@@ -2033,7 +2033,7 @@ export declare const coreBehaviors: Behavior_2<
2033
2033
  | 'style.toggle',
2034
2034
  'insert.blocks'
2035
2035
  >
2036
- blocks: Array<PortableTextBlock>
2036
+ blocks: Array<BlockWithOptionalKey>
2037
2037
  placement: InsertPlacement
2038
2038
  }
2039
2039
  | {
@@ -4577,7 +4577,7 @@ export declare function createCodeEditorBehaviors(
4577
4577
  | 'style.toggle',
4578
4578
  'insert.blocks'
4579
4579
  >
4580
- blocks: Array<PortableTextBlock>
4580
+ blocks: Array<BlockWithOptionalKey>
4581
4581
  placement: InsertPlacement
4582
4582
  }
4583
4583
  | {
@@ -7121,7 +7121,7 @@ export declare function createEmojiPickerBehaviors<TEmojiMatch>(
7121
7121
  | 'style.toggle',
7122
7122
  'insert.blocks'
7123
7123
  >
7124
- blocks: Array<PortableTextBlock>
7124
+ blocks: Array<BlockWithOptionalKey>
7125
7125
  placement: InsertPlacement
7126
7126
  }
7127
7127
  | {
@@ -9665,7 +9665,7 @@ export declare function createLinkBehaviors(
9665
9665
  | 'style.toggle',
9666
9666
  'insert.blocks'
9667
9667
  >
9668
- blocks: Array<PortableTextBlock>
9668
+ blocks: Array<BlockWithOptionalKey>
9669
9669
  placement: InsertPlacement
9670
9670
  }
9671
9671
  | {
@@ -12251,7 +12251,7 @@ export declare function createMarkdownBehaviors(
12251
12251
  | 'style.toggle',
12252
12252
  'insert.blocks'
12253
12253
  >
12254
- blocks: Array<PortableTextBlock>
12254
+ blocks: Array<BlockWithOptionalKey>
12255
12255
  placement: InsertPlacement
12256
12256
  }
12257
12257
  | {
@@ -151,7 +151,7 @@ declare type AbstractBehaviorEvent =
151
151
  }
152
152
  | {
153
153
  type: StrictExtract_2<SyntheticBehaviorEventType, 'insert.blocks'>
154
- blocks: Array<PortableTextBlock>
154
+ blocks: Array<BlockWithOptionalKey_2>
155
155
  placement: InsertPlacement_2
156
156
  }
157
157
  | {
@@ -2033,7 +2033,7 @@ export declare const coreBehaviors: Behavior_2<
2033
2033
  | 'style.toggle',
2034
2034
  'insert.blocks'
2035
2035
  >
2036
- blocks: Array<PortableTextBlock>
2036
+ blocks: Array<BlockWithOptionalKey>
2037
2037
  placement: InsertPlacement
2038
2038
  }
2039
2039
  | {
@@ -4577,7 +4577,7 @@ export declare function createCodeEditorBehaviors(
4577
4577
  | 'style.toggle',
4578
4578
  'insert.blocks'
4579
4579
  >
4580
- blocks: Array<PortableTextBlock>
4580
+ blocks: Array<BlockWithOptionalKey>
4581
4581
  placement: InsertPlacement
4582
4582
  }
4583
4583
  | {
@@ -7121,7 +7121,7 @@ export declare function createEmojiPickerBehaviors<TEmojiMatch>(
7121
7121
  | 'style.toggle',
7122
7122
  'insert.blocks'
7123
7123
  >
7124
- blocks: Array<PortableTextBlock>
7124
+ blocks: Array<BlockWithOptionalKey>
7125
7125
  placement: InsertPlacement
7126
7126
  }
7127
7127
  | {
@@ -9665,7 +9665,7 @@ export declare function createLinkBehaviors(
9665
9665
  | 'style.toggle',
9666
9666
  'insert.blocks'
9667
9667
  >
9668
- blocks: Array<PortableTextBlock>
9668
+ blocks: Array<BlockWithOptionalKey>
9669
9669
  placement: InsertPlacement
9670
9670
  }
9671
9671
  | {
@@ -12251,7 +12251,7 @@ export declare function createMarkdownBehaviors(
12251
12251
  | 'style.toggle',
12252
12252
  'insert.blocks'
12253
12253
  >
12254
- blocks: Array<PortableTextBlock>
12254
+ blocks: Array<BlockWithOptionalKey>
12255
12255
  placement: InsertPlacement
12256
12256
  }
12257
12257
  | {
package/lib/index.d.cts CHANGED
@@ -63,6 +63,7 @@ import {
63
63
  } from 'xstate'
64
64
  import type {EventObject, Snapshot} from 'xstate'
65
65
  import {GuardArgs} from 'xstate/guards'
66
+ import {Editor as Editor_2} from './create-editor'
66
67
 
67
68
  declare type AbstractBehaviorEvent =
68
69
  | {
@@ -153,7 +154,7 @@ declare type AbstractBehaviorEvent =
153
154
  }
154
155
  | {
155
156
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
156
- blocks: Array<PortableTextBlock>
157
+ blocks: Array<BlockWithOptionalKey>
157
158
  placement: InsertPlacement
158
159
  }
159
160
  | {
@@ -6815,7 +6816,7 @@ declare type UnsetEvent = {
6815
6816
  * ```
6816
6817
  * @group Hooks
6817
6818
  */
6818
- export declare function useEditor(): Editor
6819
+ export declare function useEditor(): Editor_2
6819
6820
 
6820
6821
  /**
6821
6822
  * @public
package/lib/index.d.ts CHANGED
@@ -63,6 +63,7 @@ import {
63
63
  } from 'xstate'
64
64
  import type {EventObject, Snapshot} from 'xstate'
65
65
  import {GuardArgs} from 'xstate/guards'
66
+ import {Editor as Editor_2} from './create-editor'
66
67
 
67
68
  declare type AbstractBehaviorEvent =
68
69
  | {
@@ -153,7 +154,7 @@ declare type AbstractBehaviorEvent =
153
154
  }
154
155
  | {
155
156
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
156
- blocks: Array<PortableTextBlock>
157
+ blocks: Array<BlockWithOptionalKey>
157
158
  placement: InsertPlacement
158
159
  }
159
160
  | {
@@ -6815,7 +6816,7 @@ declare type UnsetEvent = {
6815
6816
  * ```
6816
6817
  * @group Hooks
6817
6818
  */
6818
- export declare function useEditor(): Editor
6819
+ export declare function useEditor(): Editor_2
6819
6820
 
6820
6821
  /**
6821
6822
  * @public
@@ -134,7 +134,7 @@ declare type AbstractBehaviorEvent =
134
134
  }
135
135
  | {
136
136
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
137
- blocks: Array<PortableTextBlock>
137
+ blocks: Array<BlockWithOptionalKey>
138
138
  placement: InsertPlacement
139
139
  }
140
140
  | {
@@ -134,7 +134,7 @@ declare type AbstractBehaviorEvent =
134
134
  }
135
135
  | {
136
136
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
137
- blocks: Array<PortableTextBlock>
137
+ blocks: Array<BlockWithOptionalKey>
138
138
  placement: InsertPlacement
139
139
  }
140
140
  | {
@@ -134,7 +134,7 @@ declare type AbstractBehaviorEvent =
134
134
  }
135
135
  | {
136
136
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
137
- blocks: Array<PortableTextBlock>
137
+ blocks: Array<BlockWithOptionalKey>
138
138
  placement: InsertPlacement
139
139
  }
140
140
  | {
@@ -134,7 +134,7 @@ declare type AbstractBehaviorEvent =
134
134
  }
135
135
  | {
136
136
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
137
- blocks: Array<PortableTextBlock>
137
+ blocks: Array<BlockWithOptionalKey>
138
138
  placement: InsertPlacement
139
139
  }
140
140
  | {
@@ -134,7 +134,7 @@ declare type AbstractBehaviorEvent =
134
134
  }
135
135
  | {
136
136
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
137
- blocks: Array<PortableTextBlock>
137
+ blocks: Array<BlockWithOptionalKey>
138
138
  placement: InsertPlacement
139
139
  }
140
140
  | {
@@ -134,7 +134,7 @@ declare type AbstractBehaviorEvent =
134
134
  }
135
135
  | {
136
136
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
137
- blocks: Array<PortableTextBlock>
137
+ blocks: Array<BlockWithOptionalKey>
138
138
  placement: InsertPlacement
139
139
  }
140
140
  | {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/editor",
3
- "version": "1.47.13",
3
+ "version": "1.47.15",
4
4
  "description": "Portable Text Editor made in React",
5
5
  "keywords": [
6
6
  "sanity",
@@ -79,15 +79,15 @@
79
79
  "slate-react": "0.112.1",
80
80
  "use-effect-event": "^1.0.2",
81
81
  "xstate": "^5.19.2",
82
- "@portabletext/block-tools": "1.1.20",
82
+ "@portabletext/block-tools": "1.1.21",
83
83
  "@portabletext/patches": "1.1.3"
84
84
  },
85
85
  "devDependencies": {
86
86
  "@portabletext/toolkit": "^2.0.17",
87
87
  "@sanity/diff-match-patch": "^3.2.0",
88
88
  "@sanity/pkg-utils": "^7.2.2",
89
- "@sanity/schema": "^3.86.0",
90
- "@sanity/types": "^3.86.0",
89
+ "@sanity/schema": "^3.86.1",
90
+ "@sanity/types": "^3.86.1",
91
91
  "@testing-library/jest-dom": "^6.6.3",
92
92
  "@testing-library/react": "^16.3.0",
93
93
  "@types/debug": "^4.1.12",
@@ -97,9 +97,9 @@
97
97
  "@types/react-dom": "^19.1.2",
98
98
  "@typescript-eslint/eslint-plugin": "^8.29.0",
99
99
  "@typescript-eslint/parser": "^8.29.0",
100
- "@vitejs/plugin-react": "^4.3.4",
101
- "@vitest/browser": "^3.1.1",
102
- "@vitest/coverage-istanbul": "^3.1.1",
100
+ "@vitejs/plugin-react": "^4.4.1",
101
+ "@vitest/browser": "^3.1.2",
102
+ "@vitest/coverage-istanbul": "^3.1.2",
103
103
  "babel-plugin-react-compiler": "19.0.0-beta-e993439-20250328",
104
104
  "eslint": "8.57.1",
105
105
  "eslint-plugin-react-compiler": "19.0.0-beta-e993439-20250328",
@@ -110,13 +110,13 @@
110
110
  "rxjs": "^7.8.2",
111
111
  "typescript": "5.8.3",
112
112
  "vite": "^6.2.5",
113
- "vitest": "^3.1.1",
113
+ "vitest": "^3.1.2",
114
114
  "vitest-browser-react": "^0.1.1",
115
115
  "racejar": "1.2.4"
116
116
  },
117
117
  "peerDependencies": {
118
- "@sanity/schema": "^3.86.0",
119
- "@sanity/types": "^3.86.0",
118
+ "@sanity/schema": "^3.86.1",
119
+ "@sanity/types": "^3.86.1",
120
120
  "react": "^16.9 || ^17 || ^18 || ^19",
121
121
  "rxjs": "^7.8.2"
122
122
  },
@@ -22,7 +22,7 @@ function eventCategory(event: BehaviorEvent) {
22
22
  return isNativeBehaviorEvent(event)
23
23
  ? 'native'
24
24
  : isAbstractBehaviorEvent(event)
25
- ? 'abstract'
25
+ ? 'synthetic'
26
26
  : isCustomBehaviorEvent(event)
27
27
  ? 'custom'
28
28
  : 'synthetic'
@@ -51,7 +51,10 @@ export function performEvent({
51
51
  }
52
52
  | undefined
53
53
  }) {
54
- debug(`(${eventCategory(event)})`, JSON.stringify(event, null, 2))
54
+ debug(
55
+ `(${!isNativeBehaviorEvent(event) ? `${mode}:` : ''}${eventCategory(event)})`,
56
+ JSON.stringify(event, null, 2),
57
+ )
55
58
 
56
59
  const defaultAction =
57
60
  isCustomBehaviorEvent(event) ||
@@ -320,7 +320,7 @@ type AbstractBehaviorEvent =
320
320
  }
321
321
  | {
322
322
  type: StrictExtract<SyntheticBehaviorEventType, 'insert.blocks'>
323
- blocks: Array<PortableTextBlock>
323
+ blocks: Array<BlockWithOptionalKey>
324
324
  placement: InsertPlacement
325
325
  }
326
326
  | {
@@ -0,0 +1,7 @@
1
+ import {createGloballyScopedContext} from '../internal-utils/globally-scoped-context'
2
+ import type {Editor} from './create-editor'
3
+
4
+ export const EditorContext = createGloballyScopedContext<Editor | null>(
5
+ '@portabletext/editor/context/editor',
6
+ null,
7
+ )
@@ -5,10 +5,10 @@ import {Synchronizer} from './components/Synchronizer'
5
5
  import {
6
6
  createInternalEditor,
7
7
  editorConfigToMachineInput,
8
- type Editor,
9
8
  type EditorConfig,
10
9
  } from './create-editor'
11
10
  import {EditorActorContext} from './editor-actor-context'
11
+ import {EditorContext} from './editor-context'
12
12
  import {editorMachine} from './editor-machine'
13
13
  import {PortableTextEditorContext} from './hooks/usePortableTextEditor'
14
14
  import {PortableTextEditorSelectionProvider} from './hooks/usePortableTextEditorSelection'
@@ -18,8 +18,6 @@ import {
18
18
  type PortableTextEditorProps,
19
19
  } from './PortableTextEditor'
20
20
 
21
- const EditorContext = React.createContext<Editor | undefined>(undefined)
22
-
23
21
  /**
24
22
  * @public
25
23
  */
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Gets the global scope instance in a given environment.
3
+ *
4
+ * The strategy is to return the most modern, and if not, the most common:
5
+ * - The `globalThis` variable is the modern approach to accessing the global scope
6
+ * - The `window` variable is the global scope in a web browser
7
+ * - The `self` variable is the global scope in workers and others
8
+ * - The `global` variable is the global scope in Node.js
9
+ */
10
+ function getGlobalScope() {
11
+ if (typeof globalThis !== 'undefined') return globalThis
12
+ if (typeof window !== 'undefined') return window
13
+ if (typeof self !== 'undefined') return self
14
+ if (typeof global !== 'undefined') return global
15
+
16
+ throw new Error('@portabletext/editor: could not locate global scope')
17
+ }
18
+
19
+ export const globalScope = getGlobalScope() as any
@@ -0,0 +1,39 @@
1
+ import {createContext, type Context} from 'react'
2
+ import {globalScope} from './global-scope'
3
+
4
+ /**
5
+ * As `@portabletext/editor` is declared as a dependency, and may be
6
+ * duplicated, sometimes across major versions it's critical that vital
7
+ * React Contexts are shared even when there is a duplicate.
8
+ *
9
+ * We have to support a Sanity Plugin being able to call hooks like
10
+ * `useEditor`, and then read the context setup by `sanity`, which calls
11
+ * `EditorProvider`, even if the provider and hook are different instances in
12
+ * memory.
13
+ *
14
+ * For this reason it's vital that all changes to globally scoped providers
15
+ * remain fully backwards compatible.
16
+ */
17
+ export function createGloballyScopedContext<
18
+ ContextType,
19
+ const T extends ContextType = ContextType,
20
+ >(
21
+ /**
22
+ * Enforce that all Symbol.for keys used for globally scoped contexts have a predictable prefix
23
+ */
24
+ key: `@portabletext/editor/context/${string}`,
25
+ defaultValue: T,
26
+ ): Context<ContextType> {
27
+ const symbol = Symbol.for(key)
28
+
29
+ /**
30
+ * Prevent errors about re-renders on React SSR on Next.js App Router
31
+ */
32
+ if (typeof document === 'undefined') {
33
+ return createContext<ContextType>(defaultValue)
34
+ }
35
+
36
+ globalScope[symbol] = globalScope[symbol] ?? createContext<T>(defaultValue)
37
+
38
+ return globalScope[symbol]
39
+ }