@portabletext/plugin-sdk-value 5.0.5-canary.0 → 5.0.6
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 +2 -1
- package/dist/index.js +195 -36
- package/dist/index.js.map +1 -1
- package/package.json +18 -3
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import {DocumentHandle} from '@sanity/sdk-react'
|
|
2
|
+
import {JSX} from 'react'
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* @public
|
|
5
6
|
*/
|
|
6
|
-
export declare function SDKValuePlugin(props: SDKValuePluginProps):
|
|
7
|
+
export declare function SDKValuePlugin(props: SDKValuePluginProps): JSX.Element
|
|
7
8
|
|
|
8
9
|
declare interface SDKValuePluginProps extends DocumentHandle {
|
|
9
10
|
path: string
|
package/dist/index.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
1
2
|
import { c } from "react/compiler-runtime";
|
|
2
3
|
import { useEditor } from "@portabletext/editor";
|
|
3
4
|
import { diffValue } from "@sanity/diff-patch";
|
|
4
5
|
import { parsePath } from "@sanity/json-match";
|
|
5
6
|
import { useEditDocument, useSanityInstance, getDocumentState } from "@sanity/sdk-react";
|
|
6
|
-
import {
|
|
7
|
+
import { useActorRef } from "@xstate/react";
|
|
8
|
+
import { fromCallback, setup } from "xstate";
|
|
7
9
|
const ARRAYIFY_ERROR_MESSAGE = "Unexpected path format from diffValue output. Please report this issue.";
|
|
8
10
|
function* getSegments(node) {
|
|
9
11
|
node.base && (yield* getSegments(node.base)), node.segment.type !== "This" && (yield node.segment);
|
|
@@ -84,44 +86,201 @@ function convertPatches(patches) {
|
|
|
84
86
|
}
|
|
85
87
|
}));
|
|
86
88
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
89
|
+
function applySync({
|
|
90
|
+
editor,
|
|
91
|
+
getRemoteValue
|
|
92
|
+
}) {
|
|
93
|
+
const remoteValue = getRemoteValue();
|
|
94
|
+
if (!remoteValue)
|
|
95
|
+
return;
|
|
96
|
+
const snapshot = editor.getSnapshot().context.value, patches = convertPatches(diffValue(snapshot, remoteValue));
|
|
97
|
+
patches.length && editor.send({
|
|
98
|
+
type: "patches",
|
|
99
|
+
patches,
|
|
100
|
+
snapshot
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
const listenToEditor = fromCallback(({
|
|
104
|
+
sendBack,
|
|
105
|
+
input
|
|
106
|
+
}) => {
|
|
107
|
+
const patchSubscription = input.editor.on("patch", () => {
|
|
108
|
+
sendBack({
|
|
109
|
+
type: "patch emitted"
|
|
110
|
+
});
|
|
111
|
+
}), mutationSubscription = input.editor.on("mutation", (event) => {
|
|
112
|
+
sendBack({
|
|
113
|
+
type: "mutation flushed",
|
|
114
|
+
value: event.value
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
return () => {
|
|
118
|
+
patchSubscription.unsubscribe(), mutationSubscription.unsubscribe();
|
|
119
|
+
};
|
|
120
|
+
}), listenToRemote = fromCallback(({
|
|
121
|
+
sendBack,
|
|
122
|
+
input
|
|
123
|
+
}) => input.onRemoteValueChange(() => {
|
|
124
|
+
sendBack({
|
|
125
|
+
type: "remote value changed"
|
|
126
|
+
});
|
|
127
|
+
})), valueSyncMachine = setup({
|
|
128
|
+
types: {
|
|
129
|
+
context: {},
|
|
130
|
+
input: {},
|
|
131
|
+
events: {}
|
|
132
|
+
},
|
|
133
|
+
actions: {
|
|
134
|
+
"send initial value": ({
|
|
135
|
+
context
|
|
136
|
+
}) => {
|
|
137
|
+
context.editor.send({
|
|
138
|
+
type: "update value",
|
|
139
|
+
value: context.getRemoteValue() ?? []
|
|
140
|
+
});
|
|
141
|
+
},
|
|
142
|
+
"push to remote": () => {
|
|
143
|
+
throw new Error("push to remote must be provided via .provide()");
|
|
144
|
+
},
|
|
145
|
+
"apply sync": ({
|
|
146
|
+
context
|
|
147
|
+
}) => {
|
|
148
|
+
applySync({
|
|
149
|
+
editor: context.editor,
|
|
150
|
+
getRemoteValue: context.getRemoteValue
|
|
151
|
+
});
|
|
152
|
+
},
|
|
153
|
+
"defer then apply sync": ({
|
|
154
|
+
context
|
|
155
|
+
}) => {
|
|
156
|
+
queueMicrotask(() => {
|
|
157
|
+
applySync({
|
|
158
|
+
editor: context.editor,
|
|
159
|
+
getRemoteValue: context.getRemoteValue
|
|
160
|
+
});
|
|
102
161
|
});
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
actors: {
|
|
165
|
+
"listen to editor": listenToEditor,
|
|
166
|
+
"listen to remote": listenToRemote
|
|
167
|
+
}
|
|
168
|
+
}).createMachine({
|
|
169
|
+
id: "value sync",
|
|
170
|
+
context: ({
|
|
171
|
+
input
|
|
172
|
+
}) => ({
|
|
173
|
+
editor: input.editor,
|
|
174
|
+
getRemoteValue: input.getRemoteValue,
|
|
175
|
+
onRemoteValueChange: input.onRemoteValueChange
|
|
176
|
+
}),
|
|
177
|
+
entry: ["send initial value"],
|
|
178
|
+
invoke: [{
|
|
179
|
+
src: "listen to editor",
|
|
180
|
+
input: ({
|
|
181
|
+
context
|
|
182
|
+
}) => ({
|
|
183
|
+
editor: context.editor
|
|
184
|
+
})
|
|
185
|
+
}, {
|
|
186
|
+
src: "listen to remote",
|
|
187
|
+
input: ({
|
|
188
|
+
context
|
|
189
|
+
}) => ({
|
|
190
|
+
onRemoteValueChange: context.onRemoteValueChange
|
|
191
|
+
})
|
|
192
|
+
}],
|
|
193
|
+
initial: "idle",
|
|
194
|
+
states: {
|
|
195
|
+
idle: {
|
|
196
|
+
on: {
|
|
197
|
+
"patch emitted": {
|
|
198
|
+
target: "local write"
|
|
199
|
+
},
|
|
200
|
+
"remote value changed": {
|
|
201
|
+
actions: ["apply sync"]
|
|
114
202
|
}
|
|
115
|
-
applySync();
|
|
116
203
|
}
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
204
|
+
},
|
|
205
|
+
"local write": {
|
|
206
|
+
on: {
|
|
207
|
+
"patch emitted": {},
|
|
208
|
+
"mutation flushed": {
|
|
209
|
+
target: "pushing to remote",
|
|
210
|
+
actions: ["push to remote"]
|
|
211
|
+
},
|
|
212
|
+
"remote value changed": {
|
|
213
|
+
target: "pending sync"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
},
|
|
217
|
+
"pushing to remote": {
|
|
218
|
+
on: {
|
|
219
|
+
"patch emitted": {
|
|
220
|
+
target: "local write"
|
|
221
|
+
},
|
|
222
|
+
"remote value changed": {
|
|
223
|
+
target: "idle"
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
"pending sync": {
|
|
228
|
+
on: {
|
|
229
|
+
"patch emitted": {},
|
|
230
|
+
"mutation flushed": {
|
|
231
|
+
target: "pushing to remote",
|
|
232
|
+
actions: ["push to remote", "defer then apply sync"]
|
|
233
|
+
},
|
|
234
|
+
"remote value changed": {}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
function SDKValuePlugin(props) {
|
|
240
|
+
const $ = c(9), {
|
|
241
|
+
documentId,
|
|
242
|
+
documentType,
|
|
243
|
+
path
|
|
244
|
+
} = props, setSdkValue = useEditDocument(props), instance = useSanityInstance(props);
|
|
245
|
+
let t0;
|
|
246
|
+
$[0] !== documentId || $[1] !== documentType || $[2] !== instance || $[3] !== path ? (t0 = getDocumentState(instance, {
|
|
247
|
+
documentId,
|
|
248
|
+
documentType,
|
|
249
|
+
path
|
|
250
|
+
}), $[0] = documentId, $[1] = documentType, $[2] = instance, $[3] = path, $[4] = t0) : t0 = $[4];
|
|
251
|
+
const {
|
|
252
|
+
getCurrent,
|
|
253
|
+
subscribe
|
|
254
|
+
} = t0;
|
|
255
|
+
let t1;
|
|
256
|
+
return $[5] !== getCurrent || $[6] !== setSdkValue || $[7] !== subscribe ? (t1 = /* @__PURE__ */ jsx(ValueSyncPlugin, { getRemoteValue: getCurrent, pushValue: setSdkValue, onRemoteValueChange: subscribe }), $[5] = getCurrent, $[6] = setSdkValue, $[7] = subscribe, $[8] = t1) : t1 = $[8], t1;
|
|
257
|
+
}
|
|
258
|
+
function ValueSyncPlugin(props) {
|
|
259
|
+
const $ = c(6), {
|
|
260
|
+
getRemoteValue,
|
|
261
|
+
pushValue,
|
|
262
|
+
onRemoteValueChange
|
|
263
|
+
} = props, editor = useEditor();
|
|
264
|
+
let t0;
|
|
265
|
+
$[0] !== pushValue ? (t0 = valueSyncMachine.provide({
|
|
266
|
+
actions: {
|
|
267
|
+
"push to remote": (t12) => {
|
|
268
|
+
const {
|
|
269
|
+
context,
|
|
270
|
+
event
|
|
271
|
+
} = t12;
|
|
272
|
+
event.type === "mutation flushed" && pushValue(event.value ?? context.editor.getSnapshot().context.value);
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
}), $[0] = pushValue, $[1] = t0) : t0 = $[1];
|
|
276
|
+
let t1;
|
|
277
|
+
return $[2] !== editor || $[3] !== getRemoteValue || $[4] !== onRemoteValueChange ? (t1 = {
|
|
278
|
+
input: {
|
|
279
|
+
editor,
|
|
280
|
+
getRemoteValue,
|
|
281
|
+
onRemoteValueChange
|
|
282
|
+
}
|
|
283
|
+
}, $[2] = editor, $[3] = getRemoteValue, $[4] = onRemoteValueChange, $[5] = t1) : t1 = $[5], useActorRef(t0, t1), null;
|
|
125
284
|
}
|
|
126
285
|
export {
|
|
127
286
|
SDKValuePlugin
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/plugin.sdk-value.tsx"],"sourcesContent":["import {\n useEditor,\n type PortableTextBlock,\n type Patch as PtePatch,\n} from '@portabletext/editor'\nimport type {\n JSONValue,\n Path,\n PathSegment,\n InsertPatch as PteInsertPatch,\n} from '@portabletext/patches'\nimport {diffValue, type SanityPatchOperations} from '@sanity/diff-patch'\nimport {\n parsePath,\n type ExprNode,\n type PathNode,\n type SegmentNode,\n type ThisNode,\n} from '@sanity/json-match'\nimport {\n getDocumentState,\n useEditDocument,\n useSanityInstance,\n type DocumentHandle,\n} from '@sanity/sdk-react'\nimport {useEffect} from 'react'\n\ninterface SDKValuePluginProps extends DocumentHandle {\n path: string\n}\n\ntype InsertPatch = Required<Pick<SanityPatchOperations, 'insert'>>\n\nconst ARRAYIFY_ERROR_MESSAGE =\n 'Unexpected path format from diffValue output. Please report this issue.'\n\nfunction* getSegments(\n node: PathNode,\n): Generator<Exclude<SegmentNode, ThisNode>> {\n if (node.base) {\n yield* getSegments(node.base)\n }\n if (node.segment.type !== 'This') {\n yield node.segment\n }\n}\n\nfunction isKeyPath(node: ExprNode): node is PathNode {\n if (node.type !== 'Path') {\n return false\n }\n if (node.base) {\n return false\n }\n if (node.recursive) {\n return false\n }\n if (node.segment.type !== 'Identifier') {\n return false\n }\n return node.segment.name === '_key'\n}\n\nexport function arrayifyPath(pathExpr: string): Path {\n const node = parsePath(pathExpr)\n if (!node) {\n return []\n }\n if (node.type !== 'Path') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n\n return Array.from(getSegments(node)).map((segment): PathSegment => {\n if (segment.type === 'Identifier') {\n return segment.name\n }\n if (segment.type !== 'Subscript') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n if (segment.elements.length !== 1) {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n\n const [element] = segment.elements\n if (element.type === 'Number') {\n return element.value\n }\n\n if (element.type !== 'Comparison') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n if (element.operator !== '==') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n return {_key: other.value}\n })\n}\n\nexport function convertPatches(patches: SanityPatchOperations[]): PtePatch[] {\n return patches.flatMap((p) => {\n return Object.entries(p).flatMap(([type, values]): PtePatch[] => {\n const origin = 'remote'\n\n switch (type) {\n case 'set':\n case 'setIfMissing':\n case 'diffMatchPatch':\n case 'inc':\n case 'dec': {\n return Object.entries(values).map(\n ([pathExpr, value]) =>\n ({type, value, origin, path: arrayifyPath(pathExpr)}) as PtePatch,\n )\n }\n case 'unset': {\n if (!Array.isArray(values)) {\n return []\n }\n return values.map(arrayifyPath).map((path) => ({type, origin, path}))\n }\n case 'insert': {\n const {items, ...rest} = values as InsertPatch['insert']\n type InsertPosition = PteInsertPatch['position']\n const position = Object.keys(rest).at(0) as InsertPosition | undefined\n\n if (!position) {\n return []\n }\n const pathExpr = (rest as {[K in InsertPosition]: string})[position]\n const insertPatch: PteInsertPatch = {\n type,\n origin,\n position,\n path: arrayifyPath(pathExpr),\n items: items as JSONValue[],\n }\n\n return [insertPatch]\n }\n\n default: {\n return []\n }\n }\n })\n })\n}\n/**\n * @public\n */\nexport function SDKValuePlugin(props: SDKValuePluginProps) {\n // NOTE: the real `useEditDocument` suspends until the document is loaded into the SDK store\n const setSdkValue = useEditDocument(props)\n const instance = useSanityInstance(props)\n const editor = useEditor()\n\n useEffect(() => {\n const getEditorValue = () => editor.getSnapshot().context.value\n const {getCurrent: getSdkValue, subscribe: onSdkValueChange} =\n getDocumentState<PortableTextBlock[]>(instance, props)\n\n let isLocalWrite = false\n let hasPendingWrites = false\n let pendingSync = false\n\n function applySync() {\n const snapshot = getEditorValue()\n const patches = convertPatches(diffValue(snapshot, getSdkValue()))\n\n if (patches.length) {\n editor.send({type: 'patches', patches, snapshot})\n }\n }\n\n const patchSubscription = editor.on('patch', () => {\n hasPendingWrites = true\n })\n\n const mutationSubscription = editor.on('mutation', (event) => {\n isLocalWrite = true\n setSdkValue(event.value ?? getEditorValue())\n isLocalWrite = false\n hasPendingWrites = false\n\n if (pendingSync) {\n pendingSync = false\n queueMicrotask(applySync)\n }\n })\n\n const unsubscribeToEditorChanges = () => {\n patchSubscription.unsubscribe()\n mutationSubscription.unsubscribe()\n }\n\n const unsubscribeToSdkChanges = onSdkValueChange(() => {\n if (isLocalWrite) {\n return\n }\n\n if (hasPendingWrites) {\n pendingSync = true\n return\n }\n\n applySync()\n })\n\n // update initial value\n editor.send({type: 'update value', value: getSdkValue() ?? []})\n\n return () => {\n unsubscribeToEditorChanges()\n unsubscribeToSdkChanges()\n }\n }, [editor, instance, props, setSdkValue])\n\n return null\n}\n"],"names":["ARRAYIFY_ERROR_MESSAGE","getSegments","node","base","segment","type","isKeyPath","recursive","name","arrayifyPath","pathExpr","parsePath","Error","Array","from","map","elements","length","element","value","operator","keyPathNode","left","right","find","other","_key","convertPatches","patches","flatMap","p","Object","entries","values","origin","path","isArray","items","rest","position","keys","at","SDKValuePlugin","props","$","_c","setSdkValue","useEditDocument","instance","useSanityInstance","editor","useEditor","t0","t1","getEditorValue","getSnapshot","context","getCurrent","getSdkValue","subscribe","onSdkValueChange","getDocumentState","isLocalWrite","hasPendingWrites","pendingSync","applySync","snapshot","diffValue","send","patchSubscription","on","mutationSubscription","event","queueMicrotask","unsubscribeToEditorChanges","unsubscribe","unsubscribeToSdkChanges","useEffect"],"mappings":";;;;;;AAiCA,MAAMA,yBACJ;AAEF,UAAUC,YACRC,MAC2C;AACvCA,OAAKC,SACP,OAAOF,YAAYC,KAAKC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,UAAUL,OAAOG,WAAW,GAACF,OAAAM,QAAAN,OAAAI,UAAAJ,OAAAD,OAAAC,OAAAE,aAAAF,OAAAQ,IAAAR,OAAAS,OAAAD,KAAAR,EAAA,CAAA,GAAAS,KAAAT,EAAA,CAAA,IA3DzCiC,UAAUzB,IA2DPC,EAAsC,GAElC;AAAI;"}
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/plugin.sdk-value.tsx"],"sourcesContent":["import {\n useEditor,\n type Editor,\n type PortableTextBlock,\n type Patch as PtePatch,\n} from '@portabletext/editor'\nimport type {\n JSONValue,\n Path,\n PathSegment,\n InsertPatch as PteInsertPatch,\n} from '@portabletext/patches'\nimport {diffValue, type SanityPatchOperations} from '@sanity/diff-patch'\nimport {\n parsePath,\n type ExprNode,\n type PathNode,\n type SegmentNode,\n type ThisNode,\n} from '@sanity/json-match'\nimport {\n getDocumentState,\n useEditDocument,\n useSanityInstance,\n type DocumentHandle,\n} from '@sanity/sdk-react'\nimport {useActorRef} from '@xstate/react'\nimport {fromCallback, setup, type AnyEventObject} from 'xstate'\n\ntype InsertPatch = Required<Pick<SanityPatchOperations, 'insert'>>\n\nconst ARRAYIFY_ERROR_MESSAGE =\n 'Unexpected path format from diffValue output. Please report this issue.'\n\nfunction* getSegments(\n node: PathNode,\n): Generator<Exclude<SegmentNode, ThisNode>> {\n if (node.base) {\n yield* getSegments(node.base)\n }\n if (node.segment.type !== 'This') {\n yield node.segment\n }\n}\n\nfunction isKeyPath(node: ExprNode): node is PathNode {\n if (node.type !== 'Path') {\n return false\n }\n if (node.base) {\n return false\n }\n if (node.recursive) {\n return false\n }\n if (node.segment.type !== 'Identifier') {\n return false\n }\n return node.segment.name === '_key'\n}\n\nexport function arrayifyPath(pathExpr: string): Path {\n const node = parsePath(pathExpr)\n if (!node) {\n return []\n }\n if (node.type !== 'Path') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n\n return Array.from(getSegments(node)).map((segment): PathSegment => {\n if (segment.type === 'Identifier') {\n return segment.name\n }\n if (segment.type !== 'Subscript') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n if (segment.elements.length !== 1) {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n\n const [element] = segment.elements\n if (element.type === 'Number') {\n return element.value\n }\n\n if (element.type !== 'Comparison') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n if (element.operator !== '==') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') {\n throw new Error(ARRAYIFY_ERROR_MESSAGE)\n }\n return {_key: other.value}\n })\n}\n\nexport function convertPatches(patches: SanityPatchOperations[]): PtePatch[] {\n return patches.flatMap((p) => {\n return Object.entries(p).flatMap(([type, values]): PtePatch[] => {\n const origin = 'remote'\n\n switch (type) {\n case 'set':\n case 'setIfMissing':\n case 'diffMatchPatch':\n case 'inc':\n case 'dec': {\n return Object.entries(values).map(\n ([pathExpr, value]) =>\n ({type, value, origin, path: arrayifyPath(pathExpr)}) as PtePatch,\n )\n }\n case 'unset': {\n if (!Array.isArray(values)) {\n return []\n }\n return values.map(arrayifyPath).map((path) => ({type, origin, path}))\n }\n case 'insert': {\n const {items, ...rest} = values as InsertPatch['insert']\n type InsertPosition = PteInsertPatch['position']\n const position = Object.keys(rest).at(0) as InsertPosition | undefined\n\n if (!position) {\n return []\n }\n const pathExpr = (rest as {[K in InsertPosition]: string})[position]\n const insertPatch: PteInsertPatch = {\n type,\n origin,\n position,\n path: arrayifyPath(pathExpr),\n items: items as JSONValue[],\n }\n\n return [insertPatch]\n }\n\n default: {\n return []\n }\n }\n })\n })\n}\n\nfunction applySync({\n editor,\n getRemoteValue,\n}: {\n editor: Editor\n getRemoteValue: () => PortableTextBlock[] | null | undefined\n}) {\n const remoteValue = getRemoteValue()\n\n if (!remoteValue) {\n return\n }\n\n const snapshot = editor.getSnapshot().context.value\n const patches = convertPatches(diffValue(snapshot, remoteValue))\n\n if (patches.length) {\n editor.send({type: 'patches', patches, snapshot})\n }\n}\n\nconst listenToEditor = fromCallback<AnyEventObject, {editor: Editor}>(\n ({sendBack, input}) => {\n const patchSubscription = input.editor.on('patch', () => {\n sendBack({type: 'patch emitted'})\n })\n\n const mutationSubscription = input.editor.on('mutation', (event) => {\n sendBack({type: 'mutation flushed', value: event.value})\n })\n\n return () => {\n patchSubscription.unsubscribe()\n mutationSubscription.unsubscribe()\n }\n },\n)\n\nconst listenToRemote = fromCallback<\n AnyEventObject,\n {onRemoteValueChange: ValueSyncConfig['onRemoteValueChange']}\n>(({sendBack, input}) => {\n return input.onRemoteValueChange(() => {\n sendBack({type: 'remote value changed'})\n })\n})\n\nconst valueSyncMachine = setup({\n types: {\n context: {} as {\n editor: Editor\n getRemoteValue: ValueSyncConfig['getRemoteValue']\n onRemoteValueChange: ValueSyncConfig['onRemoteValueChange']\n },\n input: {} as {\n editor: Editor\n getRemoteValue: ValueSyncConfig['getRemoteValue']\n onRemoteValueChange: ValueSyncConfig['onRemoteValueChange']\n },\n events: {} as\n | {type: 'patch emitted'}\n | {type: 'mutation flushed'; value: PortableTextBlock[] | undefined}\n | {type: 'remote value changed'},\n },\n actions: {\n 'send initial value': ({context}) => {\n context.editor.send({\n type: 'update value',\n value: context.getRemoteValue() ?? [],\n })\n },\n 'push to remote': () => {\n throw new Error('push to remote must be provided via .provide()')\n },\n 'apply sync': ({context}) => {\n applySync({\n editor: context.editor,\n getRemoteValue: context.getRemoteValue,\n })\n },\n 'defer then apply sync': ({context}) => {\n queueMicrotask(() => {\n applySync({\n editor: context.editor,\n getRemoteValue: context.getRemoteValue,\n })\n })\n },\n },\n actors: {\n 'listen to editor': listenToEditor,\n 'listen to remote': listenToRemote,\n },\n}).createMachine({\n id: 'value sync',\n context: ({input}) => ({\n editor: input.editor,\n getRemoteValue: input.getRemoteValue,\n onRemoteValueChange: input.onRemoteValueChange,\n }),\n entry: ['send initial value'],\n invoke: [\n {\n src: 'listen to editor',\n input: ({context}) => ({editor: context.editor}),\n },\n {\n src: 'listen to remote',\n input: ({context}) => ({\n onRemoteValueChange: context.onRemoteValueChange,\n }),\n },\n ],\n initial: 'idle',\n states: {\n 'idle': {\n on: {\n 'patch emitted': {\n target: 'local write',\n },\n 'remote value changed': {\n actions: ['apply sync'],\n },\n },\n },\n 'local write': {\n on: {\n 'patch emitted': {},\n 'mutation flushed': {\n target: 'pushing to remote',\n actions: ['push to remote'],\n },\n 'remote value changed': {\n target: 'pending sync',\n },\n },\n },\n 'pushing to remote': {\n on: {\n 'patch emitted': {\n target: 'local write',\n },\n 'remote value changed': {\n target: 'idle',\n },\n },\n },\n 'pending sync': {\n on: {\n 'patch emitted': {},\n 'mutation flushed': {\n target: 'pushing to remote',\n actions: ['push to remote', 'defer then apply sync'],\n },\n 'remote value changed': {},\n },\n },\n },\n})\n\ninterface SDKValuePluginProps extends DocumentHandle {\n path: string\n}\n\n/**\n * @public\n */\nexport function SDKValuePlugin(props: SDKValuePluginProps) {\n const {documentId, documentType, path} = props\n const setSdkValue = useEditDocument(props)\n const instance = useSanityInstance(props)\n\n const handle = {documentId, documentType, path}\n const {getCurrent, subscribe} = getDocumentState<PortableTextBlock[]>(\n instance,\n handle,\n )\n\n return (\n <ValueSyncPlugin\n getRemoteValue={getCurrent}\n pushValue={setSdkValue}\n onRemoteValueChange={subscribe}\n />\n )\n}\n\ntype ValueSyncConfig = {\n getRemoteValue: () => PortableTextBlock[] | null | undefined\n pushValue: (value: PortableTextBlock[]) => void\n onRemoteValueChange: (callback: () => void) => () => void\n}\n\nexport function ValueSyncPlugin(props: ValueSyncConfig) {\n const {getRemoteValue, pushValue, onRemoteValueChange} = props\n const editor = useEditor()\n\n useActorRef(\n valueSyncMachine.provide({\n actions: {\n 'push to remote': ({context, event}) => {\n if (event.type !== 'mutation flushed') {\n return\n }\n\n pushValue(event.value ?? context.editor.getSnapshot().context.value)\n },\n },\n }),\n {\n input: {\n editor,\n getRemoteValue,\n onRemoteValueChange,\n },\n },\n )\n\n return null\n}\n"],"names":["ARRAYIFY_ERROR_MESSAGE","getSegments","node","base","segment","type","isKeyPath","recursive","name","arrayifyPath","pathExpr","parsePath","Error","Array","from","map","elements","length","element","value","operator","keyPathNode","left","right","find","other","_key","convertPatches","patches","flatMap","p","Object","entries","values","origin","path","isArray","items","rest","position","keys","at","applySync","editor","getRemoteValue","remoteValue","snapshot","getSnapshot","context","diffValue","send","listenToEditor","fromCallback","sendBack","input","patchSubscription","on","mutationSubscription","event","unsubscribe","listenToRemote","onRemoteValueChange","valueSyncMachine","setup","types","events","actions","send initial value","push to remote","apply sync","defer then apply sync","queueMicrotask","actors","createMachine","id","entry","invoke","src","initial","states","target","SDKValuePlugin","props","$","_c","documentId","documentType","setSdkValue","useEditDocument","instance","useSanityInstance","t0","getDocumentState","getCurrent","subscribe","t1","ValueSyncPlugin","pushValue","useEditor","provide","useActorRef"],"mappings":";;;;;;;;AA+BA,MAAMA,yBACJ;AAEF,UAAUC,YACRC,MAC2C;AACvCA,OAAKC,SACP,OAAOF,YAAYC,KAAKC,IAAI,IAE1BD,KAAKE,QAAQC,SAAS,WACxB,MAAMH,KAAKE;AAEf;AAEA,SAASE,UAAUJ,MAAkC;AAUnD,SATIA,KAAKG,SAAS,UAGdH,KAAKC,QAGLD,KAAKK,aAGLL,KAAKE,QAAQC,SAAS,eACjB,KAEFH,KAAKE,QAAQI,SAAS;AAC/B;AAEO,SAASC,aAAaC,UAAwB;AACnD,QAAMR,OAAOS,UAAUD,QAAQ;AAC/B,MAAI,CAACR;AACH,WAAO,CAAA;AAET,MAAIA,KAAKG,SAAS;AAChB,UAAM,IAAIO,MAAMZ,sBAAsB;AAGxC,SAAOa,MAAMC,KAAKb,YAAYC,IAAI,CAAC,EAAEa,IAAKX,CAAAA,YAAyB;AACjE,QAAIA,QAAQC,SAAS;AACnB,aAAOD,Q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AAOI,cAAcC,QAAQ7B,KAAM;AAAA,MAAC;AAAA,IAAA;AAAA,EAExE,CACD,GAACgE,OAAAc,WAAAd,OAAAQ,MAAAA,KAAAR,EAAA,CAAA;AAAA,MAAAY;AAAA,SAAAZ,EAAA,CAAA,MAAAxC,UAAAwC,SAAAvC,kBAAAuC,EAAA,CAAA,MAAAtB,uBACFkC,KAAA;AAAA,IAAAzC,OACS;AAAA,MAAAX;AAAAA,MAAAC;AAAAA,MAAAiB;AAAAA,IAAAA;AAAAA,EAIP,GACDsB,OAAAxC,QAAAwC,OAAAvC,gBAAAuC,OAAAtB,qBAAAsB,OAAAY,MAAAA,KAAAZ,EAAA,CAAA,GAlBHiB,YACET,IAWAI,EAOF,GAEO;AAAI;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@portabletext/plugin-sdk-value",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.6",
|
|
4
4
|
"description": "Synchronizes the Portable Text Editor value with the Sanity SDK, allowing for two-way editing.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"portabletext",
|
|
@@ -35,7 +35,9 @@
|
|
|
35
35
|
],
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@sanity/diff-patch": "^6.0.0",
|
|
38
|
-
"@sanity/json-match": "^1.0.5"
|
|
38
|
+
"@sanity/json-match": "^1.0.5",
|
|
39
|
+
"@xstate/react": "^6.0.0",
|
|
40
|
+
"xstate": "^5.25.0"
|
|
39
41
|
},
|
|
40
42
|
"devDependencies": {
|
|
41
43
|
"@sanity/schema": "^5.9.0",
|
|
@@ -44,6 +46,9 @@
|
|
|
44
46
|
"@sanity/types": "^5.9.0",
|
|
45
47
|
"@types/react": "^19.2.7",
|
|
46
48
|
"@types/react-dom": "^19.2.3",
|
|
49
|
+
"@vitejs/plugin-react": "^5.1.4",
|
|
50
|
+
"@vitest/browser": "^4.0.18",
|
|
51
|
+
"@vitest/browser-playwright": "^4.0.18",
|
|
47
52
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
48
53
|
"eslint": "^9.39.1",
|
|
49
54
|
"eslint-plugin-react-hooks": "^7.0.1",
|
|
@@ -53,8 +58,11 @@
|
|
|
53
58
|
"typescript": "5.9.3",
|
|
54
59
|
"typescript-eslint": "^8.48.0",
|
|
55
60
|
"vitest": "^4.0.18",
|
|
61
|
+
"vitest-browser-react": "^2.0.5",
|
|
62
|
+
"@portabletext/editor": "^5.0.4",
|
|
56
63
|
"@portabletext/patches": "^2.0.4",
|
|
57
|
-
"@portabletext/
|
|
64
|
+
"@portabletext/schema": "^2.1.1",
|
|
65
|
+
"@portabletext/test": "^1.0.3"
|
|
58
66
|
},
|
|
59
67
|
"peerDependencies": {
|
|
60
68
|
"@sanity/sdk-react": "^2.1.2",
|
|
@@ -74,6 +82,13 @@
|
|
|
74
82
|
"clean": "del .turbo && del dist && del node_modules",
|
|
75
83
|
"dev": "pkg-utils watch",
|
|
76
84
|
"lint:fix": "biome lint --write .",
|
|
85
|
+
"test:browser": "vitest --run --project browser",
|
|
86
|
+
"test:browser:chromium": "vitest --run --project \"browser (chromium)\"",
|
|
87
|
+
"test:browser:chromium:watch": "vitest --project \"browser (chromium)\"",
|
|
88
|
+
"test:browser:firefox": "vitest --run --project \"browser (firefox)\"",
|
|
89
|
+
"test:browser:firefox:watch": "vitest --project \"browser (firefox)\"",
|
|
90
|
+
"test:browser:webkit": "vitest --run --project \"browser (webkit)\"",
|
|
91
|
+
"test:browser:webkit:watch": "vitest --project \"browser (webkit)\"",
|
|
77
92
|
"test:unit": "vitest --run --project unit",
|
|
78
93
|
"test:unit:watch": "vitest --project unit",
|
|
79
94
|
"test:watch": "vitest"
|