@payloadcms/live-preview 3.44.0-canary.9 → 3.44.0-internal.6b79dc2
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"handleMessage.d.ts","sourceRoot":"","sources":["../src/handleMessage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kCAAkC,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAwB7F,eAAO,MAAM,aAAa,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAA;IACjC,WAAW,EAAE,CAAC,CAAA;IACd,cAAc,CAAC,EAAE,kCAAkC,CAAA;IACnD,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAAO,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"handleMessage.d.ts","sourceRoot":"","sources":["../src/handleMessage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,kCAAkC,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAwB7F,eAAO,MAAM,aAAa,GAAU,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,QAAQ;IACvE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,uBAAuB,CAAC,CAAC,CAAC,CAAA;IACjC,WAAW,EAAE,CAAC,CAAA;IACd,cAAc,CAAC,EAAE,kCAAkC,CAAA;IACnD,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAAO,CAAC,CAAC,CAyCZ,CAAA"}
|
package/dist/handleMessage.js
CHANGED
|
@@ -38,7 +38,10 @@ export const handleMessage = async (args)=>{
|
|
|
38
38
|
_payloadLivePreview.previousData = mergedData;
|
|
39
39
|
return mergedData;
|
|
40
40
|
}
|
|
41
|
-
|
|
41
|
+
if (!_payloadLivePreview.previousData) {
|
|
42
|
+
_payloadLivePreview.previousData = initialData;
|
|
43
|
+
}
|
|
44
|
+
return _payloadLivePreview.previousData;
|
|
42
45
|
};
|
|
43
46
|
|
|
44
47
|
//# sourceMappingURL=handleMessage.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/handleMessage.ts"],"sourcesContent":["import type { FieldSchemaJSON } from 'payload'\n\nimport type { CollectionPopulationRequestHandler, LivePreviewMessageEvent } from './types.js'\n\nimport { isLivePreviewEvent } from './isLivePreviewEvent.js'\nimport { mergeData } from './mergeData.js'\n\nconst _payloadLivePreview: {\n fieldSchema: FieldSchemaJSON | undefined\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n previousData: any\n} = {\n /**\n * For performance reasons, `fieldSchemaJSON` will only be sent once on the initial message\n * We need to cache this value so that it can be used across subsequent messages\n * To do this, save `fieldSchemaJSON` when it arrives as a global variable\n * Send this cached value to `mergeData`, instead of `eventData.fieldSchemaJSON` directly\n */\n fieldSchema: undefined,\n /**\n * Each time the data is merged, cache the result as a `previousData` variable\n * This will ensure changes compound overtop of each other\n */\n previousData: undefined,\n}\n\nexport const handleMessage = async <T extends Record<string, any>>(args: {\n apiRoute?: string\n depth?: number\n event: LivePreviewMessageEvent<T>\n initialData: T\n requestHandler?: CollectionPopulationRequestHandler\n serverURL: string\n}): Promise<T> => {\n const { apiRoute, depth, event, initialData, requestHandler, serverURL } = args\n\n if (isLivePreviewEvent(event, serverURL)) {\n const { data, externallyUpdatedRelationship, fieldSchemaJSON, locale } = event.data\n\n if (!_payloadLivePreview?.fieldSchema && fieldSchemaJSON) {\n _payloadLivePreview.fieldSchema = fieldSchemaJSON\n }\n\n if (!_payloadLivePreview?.fieldSchema) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Payload Live Preview: No `fieldSchemaJSON` was received from the parent window. Unable to merge data.',\n )\n\n return initialData\n }\n\n const mergedData = await mergeData<T>({\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema: _payloadLivePreview.fieldSchema,\n incomingData: data,\n initialData: _payloadLivePreview?.previousData || initialData,\n locale,\n requestHandler,\n serverURL,\n })\n\n _payloadLivePreview.previousData = mergedData\n\n return mergedData\n }\n\n
|
|
1
|
+
{"version":3,"sources":["../src/handleMessage.ts"],"sourcesContent":["import type { FieldSchemaJSON } from 'payload'\n\nimport type { CollectionPopulationRequestHandler, LivePreviewMessageEvent } from './types.js'\n\nimport { isLivePreviewEvent } from './isLivePreviewEvent.js'\nimport { mergeData } from './mergeData.js'\n\nconst _payloadLivePreview: {\n fieldSchema: FieldSchemaJSON | undefined\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n previousData: any\n} = {\n /**\n * For performance reasons, `fieldSchemaJSON` will only be sent once on the initial message\n * We need to cache this value so that it can be used across subsequent messages\n * To do this, save `fieldSchemaJSON` when it arrives as a global variable\n * Send this cached value to `mergeData`, instead of `eventData.fieldSchemaJSON` directly\n */\n fieldSchema: undefined,\n /**\n * Each time the data is merged, cache the result as a `previousData` variable\n * This will ensure changes compound overtop of each other\n */\n previousData: undefined,\n}\n\nexport const handleMessage = async <T extends Record<string, any>>(args: {\n apiRoute?: string\n depth?: number\n event: LivePreviewMessageEvent<T>\n initialData: T\n requestHandler?: CollectionPopulationRequestHandler\n serverURL: string\n}): Promise<T> => {\n const { apiRoute, depth, event, initialData, requestHandler, serverURL } = args\n\n if (isLivePreviewEvent(event, serverURL)) {\n const { data, externallyUpdatedRelationship, fieldSchemaJSON, locale } = event.data\n\n if (!_payloadLivePreview?.fieldSchema && fieldSchemaJSON) {\n _payloadLivePreview.fieldSchema = fieldSchemaJSON\n }\n\n if (!_payloadLivePreview?.fieldSchema) {\n // eslint-disable-next-line no-console\n console.warn(\n 'Payload Live Preview: No `fieldSchemaJSON` was received from the parent window. Unable to merge data.',\n )\n\n return initialData\n }\n\n const mergedData = await mergeData<T>({\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema: _payloadLivePreview.fieldSchema,\n incomingData: data,\n initialData: _payloadLivePreview?.previousData || initialData,\n locale,\n requestHandler,\n serverURL,\n })\n\n _payloadLivePreview.previousData = mergedData\n\n return mergedData\n }\n\n if (!_payloadLivePreview.previousData) {\n _payloadLivePreview.previousData = initialData\n }\n\n return _payloadLivePreview.previousData as T\n}\n"],"names":["isLivePreviewEvent","mergeData","_payloadLivePreview","fieldSchema","undefined","previousData","handleMessage","args","apiRoute","depth","event","initialData","requestHandler","serverURL","data","externallyUpdatedRelationship","fieldSchemaJSON","locale","console","warn","mergedData","incomingData"],"mappings":"AAIA,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,MAAMC,sBAIF;IACF;;;;;GAKC,GACDC,aAAaC;IACb;;;GAGC,GACDC,cAAcD;AAChB;AAEA,OAAO,MAAME,gBAAgB,OAAsCC;IAQjE,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,WAAW,EAAEC,cAAc,EAAEC,SAAS,EAAE,GAAGN;IAE3E,IAAIP,mBAAmBU,OAAOG,YAAY;QACxC,MAAM,EAAEC,IAAI,EAAEC,6BAA6B,EAAEC,eAAe,EAAEC,MAAM,EAAE,GAAGP,MAAMI,IAAI;QAEnF,IAAI,CAACZ,qBAAqBC,eAAea,iBAAiB;YACxDd,oBAAoBC,WAAW,GAAGa;QACpC;QAEA,IAAI,CAACd,qBAAqBC,aAAa;YACrC,sCAAsC;YACtCe,QAAQC,IAAI,CACV;YAGF,OAAOR;QACT;QAEA,MAAMS,aAAa,MAAMnB,UAAa;YACpCO;YACAC;YACAM;YACAZ,aAAaD,oBAAoBC,WAAW;YAC5CkB,cAAcP;YACdH,aAAaT,qBAAqBG,gBAAgBM;YAClDM;YACAL;YACAC;QACF;QAEAX,oBAAoBG,YAAY,GAAGe;QAEnC,OAAOA;IACT;IAEA,IAAI,CAAClB,oBAAoBG,YAAY,EAAE;QACrCH,oBAAoBG,YAAY,GAAGM;IACrC;IAEA,OAAOT,oBAAoBG,YAAY;AACzC,EAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@payloadcms/live-preview",
|
|
3
|
-
"version": "3.44.0-
|
|
3
|
+
"version": "3.44.0-internal.6b79dc2",
|
|
4
4
|
"description": "The official live preview JavaScript SDK for Payload",
|
|
5
5
|
"homepage": "https://payloadcms.com",
|
|
6
6
|
"repository": {
|
|
@@ -33,7 +33,7 @@
|
|
|
33
33
|
],
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@payloadcms/eslint-config": "3.28.0",
|
|
36
|
-
"payload": "3.44.0-
|
|
36
|
+
"payload": "3.44.0-internal.6b79dc2"
|
|
37
37
|
},
|
|
38
38
|
"publishConfig": {
|
|
39
39
|
"registry": "https://registry.npmjs.org/"
|