@sanity/sdk 2.17.0 → 2.19.0
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/_chunks-dts/createGroqSearchFilter.d.ts +8 -11
- package/dist/_chunks-dts/createGroqSearchFilter.d.ts.map +1 -1
- package/dist/_chunks-es/_internal.js +1 -0
- package/dist/_chunks-es/_internal.js.map +1 -1
- package/dist/_chunks-es/createGroqSearchFilter.js +8 -4
- package/dist/_chunks-es/createGroqSearchFilter.js.map +1 -1
- package/dist/_chunks-es/telemetryManager.js +2 -2
- package/dist/_exports/_internal.d.ts.map +1 -1
- package/dist/index.d.ts +197 -13
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +492 -123
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/_exports/index.ts +7 -1
- package/src/document/documentStore.concurrency.test.ts +1306 -0
- package/src/document/documentStore.test.ts +11 -0
- package/src/document/documentStore.ts +0 -1
- package/src/document/listen.test.ts +56 -0
- package/src/document/listen.ts +65 -20
- package/src/document/listenerEventOperators.test.ts +311 -0
- package/src/document/listenerEventOperators.ts +217 -0
- package/src/document/patchOperations.test.ts +49 -2
- package/src/document/patchOperations.ts +50 -0
- package/src/document/processActions/edit.ts +9 -2
- package/src/document/processActions/shared.ts +111 -1
- package/src/document/processActions.test.ts +185 -1
- package/src/document/reducers.test.ts +123 -0
- package/src/document/reducers.ts +37 -2
- package/src/document/sharedListener.test.ts +2 -1
- package/src/document/sharedListener.ts +12 -1
- package/src/document/util.test.ts +46 -0
- package/src/document/util.ts +37 -1
- package/src/presence/bifurTransport.test.ts +155 -3
- package/src/presence/bifurTransport.ts +79 -12
- package/src/presence/paths.test.ts +70 -0
- package/src/presence/paths.ts +41 -0
- package/src/presence/presenceStore.test.ts +822 -2
- package/src/presence/presenceStore.ts +518 -102
- package/src/presence/types.ts +175 -3
- package/dist/_chunks-es/version.js +0 -7
- package/dist/_chunks-es/version.js.map +0 -1
package/src/presence/types.ts
CHANGED
|
@@ -1,27 +1,199 @@
|
|
|
1
1
|
import {type SanityClient} from '@sanity/client'
|
|
2
|
+
import {type Path} from '@sanity/types'
|
|
2
3
|
import {type Observable} from 'rxjs'
|
|
3
4
|
|
|
5
|
+
import {type PerspectiveHandle} from '../config/sanityConfig'
|
|
4
6
|
import {type SanityUser} from '../users/types'
|
|
5
7
|
|
|
6
|
-
/**
|
|
8
|
+
/**
|
|
9
|
+
* One end of a text selection: a Portable Text path plus a character offset
|
|
10
|
+
* within the span it addresses.
|
|
11
|
+
* @public
|
|
12
|
+
*/
|
|
13
|
+
export interface PresenceSelectionPoint {
|
|
14
|
+
path: Path
|
|
15
|
+
offset: number
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A Portable Text caret or selected range, as exchanged with the Studio.
|
|
20
|
+
*
|
|
21
|
+
* Structurally identical to `EditorSelection` from `@portabletext/editor`, and
|
|
22
|
+
* declared separately so that `@sanity/sdk` stays free of React dependencies. A
|
|
23
|
+
* value from the editor can be passed straight through, and vice versa.
|
|
24
|
+
*
|
|
25
|
+
* `offset` is a character offset within the span that `path` addresses.
|
|
26
|
+
* @public
|
|
27
|
+
*/
|
|
28
|
+
export type PresenceSelection = {
|
|
29
|
+
anchor: PresenceSelectionPoint
|
|
30
|
+
focus: PresenceSelectionPoint
|
|
31
|
+
backward?: boolean
|
|
32
|
+
} | null
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Somewhere a participant is, as it arrives over the wire.
|
|
36
|
+
*
|
|
37
|
+
* Prefer {@link DocumentPresence} from `getDocumentPresence`, which is scoped to one
|
|
38
|
+
* document, flattened for rendering, and types `path` accurately.
|
|
39
|
+
* @public
|
|
40
|
+
*/
|
|
7
41
|
export interface PresenceLocation {
|
|
8
42
|
type: 'document'
|
|
43
|
+
/**
|
|
44
|
+
* The specific document the participant is in, so a draft, published, or version
|
|
45
|
+
* id rather than a bare document id.
|
|
46
|
+
*/
|
|
9
47
|
documentId: string
|
|
48
|
+
/**
|
|
49
|
+
* The focused field path, empty when they are in the document but not a field.
|
|
50
|
+
*
|
|
51
|
+
* Declared as `string[]`, but segments can also be numbers or `{_key: string}`
|
|
52
|
+
* objects when the focus is inside an array or a Portable Text field, because
|
|
53
|
+
* that is what other clients send. Guard for those rather than assuming strings.
|
|
54
|
+
* Widening the declared type is a breaking change, so it waits for the next major;
|
|
55
|
+
* {@link DocumentPresence.path} is typed correctly today.
|
|
56
|
+
*/
|
|
10
57
|
path: string[]
|
|
58
|
+
/**
|
|
59
|
+
* When the participant said they were last active, on *their* clock.
|
|
60
|
+
*
|
|
61
|
+
* Fine for display, unreliable for deciding whether someone is still here: it is
|
|
62
|
+
* subject to clock skew between machines. Presence already drops participants that
|
|
63
|
+
* stop announcing, so a session appearing here is one the SDK still considers
|
|
64
|
+
* live.
|
|
65
|
+
*/
|
|
11
66
|
lastActiveAt: string
|
|
67
|
+
/** A Portable Text caret, when the focused field is a Portable Text field. */
|
|
68
|
+
selection?: PresenceSelection
|
|
12
69
|
}
|
|
13
70
|
|
|
14
|
-
/**
|
|
71
|
+
/**
|
|
72
|
+
* A location as it travels over the wire. Identical in shape to
|
|
73
|
+
* {@link PresenceLocation}, except `path` is a full `Path`, which is what is
|
|
74
|
+
* really exchanged. See the note on {@link PresenceLocation.path}.
|
|
75
|
+
*
|
|
76
|
+
* Internal: nothing in the public API accepts or returns this. Apps describe
|
|
77
|
+
* where they are with {@link ReportPresenceOptions} and read presence as
|
|
78
|
+
* {@link PresenceLocation}.
|
|
79
|
+
* @internal
|
|
80
|
+
*/
|
|
81
|
+
export interface WirePresenceLocation extends Omit<PresenceLocation, 'path'> {
|
|
82
|
+
path: Path
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Which specific document a presence id resolves to.
|
|
87
|
+
*
|
|
88
|
+
* Presence compares exact document ids, so a client in a draft and a client in the
|
|
89
|
+
* published document are in different places even for the same `documentId`. Pass
|
|
90
|
+
* the perspective you are editing under and the SDK resolves it; the React hooks
|
|
91
|
+
* take it from `ResourceProvider` when you do not pass one.
|
|
92
|
+
* @public
|
|
93
|
+
*/
|
|
94
|
+
export interface PresencePerspectiveOptions extends PerspectiveHandle {
|
|
95
|
+
/** Live-edit documents have no draft, so presence resolves to the published id. */
|
|
96
|
+
liveEdit?: boolean
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* What an app reports about where the current user is.
|
|
101
|
+
*
|
|
102
|
+
* Omit `path` for document-level presence, or pass one for field-level presence.
|
|
103
|
+
* @public
|
|
104
|
+
*/
|
|
105
|
+
export interface ReportPresenceOptions extends PresencePerspectiveOptions {
|
|
106
|
+
/**
|
|
107
|
+
* The document the user is in.
|
|
108
|
+
*
|
|
109
|
+
* Pass the plain document id; the perspective decides which specific document that
|
|
110
|
+
* resolves to. An already-specific id is accepted and re-resolved, so passing
|
|
111
|
+
* `drafts.abc` while the perspective is `published` reports the published document.
|
|
112
|
+
*/
|
|
113
|
+
documentId: string
|
|
114
|
+
/**
|
|
115
|
+
* The focused field path. Supports keyed and numeric segments, so array items
|
|
116
|
+
* and Portable Text spans can be addressed.
|
|
117
|
+
*/
|
|
118
|
+
path?: Path
|
|
119
|
+
/** A Portable Text caret, when the focused field is a Portable Text field. */
|
|
120
|
+
selection?: PresenceSelection
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* One participant's session and everywhere it currently is.
|
|
125
|
+
*
|
|
126
|
+
* Keyed by session, not by user: the same person in two tabs is two entries with
|
|
127
|
+
* the same `user`.
|
|
128
|
+
* @public
|
|
129
|
+
*/
|
|
15
130
|
export interface UserPresence {
|
|
16
131
|
user: SanityUser
|
|
17
132
|
locations: PresenceLocation[]
|
|
133
|
+
/** Identifies one tab. Stable while that tab is open, and not reused. */
|
|
134
|
+
sessionId: string
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* One participant at one location within a single document, flattened so it can
|
|
139
|
+
* be rendered directly against a field.
|
|
140
|
+
*
|
|
141
|
+
* Unlike {@link PresenceLocation.path}, `path` here is typed as a full `Path`, so
|
|
142
|
+
* keyed and numeric segments are described rather than cast away.
|
|
143
|
+
* @beta
|
|
144
|
+
*/
|
|
145
|
+
export interface DocumentPresence {
|
|
146
|
+
user: SanityUser
|
|
147
|
+
/** Identifies one tab, so the same person in two tabs appears twice. */
|
|
18
148
|
sessionId: string
|
|
149
|
+
/**
|
|
150
|
+
* The specific document id this participant is in: a draft, published, or
|
|
151
|
+
* version id, depending on which perspective they are editing.
|
|
152
|
+
*/
|
|
153
|
+
documentId: string
|
|
154
|
+
/** The focused field path. Empty when they are in the document but no field. */
|
|
155
|
+
path: Path
|
|
156
|
+
/**
|
|
157
|
+
* When they said they were last active, on *their* clock. Fine for display,
|
|
158
|
+
* unreliable for liveness. See {@link PresenceLocation.lastActiveAt}.
|
|
159
|
+
*/
|
|
160
|
+
lastActiveAt: string
|
|
161
|
+
/** The Portable Text caret, when they are focused in a Portable Text field. */
|
|
162
|
+
selection?: PresenceSelection
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/** @beta */
|
|
166
|
+
export interface DocumentPresenceOptions extends PresencePerspectiveOptions {
|
|
167
|
+
/**
|
|
168
|
+
* The document to look at. Resolved through the perspective exactly as
|
|
169
|
+
* {@link ReportPresenceOptions.documentId} is, so reads match writes.
|
|
170
|
+
*/
|
|
171
|
+
documentId: string
|
|
172
|
+
/**
|
|
173
|
+
* Narrows to participants at or below this field path. Omit it for everyone in
|
|
174
|
+
* the document.
|
|
175
|
+
*/
|
|
176
|
+
path?: Path
|
|
177
|
+
/**
|
|
178
|
+
* By default a draft, its published version, and any release versions are
|
|
179
|
+
* treated as the same document, which is what document lists want. Set this to
|
|
180
|
+
* compare ids exactly, which is what field-level indicators want so that a
|
|
181
|
+
* draft and a release version do not bleed into each other.
|
|
182
|
+
*/
|
|
183
|
+
excludeVersions?: boolean
|
|
19
184
|
}
|
|
20
185
|
|
|
21
186
|
/** @public */
|
|
22
187
|
export type PresenceTransport = [
|
|
23
188
|
incomingEvents$: Observable<TransportEvent>,
|
|
24
189
|
dispatchMessage: (message: TransportMessage) => Observable<void>,
|
|
190
|
+
/**
|
|
191
|
+
* Emits an incrementing generation number each time the connection becomes
|
|
192
|
+
* live. Reconnects with backoff, and subscribing keeps the connection alive.
|
|
193
|
+
*/
|
|
194
|
+
connections$: Observable<number>,
|
|
195
|
+
/** Emits when the page is going away, so a disconnect can be announced. */
|
|
196
|
+
unload$: Observable<void>,
|
|
25
197
|
]
|
|
26
198
|
|
|
27
199
|
/** @public */
|
|
@@ -54,7 +226,7 @@ export interface DisconnectEvent {
|
|
|
54
226
|
/** @public */
|
|
55
227
|
export type TransportMessage =
|
|
56
228
|
| {type: 'rollCall'}
|
|
57
|
-
| {type: 'state'; locations:
|
|
229
|
+
| {type: 'state'; locations: WirePresenceLocation[]}
|
|
58
230
|
| {type: 'disconnect'}
|
|
59
231
|
|
|
60
232
|
/** @public */
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sources":["../../src/version.ts"],"sourcesContent":["import {version} from '../package.json'\nimport {getEnv} from './utils/getEnv'\n\n/**\n * This version is provided by pkg-utils at build time\n * @internal\n */\nexport const CORE_SDK_VERSION = getEnv('PKG_VERSION') || `${version}-development`\n"],"names":[],"mappings":";;AAOO,MAAM,mBAAmB,OAAO,aAAa,KAAK,GAAG,OAAO;"}
|