@portabletext/plugin-sdk-value 5.0.4 → 5.0.5
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 +29 -11
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -85,25 +85,43 @@ function convertPatches(patches) {
|
|
|
85
85
|
}));
|
|
86
86
|
}
|
|
87
87
|
function SDKValuePlugin(props) {
|
|
88
|
-
const $ = c(
|
|
88
|
+
const $ = c(8), {
|
|
89
|
+
documentId,
|
|
90
|
+
documentType,
|
|
91
|
+
path
|
|
92
|
+
} = props, setSdkValue = useEditDocument(props), instance = useSanityInstance(props), editor = useEditor();
|
|
89
93
|
let t0, t1;
|
|
90
|
-
return $[0] !==
|
|
91
|
-
const
|
|
94
|
+
return $[0] !== documentId || $[1] !== documentType || $[2] !== editor || $[3] !== instance || $[4] !== path || $[5] !== setSdkValue ? (t0 = () => {
|
|
95
|
+
const handle = {
|
|
96
|
+
documentId,
|
|
97
|
+
documentType,
|
|
98
|
+
path
|
|
99
|
+
}, getEditorValue = () => editor.getSnapshot().context.value, {
|
|
92
100
|
getCurrent: getSdkValue,
|
|
93
101
|
subscribe: onSdkValueChange
|
|
94
|
-
} = getDocumentState(instance,
|
|
95
|
-
let isLocalWrite = !1;
|
|
96
|
-
const
|
|
97
|
-
isLocalWrite = !0, setSdkValue(event.value ?? getEditorValue()), isLocalWrite = !1;
|
|
98
|
-
}), unsubscribeToEditorChanges = () => editorSubscription.unsubscribe(), unsubscribeToSdkChanges = onSdkValueChange(() => {
|
|
99
|
-
if (isLocalWrite)
|
|
100
|
-
return;
|
|
102
|
+
} = getDocumentState(instance, handle);
|
|
103
|
+
let isLocalWrite = !1, hasPendingWrites = !1, pendingSync = !1;
|
|
104
|
+
const applySync = function() {
|
|
101
105
|
const snapshot = getEditorValue(), patches = convertPatches(diffValue(snapshot, getSdkValue()));
|
|
102
106
|
patches.length && editor.send({
|
|
103
107
|
type: "patches",
|
|
104
108
|
patches,
|
|
105
109
|
snapshot
|
|
106
110
|
});
|
|
111
|
+
}, patchSubscription = editor.on("patch", () => {
|
|
112
|
+
hasPendingWrites = !0;
|
|
113
|
+
}), mutationSubscription = editor.on("mutation", (event) => {
|
|
114
|
+
isLocalWrite = !0, setSdkValue(event.value ?? getEditorValue()), isLocalWrite = !1, hasPendingWrites = !1, pendingSync && (pendingSync = !1, queueMicrotask(applySync));
|
|
115
|
+
}), unsubscribeToEditorChanges = () => {
|
|
116
|
+
patchSubscription.unsubscribe(), mutationSubscription.unsubscribe();
|
|
117
|
+
}, unsubscribeToSdkChanges = onSdkValueChange(() => {
|
|
118
|
+
if (!isLocalWrite) {
|
|
119
|
+
if (hasPendingWrites) {
|
|
120
|
+
pendingSync = !0;
|
|
121
|
+
return;
|
|
122
|
+
}
|
|
123
|
+
applySync();
|
|
124
|
+
}
|
|
107
125
|
});
|
|
108
126
|
return editor.send({
|
|
109
127
|
type: "update value",
|
|
@@ -111,7 +129,7 @@ function SDKValuePlugin(props) {
|
|
|
111
129
|
}), () => {
|
|
112
130
|
unsubscribeToEditorChanges(), unsubscribeToSdkChanges();
|
|
113
131
|
};
|
|
114
|
-
}, t1 = [editor, instance,
|
|
132
|
+
}, t1 = [editor, instance, documentId, documentType, path, setSdkValue], $[0] = documentId, $[1] = documentType, $[2] = editor, $[3] = instance, $[4] = path, $[5] = setSdkValue, $[6] = t0, $[7] = t1) : (t0 = $[6], t1 = $[7]), useEffect(t0, t1), null;
|
|
115
133
|
}
|
|
116
134
|
export {
|
|
117
135
|
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\n const editorSubscription = editor.on('mutation', (event) => {\n isLocalWrite = true\n setSdkValue(event.value ?? getEditorValue())\n isLocalWrite = false\n })\n const unsubscribeToEditorChanges = () => editorSubscription.unsubscribe()\n const unsubscribeToSdkChanges = onSdkValueChange(() => {\n if (isLocalWrite) {\n return\n }\n\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","isLocalWrite","editorSubscription","on","event","unsubscribeToEditorChanges","unsubscribe","unsubscribeToSdkChanges","snapshot","diffValue","send","useEffect"],"mappings":";;;;;;AAiCA,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;AAEjB,QAAIJ,QAAQC,SAAS;AACnB,YAAM,IAAIO,MAAMZ,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AA,CAAa,CAAC;AAE7D9B,cAAOX,UACTiC,OAAMqB,KAAM;AAAA,QAAAlE,MAAO;AAAA,QAASuB;AAAAA,QAAAyC;AAAAA,MAAAA,CAAoB;AAAA,IACjD,CACF;AAGDnB,WAAAA,OAAMqB,KAAM;AAAA,MAAAlE,MAAO;AAAA,MAAcc,OAASuC,YAAAA,KAAA,CAAA;AAAA,IAAA,CAAoB,GAEvD,MAAA;AACLQ,iCAAAA,GACAE,wBAAAA;AAAAA,IAAyB;AAAA,EAC1B,GACAf,KAAA,CAACH,QAAQF,UAAUL,OAAOG,WAAW,GAACF,OAAAM,QAAAN,OAAAI,UAAAJ,OAAAD,OAAAC,OAAAE,aAAAF,OAAAQ,IAAAR,OAAAS,OAAAD,KAAAR,EAAA,CAAA,GAAAS,KAAAT,EAAA,CAAA,IAjCzC4B,UAAUpB,IAiCPC,EAAsC,GAElC;AAAI;"}
|
|
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 const {documentId, documentType, path} = props\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 handle = {documentId, documentType, path}\n const getEditorValue = () => editor.getSnapshot().context.value\n const {getCurrent: getSdkValue, subscribe: onSdkValueChange} =\n getDocumentState<PortableTextBlock[]>(instance, handle)\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, documentId, documentType, path, 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","documentId","documentType","setSdkValue","useEditDocument","instance","useSanityInstance","editor","useEditor","t0","t1","handle","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,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;AAEjB,QAAIJ,QAAQC,SAAS;AACnB,YAAM,IAAIO,MAAMZ,sBAAsB;AAExC,QAAII,QAAQY,SAASC,WAAW;AAC9B,YAAM,IAAIL,MAAMZ,sBAAsB;AAGxC,UAAM,CAACkB,OAAO,IAAId,QAAQY;AAC1B,QAAIE,QAAQb,SAAS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