@portabletext/plugin-sdk-value 1.0.2 → 1.0.4

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.cjs CHANGED
@@ -91,7 +91,7 @@ function SDKValuePlugin(props) {
91
91
  }), () => {
92
92
  unsubscribeToEditorChanges(), unsubscribeToSdkChanges();
93
93
  };
94
- }, t1 = [setSdkValue, editor$1, instance, props], $[0] = editor$1, $[1] = instance, $[2] = props, $[3] = setSdkValue, $[4] = t0, $[5] = t1) : (t0 = $[4], t1 = $[5]), react.useEffect(t0, t1), null;
94
+ }, t1 = [editor$1, instance, props, setSdkValue], $[0] = editor$1, $[1] = instance, $[2] = props, $[3] = setSdkValue, $[4] = t0, $[5] = t1) : (t0 = $[4], t1 = $[5]), react.useEffect(t0, t1), null;
95
95
  }
96
96
  exports.SDKValuePlugin = SDKValuePlugin;
97
97
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","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) yield* getSegments(node.base)\n if (node.segment.type !== 'This') yield node.segment\n}\n\nfunction isKeyPath(node: ExprNode): node is PathNode {\n if (node.type !== 'Path') return false\n if (node.base) return false\n if (node.recursive) return false\n if (node.segment.type !== 'Identifier') return false\n return node.segment.name === '_key'\n}\n\nfunction arrayifyPath(pathExpr: string): Path {\n const node = parsePath(pathExpr)\n if (!node) return []\n if (node.type !== 'Path') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n return Array.from(getSegments(node)).map((segment): PathSegment => {\n if (segment.type === 'Identifier') return segment.name\n if (segment.type !== 'Subscript') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (segment.elements.length !== 1) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n const [element] = segment.elements\n if (element.type === 'Number') return element.value\n\n if (element.type !== 'Comparison') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (element.operator !== '==') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n return {_key: other.value}\n })\n}\n\nfunction 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)) return []\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) return []\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 const editorSubscription = editor.on('patch', () =>\n setSdkValue(getEditorValue()),\n )\n const unsubscribeToEditorChanges = () => editorSubscription.unsubscribe()\n const unsubscribeToSdkChanges = onSdkValueChange(() => {\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 // update initial value\n editor.send({type: 'update value', value: getSdkValue() ?? []})\n\n return () => {\n unsubscribeToEditorChanges()\n unsubscribeToSdkChanges()\n }\n }, [setSdkValue, editor, instance, props])\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","editorSubscription","on","unsubscribeToEditorChanges","unsubscribe","unsubscribeToSdkChanges","snapshot","diffValue","send","useEffect"],"mappings":";;;AAiCA,MAAMA,yBACJ;AAEF,UAAUC,YACRC,MAC2C;AACvCA,OAAKC,SAAM,OAA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A,SAAAT,EAAA,CAAA,MAAAM,YAAAN,EAAAI,CAAAA,MAAAA,YAAAJ,EAAAD,CAAAA,MAAAA,SAAAC,SAAAE,eAEhBM,KAAAA,MAAA;AACR,UAAAE,iBAAAA,MAA6BJ,SAAMK,YAAa,EAACC,QAAArC,OACjD;AAAA,MAAAsC,YAAAC;AAAAA,MAAAC,WAAAC;AAAAA,IAAAA,IACEC,0BAAsCb,UAAUL,KAAK,GAEvDmB,qBAA2BZ,SAAMa,GAAI,SACnCjB,MAAAA,YAAYQ,gBAAgB,CAC9B,GACAU,6BAAAA,MAAyCF,mBAAkBG,eAC3DC,0BAAgCN,iBAAgB,MAAA;AAC9CO,YAAAA,WAAiBb,kBACjB1B,UAAgBD,eAAeyC,oBAAUD,UAAUT,YAAY,CAAC,CAAC;AAE7D9B,cAAOX,UACTiC,SAAMmB,KAAA;AAAA,QAAAhE,MAAa;AAAA,QAASuB;AAAAA,QAAAuC;AAAAA,MAAAA,CAAoB;AAAA,IAAA,CAEnD;AAGDjB,WAAAA,SAAMmB,KAAA;AAAA,MAAAhE,MAAa;AAAA,MAAcc,OAASuC,YAAY,KAAC,CAAA;AAAA,IAAO,CAAA,GAAC,MAAA;AAG7DM,iCAAAA,GACAE,wBAAwB;AAAA,IAAC;AAAA,EAAA,GAE1Bb,MAACP,aAAaI,UAAQF,UAAUL,KAAK,GAACC,OAAAM,UAAAN,OAAAI,UAAAJ,OAAAD,OAAAC,OAAAE,aAAAF,OAAAQ,IAAAR,OAAAS,OAAAD,KAAAR,EAAA,CAAA,GAAAS,KAAAT,EAAA,CAAA,IAzBzC0B,gBAAUlB,IAyBPC,EAAsC,GAAC;AAAA;;"}
1
+ {"version":3,"file":"index.cjs","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) yield* getSegments(node.base)\n if (node.segment.type !== 'This') yield node.segment\n}\n\nfunction isKeyPath(node: ExprNode): node is PathNode {\n if (node.type !== 'Path') return false\n if (node.base) return false\n if (node.recursive) return false\n if (node.segment.type !== 'Identifier') return false\n return node.segment.name === '_key'\n}\n\nfunction arrayifyPath(pathExpr: string): Path {\n const node = parsePath(pathExpr)\n if (!node) return []\n if (node.type !== 'Path') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n return Array.from(getSegments(node)).map((segment): PathSegment => {\n if (segment.type === 'Identifier') return segment.name\n if (segment.type !== 'Subscript') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (segment.elements.length !== 1) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n const [element] = segment.elements\n if (element.type === 'Number') return element.value\n\n if (element.type !== 'Comparison') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (element.operator !== '==') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n return {_key: other.value}\n })\n}\n\nfunction 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)) return []\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) return []\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 const editorSubscription = editor.on('patch', () =>\n setSdkValue(getEditorValue()),\n )\n const unsubscribeToEditorChanges = () => editorSubscription.unsubscribe()\n const unsubscribeToSdkChanges = onSdkValueChange(() => {\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 // 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","editorSubscription","on","unsubscribeToEditorChanges","unsubscribe","unsubscribeToSdkChanges","snapshot","diffValue","send","useEffect"],"mappings":";;;AAiCA,MAAMA,yBACJ;AAEF,UAAUC,YACRC,MAC2C;AACvCA,OAAKC,SAAM,OAAOF,YAAYC,KAAKC,IAAI,IACvCD,KAAKE,QAAQC,SAAS,WAAQ,MAAMH,KAAKE;AAC/C;AAEA,SAASE,UAAUJ,MAAkC;AAInD,SAHIA,KAAKG,SAAS,UACdH,KAAKC,QACLD,KAAKK,aACLL,KAAKE,QAAQC,SAAS,eAAqB,KACxCH,KAAKE,QAAQI,SAAS;AAC/B;AAEA,SAASC,aAAaC,UAAwB;AAC5C,QAAMR,OAAOS,UAAAA,UAAUD,QAAQ;AAC/B,MAAI,CAACR,KAAM,QAAO,CAAA;AAClB,MAAIA,KAAKG,SAAS,OAAQ,OAAM,IAAIO,MAAMZ,sBAAsB;AAEhE,SAAOa,MAAMC,KAAKb,YAAYC,IAAI,CAAC,EAAEa,IAAKX,CAAAA,YAAyB;AACjE,QAAIA,QAAQC,SAAS,aAAc,QAAOD,QAAQI;AAClD,QAAIJ,QAAQC,SAAS,YAAa,OAAM,IAAIO,MAAMZ,sBAAsB;AACxE,QAAII,QAAQY,SAASC,WAAW,EAAG,OAAM,IAAIL,MAAMZ,sBAAsB;AAEzE,UAAM,CAACkB,OAAO,IAAId,QAAQY;AAC1B,QAAIE,QAAQb,SAAS,SAAU,QAAOa,QAAQC;AAE9C,QAAID,QAAQb,SAAS,aAAc,OAAM,IAAIO,MAAMZ,s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AAAA,EAAA,GAE1Bb,MAACH,UAAQF,UAAUL,OAAOG,WAAW,GAACF,OAAAM,UAAAN,OAAAI,UAAAJ,OAAAD,OAAAC,OAAAE,aAAAF,OAAAQ,IAAAR,OAAAS,OAAAD,KAAAR,EAAA,CAAA,GAAAS,KAAAT,EAAA,CAAA,IAzBzC0B,gBAAUlB,IAyBPC,EAAsC,GAAC;AAAA;;"}
package/dist/index.js CHANGED
@@ -94,7 +94,7 @@ function SDKValuePlugin(props) {
94
94
  }), () => {
95
95
  unsubscribeToEditorChanges(), unsubscribeToSdkChanges();
96
96
  };
97
- }, t1 = [setSdkValue, editor, instance, props], $[0] = editor, $[1] = instance, $[2] = props, $[3] = setSdkValue, $[4] = t0, $[5] = t1) : (t0 = $[4], t1 = $[5]), useEffect(t0, t1), null;
97
+ }, t1 = [editor, instance, props, setSdkValue], $[0] = editor, $[1] = instance, $[2] = props, $[3] = setSdkValue, $[4] = t0, $[5] = t1) : (t0 = $[4], t1 = $[5]), useEffect(t0, t1), null;
98
98
  }
99
99
  export {
100
100
  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) yield* getSegments(node.base)\n if (node.segment.type !== 'This') yield node.segment\n}\n\nfunction isKeyPath(node: ExprNode): node is PathNode {\n if (node.type !== 'Path') return false\n if (node.base) return false\n if (node.recursive) return false\n if (node.segment.type !== 'Identifier') return false\n return node.segment.name === '_key'\n}\n\nfunction arrayifyPath(pathExpr: string): Path {\n const node = parsePath(pathExpr)\n if (!node) return []\n if (node.type !== 'Path') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n return Array.from(getSegments(node)).map((segment): PathSegment => {\n if (segment.type === 'Identifier') return segment.name\n if (segment.type !== 'Subscript') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (segment.elements.length !== 1) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n const [element] = segment.elements\n if (element.type === 'Number') return element.value\n\n if (element.type !== 'Comparison') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (element.operator !== '==') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n return {_key: other.value}\n })\n}\n\nfunction 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)) return []\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) return []\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 const editorSubscription = editor.on('patch', () =>\n setSdkValue(getEditorValue()),\n )\n const unsubscribeToEditorChanges = () => editorSubscription.unsubscribe()\n const unsubscribeToSdkChanges = onSdkValueChange(() => {\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 // update initial value\n editor.send({type: 'update value', value: getSdkValue() ?? []})\n\n return () => {\n unsubscribeToEditorChanges()\n unsubscribeToSdkChanges()\n }\n }, [setSdkValue, editor, instance, props])\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","editorSubscription","on","unsubscribeToEditorChanges","unsubscribe","unsubscribeToSdkChanges","snapshot","diffVal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AiBC,kBAAkBN,KAAK,GACxCO,SAAeC,UAAU;AAAC,MAAAC,IAAAC;AAAA,SAAAT,EAAA,CAAA,MAAAM,UAAAN,EAAAI,CAAAA,MAAAA,YAAAJ,EAAAD,CAAAA,MAAAA,SAAAC,SAAAE,eAEhBM,KAAAA,MAAA;AACR,UAAAE,iBAAAA,MAA6BJ,OAAMK,YAAa,EAACC,QAAArC,OACjD;AAAA,MAAAsC,YAAAC;AAAAA,MAAAC,WAAAC;AAAAA,IAAAA,IACEC,iBAAsCb,UAAUL,KAAK,GAEvDmB,qBAA2BZ,OAAMa,GAAI,SACnCjB,MAAAA,YAAYQ,gBAAgB,CAC9B,GACAU,6BAAAA,MAAyCF,mBAAkBG,eAC3DC,0BAAgCN,iBAAgB,MAAA;AAC9CO,YAAAA,WAAiBb,kBACjB1B,UAAgBD,eAAeyC,UAAUD,UAAUT,YAAY,CAAC,CAAC;AAE7D9B,cAAOX,UACTiC,OAAMmB,KAAA;AAAA,QAAAhE,MAAa;AAAA,QAASuB;AAAAA,QAAAuC;AAAAA,MAAAA,CAAoB;AAAA,IAAA,CAEnD;AAGDjB,WAAAA,OAAMmB,KAAA;AAAA,MAAAhE,MAAa;AAAA,MAAcc,OAASuC,YAAY,KAAC,CAAA;AAAA,IAAO,CAAA,GAAC,MAAA;AAG7DM,iCAAAA,GACAE,wBAAwB;AAAA,IAAC;AAAA,EAAA,GAE1Bb,MAACP,aAAaI,QAAQF,UAAUL,KAAK,GAACC,OAAAM,QAAAN,OAAAI,UAAAJ,OAAAD,OAAAC,OAAAE,aAAAF,OAAAQ,IAAAR,OAAAS,OAAAD,KAAAR,EAAA,CAAA,GAAAS,KAAAT,EAAA,CAAA,IAzBzC0B,UAAUlB,IAyBPC,EAAsC,GAAC;AAAA;"}
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) yield* getSegments(node.base)\n if (node.segment.type !== 'This') yield node.segment\n}\n\nfunction isKeyPath(node: ExprNode): node is PathNode {\n if (node.type !== 'Path') return false\n if (node.base) return false\n if (node.recursive) return false\n if (node.segment.type !== 'Identifier') return false\n return node.segment.name === '_key'\n}\n\nfunction arrayifyPath(pathExpr: string): Path {\n const node = parsePath(pathExpr)\n if (!node) return []\n if (node.type !== 'Path') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n return Array.from(getSegments(node)).map((segment): PathSegment => {\n if (segment.type === 'Identifier') return segment.name\n if (segment.type !== 'Subscript') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (segment.elements.length !== 1) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n\n const [element] = segment.elements\n if (element.type === 'Number') return element.value\n\n if (element.type !== 'Comparison') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n if (element.operator !== '==') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const keyPathNode = [element.left, element.right].find(isKeyPath)\n if (!keyPathNode) throw new Error(ARRAYIFY_ERROR_MESSAGE)\n const other = element.left === keyPathNode ? element.right : element.left\n if (other.type !== 'String') throw new Error(ARRAYIFY_ERROR_MESSAGE)\n return {_key: other.value}\n })\n}\n\nfunction 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)) return []\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) return []\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 const editorSubscription = editor.on('patch', () =>\n setSdkValue(getEditorValue()),\n )\n const unsubscribeToEditorChanges = () => editorSubscription.unsubscribe()\n const unsubscribeToSdkChanges = onSdkValueChange(() => {\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 // 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","editorSubscription","on","unsubscribeToEditorChanges","unsubscribe","unsubscribeToSdkChanges","snapshot","diffValue","send","useEffect"],"mappings":";;;;;;AAiCA,MAAMA,yBACJ;AAEF,UAAUC,YACRC,MAC2C;AACvCA,OAAKC,SAAM,OAAOF,YAAYC,KAAKC,IAAI,IACvCD,KAAKE,QAAQC,SAAS,WAAQ,MAAMH,KAAKE;AAC/C;AAEA,SAASE,UAAUJ,MAAkC;AAInD,SAHIA,KAAKG,SAAS,UACdH,KAAKC,QACLD,KAAKK,aACLL,KAAKE,QAAQC,SAAS,eAAqB,KACxCH,KAAKE,QAAQI,SAAS;AAC/B;AAEA,SAASC,aAAaC,UAAwB;AAC5C,QAAMR,OAAOS,UAAUD,QAAQ;AAC/B,MAAI,CAACR,KAAM,QAAO,CAAA;AAClB,MAAIA,KAAKG,SAAS,OAAQ,OAAM,IAAIO,MAAMZ,sBAAsB;AAEhE,SAAOa,MAAMC,KAAKb,YAAYC,IAAI,CAAC,EAAEa,IAAKX,CAAAA,YAAyB;AACjE,QAAIA,QAAQC,SAAS,aAAc,QAAOD,QAAQI;AAClD,QAAIJ,QAAQC,SAAS,YAAa,OAAM,IAAIO,MAAMZ,sBAAsB;AACxE,QAAII,QAAQY,SAASC,WAAW,EAAG,OAAM,IAAIL,MAAMZ,sBAAsB;AAEzE,UAAM,CAACkB,OAAO,IAAId,QAAQY;AAC1B,QAAIE,QAAQb,SAAS,SAAU,QAAOa,QAAQC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AA;AAAAA,IAAyB;AAAA,EAAA,GAE1Bb,MAACH,QAAQF,UAAUL,OAAOG,WAAW,GAACF,OAAAM,QAAAN,OAAAI,UAAAJ,OAAAD,OAAAC,OAAAE,aAAAF,OAAAQ,IAAAR,OAAAS,OAAAD,KAAAR,EAAA,CAAA,GAAAS,KAAAT,EAAA,CAAA,IAzBzC0B,UAAUlB,IAyBPC,EAAsC,GAAC;AAAA;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@portabletext/plugin-sdk-value",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "description": "Synchronizes the Portable Text Editor value with the Sanity SDK, allowing for two-way editing.",
5
5
  "keywords": [
6
6
  "portabletext",
@@ -44,13 +44,13 @@
44
44
  "@portabletext/editor": "^2.4.1",
45
45
  "@portabletext/patches": "^1.1.6",
46
46
  "@sanity/schema": "^4.3.0",
47
- "@sanity/sdk-react": "^2.1.1",
47
+ "@sanity/sdk-react": "^2.1.2",
48
48
  "@sanity/types": "^4.3.0",
49
49
  "@testing-library/react": "^16.3.0",
50
50
  "@testing-library/user-event": "^14.6.1",
51
51
  "@types/react": "^19.1.2",
52
52
  "@vitejs/plugin-react": "^4.4.1",
53
- "babel-plugin-react-compiler": "19.0.0-beta-e993439-20250328",
53
+ "babel-plugin-react-compiler": "19.1.0-rc.3",
54
54
  "playwright": "^1.52.0",
55
55
  "react": "^19.1.0",
56
56
  "react-dom": "^19.1.0",
@@ -58,19 +58,18 @@
58
58
  },
59
59
  "peerDependencies": {
60
60
  "@portabletext/editor": "^2.4.1",
61
- "@sanity/sdk-react": "^2.1.1",
62
- "react": "^19.1.0",
63
- "react-dom": "^19.1.0"
61
+ "@sanity/sdk-react": "^2.1.2",
62
+ "react": "^19",
63
+ "react-dom": "^19"
64
64
  },
65
65
  "dependencies": {
66
66
  "@sanity/diff-patch": "^6.0.0",
67
- "@sanity/json-match": "^1.0.5",
68
- "react-compiler-runtime": "19.1.0-rc.1"
67
+ "@sanity/json-match": "^1.0.5"
69
68
  },
70
69
  "scripts": {
71
70
  "build": "pkg-utils build --strict --check --clean",
72
71
  "check:lint": "biome lint .",
73
- "check:react-compiler": "eslint --cache --no-inline-config --no-eslintrc --ignore-pattern '**/__tests__/**' --ext .cjs,.mjs,.js,.jsx,.ts,.tsx --parser @typescript-eslint/parser --plugin react-compiler --plugin react-hooks --rule 'react-compiler/react-compiler: [warn]' --rule 'react-hooks/rules-of-hooks: [error]' --rule 'react-hooks/exhaustive-deps: [error]' src",
72
+ "check:react-compiler": "eslint .",
74
73
  "check:types": "tsc",
75
74
  "check:types:watch": "tsc --watch",
76
75
  "clean": "del .turbo && del dist && del node_modules",
@@ -151,7 +151,7 @@ export function SDKValuePlugin(props: SDKValuePluginProps) {
151
151
  unsubscribeToEditorChanges()
152
152
  unsubscribeToSdkChanges()
153
153
  }
154
- }, [setSdkValue, editor, instance, props])
154
+ }, [editor, instance, props, setSdkValue])
155
155
 
156
156
  return null
157
157
  }