@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.
- package/lib/_chunks-cjs/editor-provider.cjs +19 -7
- package/lib/_chunks-cjs/editor-provider.cjs.map +1 -1
- package/lib/_chunks-es/editor-provider.js +19 -7
- package/lib/_chunks-es/editor-provider.js.map +1 -1
- package/lib/behaviors/index.d.cts +6 -6
- package/lib/behaviors/index.d.ts +6 -6
- package/lib/index.d.cts +3 -2
- package/lib/index.d.ts +3 -2
- package/lib/plugins/index.d.cts +1 -1
- package/lib/plugins/index.d.ts +1 -1
- package/lib/selectors/index.d.cts +1 -1
- package/lib/selectors/index.d.ts +1 -1
- package/lib/utils/index.d.cts +1 -1
- package/lib/utils/index.d.ts +1 -1
- package/package.json +10 -10
- package/src/behaviors/behavior.perform-event.ts +5 -2
- package/src/behaviors/behavior.types.event.ts +1 -1
- package/src/editor/editor-context.tsx +7 -0
- package/src/editor/editor-provider.tsx +1 -3
- package/src/internal-utils/global-scope.ts +19 -0
- package/src/internal-utils/globally-scoped-context.ts +39 -0
|
@@ -151,7 +151,7 @@ declare type AbstractBehaviorEvent =
|
|
|
151
151
|
}
|
|
152
152
|
| {
|
|
153
153
|
type: StrictExtract_2<SyntheticBehaviorEventType, 'insert.blocks'>
|
|
154
|
-
blocks: Array<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
12254
|
+
blocks: Array<BlockWithOptionalKey>
|
|
12255
12255
|
placement: InsertPlacement
|
|
12256
12256
|
}
|
|
12257
12257
|
| {
|
package/lib/behaviors/index.d.ts
CHANGED
|
@@ -151,7 +151,7 @@ declare type AbstractBehaviorEvent =
|
|
|
151
151
|
}
|
|
152
152
|
| {
|
|
153
153
|
type: StrictExtract_2<SyntheticBehaviorEventType, 'insert.blocks'>
|
|
154
|
-
blocks: Array<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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<
|
|
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():
|
|
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<
|
|
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():
|
|
6819
|
+
export declare function useEditor(): Editor_2
|
|
6819
6820
|
|
|
6820
6821
|
/**
|
|
6821
6822
|
* @public
|
package/lib/plugins/index.d.cts
CHANGED
package/lib/plugins/index.d.ts
CHANGED
package/lib/selectors/index.d.ts
CHANGED
package/lib/utils/index.d.cts
CHANGED
package/lib/utils/index.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/editor",
|
|
3
|
-
"version": "1.47.
|
|
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.
|
|
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.
|
|
90
|
-
"@sanity/types": "^3.86.
|
|
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.
|
|
101
|
-
"@vitest/browser": "^3.1.
|
|
102
|
-
"@vitest/coverage-istanbul": "^3.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.
|
|
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.
|
|
119
|
-
"@sanity/types": "^3.86.
|
|
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
|
-
? '
|
|
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(
|
|
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) ||
|
|
@@ -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
|
+
}
|