@portabletext/plugin-sdk-value 7.0.33 → 7.0.35-crx.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/index.js CHANGED
@@ -6,7 +6,6 @@ import { parsePath } from "@sanity/json-match";
6
6
  import { useEditDocument, useSanityInstance, getDocumentState } from "@sanity/sdk-react";
7
7
  import { useActorRef } from "@xstate/react";
8
8
  import { fromCallback, setup } from "xstate";
9
- const ARRAYIFY_ERROR_MESSAGE = "Unexpected path format from diffValue output. Please report this issue.";
10
9
  function* getSegments(node) {
11
10
  node.base && (yield* getSegments(node.base)), node.segment.type !== "This" && (yield node.segment);
12
11
  }
@@ -14,77 +13,92 @@ function isKeyPath(node) {
14
13
  return node.type !== "Path" || node.base || node.recursive || node.segment.type !== "Identifier" ? !1 : node.segment.name === "_key";
15
14
  }
16
15
  function arrayifyPath(pathExpr) {
17
- const node = parsePath(pathExpr);
18
- if (!node)
19
- return [];
20
- if (node.type !== "Path")
21
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
22
- return Array.from(getSegments(node)).map((segment) => {
23
- if (segment.type === "Identifier")
24
- return segment.name;
25
- if (segment.type !== "Subscript")
26
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
27
- if (segment.elements.length !== 1)
28
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
16
+ let node;
17
+ try {
18
+ node = parsePath(pathExpr);
19
+ } catch {
20
+ return null;
21
+ }
22
+ if (!node || node.type !== "Path")
23
+ return null;
24
+ const path = [];
25
+ for (const segment of getSegments(node)) {
26
+ if (segment.type === "Identifier") {
27
+ path.push(segment.name);
28
+ continue;
29
+ }
30
+ if (segment.type !== "Subscript" || segment.elements.length !== 1)
31
+ return null;
29
32
  const [element] = segment.elements;
30
- if (element.type === "Number")
31
- return element.value;
32
- if (element.type !== "Comparison")
33
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
34
- if (element.operator !== "==")
35
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
33
+ if (element.type === "Number") {
34
+ path.push(element.value);
35
+ continue;
36
+ }
37
+ if (element.type !== "Comparison" || element.operator !== "==")
38
+ return null;
36
39
  const keyPathNode = [element.left, element.right].find(isKeyPath);
37
40
  if (!keyPathNode)
38
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
41
+ return null;
39
42
  const other = element.left === keyPathNode ? element.right : element.left;
40
43
  if (other.type !== "String")
41
- throw new Error(ARRAYIFY_ERROR_MESSAGE);
42
- return {
44
+ return null;
45
+ path.push({
43
46
  _key: other.value
44
- };
45
- });
47
+ });
48
+ }
49
+ return path;
46
50
  }
47
51
  function convertPatches(patches) {
48
- return patches.flatMap((p) => Object.entries(p).flatMap(([type, values]) => {
49
- const origin = "remote";
50
- switch (type) {
51
- case "set":
52
- case "setIfMissing":
53
- case "diffMatchPatch":
54
- case "inc":
55
- case "dec":
56
- return Object.entries(values).map(([pathExpr, value]) => ({
57
- type,
58
- value,
59
- origin,
60
- path: arrayifyPath(pathExpr)
61
- }));
62
- case "unset":
63
- return Array.isArray(values) ? values.map(arrayifyPath).map((path) => ({
64
- type,
65
- origin,
66
- path
67
- })) : [];
68
- case "insert": {
69
- const {
70
- items,
71
- ...rest
72
- } = values, position = Object.keys(rest).at(0);
73
- if (!position)
52
+ let incomplete = !1;
53
+ return {
54
+ patches: patches.flatMap((operation) => Object.entries(operation).flatMap(([type, values]) => {
55
+ const origin = "remote";
56
+ switch (type) {
57
+ case "set":
58
+ case "setIfMissing":
59
+ case "diffMatchPatch":
60
+ case "inc":
61
+ case "dec":
62
+ return Object.entries(values).flatMap(([pathExpr, value]) => {
63
+ const path = arrayifyPath(pathExpr);
64
+ return path ? [{
65
+ type,
66
+ value,
67
+ origin,
68
+ path
69
+ }] : (incomplete = !0, []);
70
+ });
71
+ case "unset":
72
+ return Array.isArray(values) ? values.flatMap((pathExpr) => {
73
+ const path = arrayifyPath(pathExpr);
74
+ return path ? [{
75
+ type,
76
+ origin,
77
+ path
78
+ }] : (incomplete = !0, []);
79
+ }) : [];
80
+ case "insert": {
81
+ const {
82
+ items,
83
+ ...rest
84
+ } = values, position = Object.keys(rest).at(0);
85
+ if (!position)
86
+ return [];
87
+ const pathExpr = rest[position], path = arrayifyPath(pathExpr);
88
+ return path ? [{
89
+ type,
90
+ origin,
91
+ position,
92
+ path,
93
+ items
94
+ }] : (incomplete = !0, []);
95
+ }
96
+ default:
74
97
  return [];
75
- const pathExpr = rest[position];
76
- return [{
77
- type,
78
- origin,
79
- position,
80
- path: arrayifyPath(pathExpr),
81
- items
82
- }];
83
98
  }
84
- default:
85
- return [];
86
- }
87
- }));
99
+ })),
100
+ incomplete
101
+ };
88
102
  }
89
103
  function applySync({
90
104
  editor,
@@ -93,13 +107,32 @@ function applySync({
93
107
  const remoteValue = getRemoteValue();
94
108
  if (!remoteValue)
95
109
  return;
96
- const snapshot = editor.getSnapshot().context.value, patches = convertPatches(diffValue(snapshot, remoteValue));
110
+ const snapshot = editor.getSnapshot().context.value, {
111
+ patches,
112
+ incomplete
113
+ } = convertPatches(diffValue(snapshot, remoteValue));
114
+ if (incomplete || editor.getSnapshot().context.value !== snapshot) {
115
+ updateValueFromRemote({
116
+ editor,
117
+ getRemoteValue
118
+ });
119
+ return;
120
+ }
97
121
  patches.length && editor.send({
98
122
  type: "patches",
99
123
  patches,
100
124
  snapshot
101
125
  });
102
126
  }
127
+ function updateValueFromRemote({
128
+ editor,
129
+ getRemoteValue
130
+ }) {
131
+ editor.send({
132
+ type: "update value",
133
+ value: getRemoteValue() ?? []
134
+ });
135
+ }
103
136
  const listenToEditor = fromCallback(({
104
137
  sendBack,
105
138
  input
@@ -134,9 +167,9 @@ const listenToEditor = fromCallback(({
134
167
  "send initial value": ({
135
168
  context
136
169
  }) => {
137
- context.editor.send({
138
- type: "update value",
139
- value: context.getRemoteValue() ?? []
170
+ updateValueFromRemote({
171
+ editor: context.editor,
172
+ getRemoteValue: context.getRemoteValue
140
173
  });
141
174
  },
142
175
  "push to remote": () => {
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 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\n/**\n * @internal\n */\ntype ValueSyncConfig = {\n getRemoteValue: () => PortableTextBlock[] | null | undefined\n pushValue: (value: PortableTextBlock[]) => void\n onRemoteValueChange: (callback: () => void) => () => void\n}\n\n/**\n * NOTE: You are probably looking for SDKValuePlugin instead of this.\n * This is a lower-level plugin that only handles syncing the value\n * between the editor and a remote source. It does not know anything\n * about Sanity documents or how to fetch/update them.\n *\n * May be removed in the future, do not rely on this directly.\n *\n * @internal\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,QAAQI;AAEj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cC,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;"}
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 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\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\n/**\n * Converts a `diffValue` path expression (e.g. `[_key==\"a\"].children[0]`) into\n * a keyed Portable Text Editor path.\n *\n * Returns `null` – rather than throwing – for any expression that can't be\n * represented as a keyed PTE path. `diffValue` can emit such expressions in\n * practice: removing several non-keyed array items at once (e.g. clearing\n * multiple span `marks`) produces an array slice like `...marks[1:]`. Throwing\n * here would escape the synchronous `applySync` and break syncing entirely, so\n * we signal failure via `null` and let the caller skip the offending patch and\n * recover.\n */\nexport function arrayifyPath(pathExpr: string): Path | null {\n let node: ExprNode | undefined\n try {\n node = parsePath(pathExpr)\n } catch {\n // `parsePath` throws on malformed input such as an empty expression.\n return null\n }\n if (!node) {\n return null\n }\n if (node.type !== 'Path') {\n return null\n }\n\n const path: Path = []\n for (const segment of getSegments(node)) {\n if (segment.type === 'Identifier') {\n path.push(segment.name)\n continue\n }\n if (segment.type !== 'Subscript') {\n return null\n }\n if (segment.elements.length !== 1) {\n return null\n }\n\n const [element] = segment.elements\n if (element.type === 'Number') {\n path.push(element.value)\n continue\n }\n if (element.type !== 'Comparison') {\n // e.g. an array slice (`Slice`) that `diffValue` emits when removing\n // multiple non-keyed items at once.\n return null\n }\n if (element.operator !== '==') {\n return null\n }\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) {\n return null\n }\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') {\n return null\n }\n path.push({_key: other.value})\n }\n\n return path\n}\n\n/**\n * Converts a batch of `diffValue` patch operations into PTE patches.\n *\n * `incomplete` is `true` when one or more operations had to be dropped because\n * their path couldn't be converted (see `arrayifyPath`). The caller uses this\n * to fall back to an authoritative full value update instead of persisting a\n * partial diff.\n */\nexport function convertPatches(patches: SanityPatchOperations[]): {\n patches: PtePatch[]\n incomplete: boolean\n} {\n let incomplete = false\n\n const converted = patches.flatMap((operation) => {\n return Object.entries(operation).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).flatMap(([pathExpr, value]) => {\n const path = arrayifyPath(pathExpr)\n if (!path) {\n incomplete = true\n return []\n }\n return [{type, value, origin, path} as PtePatch]\n })\n }\n case 'unset': {\n if (!Array.isArray(values)) {\n return []\n }\n return values.flatMap((pathExpr) => {\n const path = arrayifyPath(pathExpr)\n if (!path) {\n incomplete = true\n return []\n }\n return [{type, origin, path} as PtePatch]\n })\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 path = arrayifyPath(pathExpr)\n if (!path) {\n incomplete = true\n return []\n }\n const insertPatch: PteInsertPatch = {\n type,\n origin,\n position,\n path,\n items: items as JSONValue[],\n }\n\n return [insertPatch]\n }\n\n default: {\n return []\n }\n }\n })\n })\n\n return {patches: converted, incomplete}\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, incomplete} = convertPatches(diffValue(snapshot, remoteValue))\n\n // Recover with an authoritative full value update when the diff can't be\n // applied faithfully. Either a patch was dropped – replaying the rest would\n // leave the editor in a partial/garbled state – or the editor moved on from\n // `snapshot` while we were diffing, so the patches were computed against a\n // value the editor no longer holds and can't be reconciled safely.\n if (incomplete || editor.getSnapshot().context.value !== snapshot) {\n updateValueFromRemote({editor, getRemoteValue})\n return\n }\n\n if (patches.length) {\n editor.send({type: 'patches', patches, snapshot})\n }\n}\n\nfunction updateValueFromRemote({\n editor,\n getRemoteValue,\n}: {\n editor: Editor\n getRemoteValue: () => PortableTextBlock[] | null | undefined\n}) {\n editor.send({type: 'update value', value: getRemoteValue() ?? []})\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 updateValueFromRemote({\n editor: context.editor,\n getRemoteValue: 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\n/**\n * @internal\n */\ntype ValueSyncConfig = {\n getRemoteValue: () => PortableTextBlock[] | null | undefined\n pushValue: (value: PortableTextBlock[]) => void\n onRemoteValueChange: (callback: () => void) => () => void\n}\n\n/**\n * NOTE: You are probably looking for SDKValuePlugin instead of this.\n * This is a lower-level plugin that only handles syncing the value\n * between the editor and a remote source. It does not know anything\n * about Sanity documents or how to fetch/update them.\n *\n * May be removed in the future, do not rely on this directly.\n *\n * @internal\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":["getSegments","node","base","segment","type","isKeyPath","recursive","name","arrayifyPath","pathExpr","parsePath","path","push","elements","length","element","value","operator","keyPathNode","left","right","find","other","_key","convertPatches","patches","incomplete","flatMap","operation","Object","entries","values","origin","Array","isArray","items","rest","position","keys","at","applySync","editor","getRemoteValue","remoteValue","snapshot","getSnapshot","context","diffValue","updateValueFromRemote","send","listenToEditor","fromCallback","sendBack","input","patchSubscription","on","mutationSubscription","event","unsubscribe","listenToRemote","onRemoteValueChange","valueSyncMachine","setup","types","events","actions","send initial value","push to remote","Error","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":";;;;;;;;AA8BA,UAAUA,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;AAcO,SAASC,aAAaC,UAA+B;AAC1D,MAAIR;AACJ,MAAI;AACFA,WAAOS,UAAUD,QAAQ;AAAA,EAC3B,QAAQ;AAEN,WAAO;AAAA,EACT;AAIA,MAHI,CAACR,QAGDA,KAAKG,SAAS;AAChB,WAAO;AAGT,QAAMO,OAAa,CAAA;AACnB,aAAWR,WAAWH,YAAYC,IAAI,GAAG;AACvC,QAAIE,QAAQC,SAAS,cAAc;AACjC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AAS,GAC9BX,OAAAU,YAAAV,OAAAI,aAAAJ,OAAAW,WAAAX,OAAAY,MAAAA,KAAAZ,EAAA,CAAA,GAJFY;AAIE;AAuBC,SAAAC,gBAAAd,OAAA;AAAA,QAAAC,IAAAC,EAAA,CAAA,GACL;AAAA,IAAA1C;AAAAA,IAAAuD;AAAAA,IAAArC;AAAAA,EAAAA,IAAyDsB,OACzDzC,SAAeyD,UAAAA;AAAW,MAAAP;AAAAR,WAAAc,aAGxBN,KAAA9B,iBAAgBsC,QAAS;AAAA,IAAAlC,SACd;AAAA,MAAA,kBACW8B,CAAAA,QAAA;AAAC,cAAA;AAAA,UAAAjD;AAAAA,UAAAW;AAAAA,QAAAA,IAAAsC;AACbtC,cAAKrD,SAAU,sBAInB6F,UAAUxC,MAAKzC,SAAU8B,QAAOL,OAAOI,cAAcC,QAAQ9B,KAAM;AAAA,MAAC;AAAA,IAAA;AAAA,EAExE,CACD,GAACmE,OAAAc,WAAAd,OAAAQ,MAAAA,KAAAR,EAAA,CAAA;AAAA,MAAAY;AAAA,SAAAZ,EAAA,CAAA,MAAA1C,UAAA0C,SAAAzC,kBAAAyC,EAAA,CAAA,MAAAvB,uBACFmC,KAAA;AAAA,IAAA1C,OACS;AAAA,MAAAZ;AAAAA,MAAAC;AAAAA,MAAAkB;AAAAA,IAAAA;AAAAA,EAIP,GACDuB,OAAA1C,QAAA0C,OAAAzC,gBAAAyC,OAAAvB,qBAAAuB,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": "7.0.33",
3
+ "version": "7.0.35-crx.0",
4
4
  "description": "Connect a Portable Text Editor with a Sanity document using the SDK",
5
5
  "keywords": [
6
6
  "@sanity/sdk",
@@ -58,16 +58,16 @@
58
58
  "typescript-eslint": "^8.62.0",
59
59
  "vitest": "^4.1.10",
60
60
  "vitest-browser-react": "^2.2.0",
61
- "@portabletext/editor": "^7.10.6",
61
+ "@portabletext/editor": "^7.10.8-crx.0",
62
+ "@portabletext/schema": "^2.2.3",
62
63
  "@portabletext/patches": "^2.0.5",
63
- "@portabletext/schema": "^2.2.2",
64
64
  "@portabletext/test": "^1.0.4"
65
65
  },
66
66
  "peerDependencies": {
67
67
  "@sanity/sdk-react": "^2.1.2",
68
68
  "react": "^19.2",
69
69
  "react-dom": "^19.2",
70
- "@portabletext/editor": "^7.10.6"
70
+ "@portabletext/editor": "^7.10.8-crx.0"
71
71
  },
72
72
  "engines": {
73
73
  "node": ">=20.19 <22 || >=22.12"