@portabletext/plugin-sdk-value 7.2.1 → 7.2.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.
- package/dist/index.d.ts +94 -125
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +931 -937
- package/dist/index.js.map +1 -1
- package/package.json +16 -14
package/dist/index.d.ts
CHANGED
|
@@ -1,142 +1,76 @@
|
|
|
1
|
-
import {DocumentHandle} from
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import {PortableTextEditableProps} from '@portabletext/editor'
|
|
7
|
-
import {PropsWithChildren} from 'react'
|
|
8
|
-
import type {RangeDecoration} from '@portabletext/editor'
|
|
9
|
-
import {ReactElement} from 'react'
|
|
10
|
-
import {usePresenceForDocument} from '@sanity/sdk-react'
|
|
11
|
-
|
|
1
|
+
import { DocumentHandle, usePresenceForDocument } from "@sanity/sdk-react";
|
|
2
|
+
import { PropsWithChildren, ReactElement } from "react";
|
|
3
|
+
import { EditorSelection, Patch, PortableTextBlock, PortableTextEditableProps, RangeDecoration } from "@portabletext/editor";
|
|
4
|
+
import "@portabletext/patches";
|
|
5
|
+
import "@sanity/diff-patch";
|
|
12
6
|
/**
|
|
13
7
|
* `@sanity/sdk-react` exports the presence hooks and their option types but not
|
|
14
8
|
* the presence data types, so these are derived from what it does export.
|
|
15
9
|
*/
|
|
16
|
-
|
|
17
|
-
typeof usePresenceForDocument
|
|
18
|
-
>['presence'][number]
|
|
19
|
-
|
|
10
|
+
type DocumentPresence = ReturnType<typeof usePresenceForDocument>['presence'][number];
|
|
20
11
|
/**
|
|
21
12
|
* Draws one remote participant's caret. This package has no opinion about how a
|
|
22
13
|
* caret looks, so it is the caller's to provide.
|
|
23
14
|
*
|
|
24
15
|
* @public
|
|
25
16
|
*/
|
|
26
|
-
|
|
27
|
-
cursor: SDKRemoteCursor,
|
|
28
|
-
) => (props: PropsWithChildren) => ReactElement
|
|
29
|
-
|
|
17
|
+
type RenderCursorFunction = (cursor: SDKRemoteCursor) => (props: PropsWithChildren) => ReactElement;
|
|
30
18
|
/**
|
|
31
|
-
* A
|
|
32
|
-
* both ways, the local user's caret is reported, and other people's carets are
|
|
33
|
-
* drawn.
|
|
34
|
-
*
|
|
35
|
-
* Place it inside `EditorProvider` in place of `PortableTextEditable`. Every
|
|
36
|
-
* other prop is forwarded untouched, and `rangeDecorations` you pass are kept
|
|
37
|
-
* and merged with the presence carets rather than replaced.
|
|
38
|
-
*
|
|
39
|
-
* Nothing else is needed: this replaces a separate `SDKValuePlugin`.
|
|
40
|
-
*
|
|
41
|
-
* @example
|
|
42
|
-
* ```tsx
|
|
43
|
-
* <EditorProvider initialConfig={{schemaDefinition}}>
|
|
44
|
-
* <SDKPortableTextEditable
|
|
45
|
-
* {...documentHandle}
|
|
46
|
-
* path="content"
|
|
47
|
-
* renderCursor={({user}) => (props) => (
|
|
48
|
-
* <Caret user={user}>{props.children}</Caret>
|
|
49
|
-
* )}
|
|
50
|
-
* />
|
|
51
|
-
* </EditorProvider>
|
|
52
|
-
* ```
|
|
19
|
+
* A remote participant's caret, together with who they are.
|
|
53
20
|
*
|
|
54
|
-
*
|
|
55
|
-
|
|
56
|
-
export declare function SDKPortableTextEditable(
|
|
57
|
-
props: SDKPortableTextEditableProps,
|
|
58
|
-
): JSX.Element
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Props for {@link SDKPortableTextEditable}.
|
|
21
|
+
* Declared in full rather than extending the internal cursor type, so nothing in
|
|
22
|
+
* the public API refers to a type consumers cannot import.
|
|
62
23
|
*
|
|
63
24
|
* @public
|
|
64
25
|
*/
|
|
65
|
-
|
|
66
|
-
extends
|
|
67
|
-
DocumentHandle,
|
|
68
|
-
Omit<PortableTextEditableProps, keyof DocumentHandle> {
|
|
26
|
+
interface SDKRemoteCursor {
|
|
69
27
|
/**
|
|
70
|
-
*
|
|
28
|
+
* Identifies one editing session rather than one person. The same user in two
|
|
29
|
+
* tabs reports two sessions and therefore draws two carets.
|
|
71
30
|
*/
|
|
72
|
-
|
|
31
|
+
sessionId: string;
|
|
73
32
|
/**
|
|
74
|
-
*
|
|
75
|
-
* needs no styling of your own. Pass `null` to draw no carets at all while
|
|
76
|
-
* still reporting the local user's presence.
|
|
33
|
+
* Where the participant last reported their selection.
|
|
77
34
|
*/
|
|
78
|
-
|
|
35
|
+
selection: EditorSelection;
|
|
36
|
+
user: DocumentPresence['user'];
|
|
79
37
|
}
|
|
80
|
-
|
|
81
|
-
/**
|
|
82
|
-
* Reports the local user's caret in a Portable Text field, so other people in
|
|
83
|
-
* the same document can see where they are.
|
|
84
|
-
*
|
|
85
|
-
* Place it inside `EditorProvider`. Prefer `SDKPortableTextEditable`, which
|
|
86
|
-
* reports and draws in one component; reach for this when you render
|
|
87
|
-
* `PortableTextEditable` yourself.
|
|
88
|
-
*
|
|
89
|
-
* Which document is reported follows the handle's perspective, or the ambient
|
|
90
|
-
* one from `ResourceProvider`. Pass the plain document id and let the
|
|
91
|
-
* perspective select the draft, the published document, or a release version.
|
|
92
|
-
*
|
|
93
|
-
* @public
|
|
94
|
-
*/
|
|
95
|
-
export declare function SDKPresencePlugin(props: SDKPresencePluginProps): null
|
|
96
|
-
|
|
97
38
|
/**
|
|
98
39
|
* Props for {@link SDKPresencePlugin}.
|
|
99
40
|
*
|
|
100
41
|
* @public
|
|
101
42
|
*/
|
|
102
|
-
|
|
43
|
+
interface SDKPresencePluginProps extends DocumentHandle {
|
|
103
44
|
/**
|
|
104
45
|
* The document path of the Portable Text field, for example `content`. The
|
|
105
46
|
* same form `SDKValuePlugin` takes.
|
|
106
47
|
*/
|
|
107
|
-
path: string
|
|
48
|
+
path: string;
|
|
108
49
|
}
|
|
109
|
-
|
|
110
50
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
113
|
-
* Declared in full rather than extending the internal cursor type, so nothing in
|
|
114
|
-
* the public API refers to a type consumers cannot import.
|
|
51
|
+
* Options for {@link useSDKPresenceCursors}.
|
|
115
52
|
*
|
|
116
53
|
* @public
|
|
117
54
|
*/
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
* tabs reports two sessions and therefore draws two carets.
|
|
122
|
-
*/
|
|
123
|
-
sessionId: string
|
|
124
|
-
/**
|
|
125
|
-
* Where the participant last reported their selection.
|
|
126
|
-
*/
|
|
127
|
-
selection: EditorSelection
|
|
128
|
-
user: DocumentPresence['user']
|
|
55
|
+
interface UseSDKPresenceCursorsOptions extends DocumentHandle {
|
|
56
|
+
path: string;
|
|
57
|
+
renderCursor: RenderCursorFunction;
|
|
129
58
|
}
|
|
130
|
-
|
|
131
59
|
/**
|
|
60
|
+
* Reports the local user's caret in a Portable Text field, so other people in
|
|
61
|
+
* the same document can see where they are.
|
|
62
|
+
*
|
|
63
|
+
* Place it inside `EditorProvider`. Prefer `SDKPortableTextEditable`, which
|
|
64
|
+
* reports and draws in one component; reach for this when you render
|
|
65
|
+
* `PortableTextEditable` yourself.
|
|
66
|
+
*
|
|
67
|
+
* Which document is reported follows the handle's perspective, or the ambient
|
|
68
|
+
* one from `ResourceProvider`. Pass the plain document id and let the
|
|
69
|
+
* perspective select the draft, the published document, or a release version.
|
|
70
|
+
*
|
|
132
71
|
* @public
|
|
133
72
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
declare interface SDKValuePluginProps extends DocumentHandle {
|
|
137
|
-
path: string
|
|
138
|
-
}
|
|
139
|
-
|
|
73
|
+
declare function SDKPresencePlugin(props: SDKPresencePluginProps): null;
|
|
140
74
|
/**
|
|
141
75
|
* Other people's carets in a Portable Text field, as range decorations.
|
|
142
76
|
*
|
|
@@ -151,27 +85,21 @@ declare interface SDKValuePluginProps extends DocumentHandle {
|
|
|
151
85
|
*
|
|
152
86
|
* @public
|
|
153
87
|
*/
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
88
|
+
declare function useSDKPresenceCursors(options: UseSDKPresenceCursorsOptions): RangeDecoration[];
|
|
89
|
+
interface SDKValuePluginProps extends DocumentHandle {
|
|
90
|
+
path: string;
|
|
91
|
+
}
|
|
158
92
|
/**
|
|
159
|
-
* Options for {@link useSDKPresenceCursors}.
|
|
160
|
-
*
|
|
161
93
|
* @public
|
|
162
94
|
*/
|
|
163
|
-
|
|
164
|
-
path: string
|
|
165
|
-
renderCursor: RenderCursorFunction
|
|
166
|
-
}
|
|
167
|
-
|
|
95
|
+
declare function SDKValuePlugin(props: SDKValuePluginProps): import("react").JSX.Element;
|
|
168
96
|
/**
|
|
169
97
|
* @internal
|
|
170
98
|
*/
|
|
171
|
-
|
|
172
|
-
getRemoteValue: () => PortableTextBlock[] | null | undefined
|
|
173
|
-
pushValue: (value: PortableTextBlock[]) => void
|
|
174
|
-
onRemoteValueChange: (callback: () => void) => () => void
|
|
99
|
+
type ValueSyncConfig = {
|
|
100
|
+
getRemoteValue: () => PortableTextBlock[] | null | undefined;
|
|
101
|
+
pushValue: (value: PortableTextBlock[]) => void;
|
|
102
|
+
onRemoteValueChange: (callback: () => void) => () => void;
|
|
175
103
|
/**
|
|
176
104
|
* Optional patch channel. When provided, operational patches from other
|
|
177
105
|
* clients are applied directly to the editor (in every state) instead of
|
|
@@ -179,17 +107,14 @@ declare type ValueSyncConfig = {
|
|
|
179
107
|
* through `pushPatches`. The whole-value sync remains as a fallback for
|
|
180
108
|
* anything the patch channel cannot express.
|
|
181
109
|
*/
|
|
182
|
-
onRemotePatches?: (
|
|
183
|
-
callback: (patches: Patch[]) => void,
|
|
184
|
-
) => (() => void) | undefined
|
|
110
|
+
onRemotePatches?: (callback: (patches: Patch[]) => void) => (() => void) | undefined;
|
|
185
111
|
/**
|
|
186
112
|
* Pushes the editor's own operational patches to the remote store. May
|
|
187
113
|
* throw when a patch cannot be converted, in which case the plugin falls
|
|
188
114
|
* back to pushing the whole value.
|
|
189
115
|
*/
|
|
190
|
-
pushPatches?: (patches: Patch[]) => void
|
|
191
|
-
}
|
|
192
|
-
|
|
116
|
+
pushPatches?: (patches: Patch[]) => void;
|
|
117
|
+
};
|
|
193
118
|
/**
|
|
194
119
|
* NOTE: You are probably looking for SDKValuePlugin instead of this.
|
|
195
120
|
* This is a lower-level plugin that only handles syncing the value
|
|
@@ -200,6 +125,50 @@ declare type ValueSyncConfig = {
|
|
|
200
125
|
*
|
|
201
126
|
* @internal
|
|
202
127
|
*/
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
128
|
+
declare function ValueSyncPlugin(props: ValueSyncConfig): null;
|
|
129
|
+
/**
|
|
130
|
+
* Props for {@link SDKPortableTextEditable}.
|
|
131
|
+
*
|
|
132
|
+
* @public
|
|
133
|
+
*/
|
|
134
|
+
interface SDKPortableTextEditableProps extends DocumentHandle, Omit<PortableTextEditableProps, keyof DocumentHandle> {
|
|
135
|
+
/**
|
|
136
|
+
* The document path of the Portable Text field, for example `content`.
|
|
137
|
+
*/
|
|
138
|
+
path: string;
|
|
139
|
+
/**
|
|
140
|
+
* Draws one remote participant's caret. Omit it for the built-in caret, which
|
|
141
|
+
* needs no styling of your own. Pass `null` to draw no carets at all while
|
|
142
|
+
* still reporting the local user's presence.
|
|
143
|
+
*/
|
|
144
|
+
renderCursor?: RenderCursorFunction | null;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* A `PortableTextEditable` wired to a Sanity document: the field's value syncs
|
|
148
|
+
* both ways, the local user's caret is reported, and other people's carets are
|
|
149
|
+
* drawn.
|
|
150
|
+
*
|
|
151
|
+
* Place it inside `EditorProvider` in place of `PortableTextEditable`. Every
|
|
152
|
+
* other prop is forwarded untouched, and `rangeDecorations` you pass are kept
|
|
153
|
+
* and merged with the presence carets rather than replaced.
|
|
154
|
+
*
|
|
155
|
+
* Nothing else is needed: this replaces a separate `SDKValuePlugin`.
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```tsx
|
|
159
|
+
* <EditorProvider initialConfig={{schemaDefinition}}>
|
|
160
|
+
* <SDKPortableTextEditable
|
|
161
|
+
* {...documentHandle}
|
|
162
|
+
* path="content"
|
|
163
|
+
* renderCursor={({user}) => (props) => (
|
|
164
|
+
* <Caret user={user}>{props.children}</Caret>
|
|
165
|
+
* )}
|
|
166
|
+
* />
|
|
167
|
+
* </EditorProvider>
|
|
168
|
+
* ```
|
|
169
|
+
*
|
|
170
|
+
* @public
|
|
171
|
+
*/
|
|
172
|
+
declare function SDKPortableTextEditable(props: SDKPortableTextEditableProps): import("react").JSX.Element;
|
|
173
|
+
export { type RenderCursorFunction, SDKPortableTextEditable, type SDKPortableTextEditableProps, SDKPresencePlugin, type SDKPresencePluginProps, type SDKRemoteCursor, SDKValuePlugin, type UseSDKPresenceCursorsOptions, ValueSyncPlugin, useSDKPresenceCursors };
|
|
174
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../src/plugin.sdk-presence.tsx","../src/plugin.sdk-value.tsx","../src/sdk-editable.tsx"],"mappings":";;;;;;;;;KAeK,mBAAmB,kBACf;;;;;;;KASG,wBACV,QAAQ,qBACJ,OAAO,sBAAsB;;;;;;;;;UAUlB;;;;;EAKf;;;;EAIA,WAAW;EACX,MAAM;;;;;;;UAQS,+BAA+B;;;;;EAK9C;;;;;;;UAQe,qCAAqC;EACpD;EACA,cAAc;;;;;;;;;;;;;;;;iBAiBA,kBAAkB,OAAO;;;;;;;;;;;;;;;iBAwBzB,sBACd,SAAS,+BACR;UC48BO,4BAA4B;EACpC;;;;;iBAqCc,eAAe,OAAO,sCAAmB,IAAA;;;;KAiFpD;EACH,sBAAsB;EACtB,YAAY,OAAO;EACnB,sBAAsB;;;;;;;;EAQtB,mBACE,WAAW,SAAS;;;;;;EAOtB,eAAe,SAAS;;;;;;;;;;;;iBAaV,gBAAgB,OAAO;;;;;;UChsCtB,qCAEb,gBAGA,KAAK,iCAAiC;;;;EAIxC;;;;;;EAMA,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA6CD,wBAAwB,OAAO,+CAA4B,IAAA"}
|