@payloadcms/live-preview 3.11.0 → 3.11.1-canary.053fca8

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,7 +1,8 @@
1
+ import type { LivePreviewMessageEvent } from './types.js';
1
2
  export declare const handleMessage: <T>(args: {
2
3
  apiRoute?: string;
3
4
  depth?: number;
4
- event: MessageEvent;
5
+ event: LivePreviewMessageEvent<T>;
5
6
  initialData: T;
6
7
  serverURL: string;
7
8
  }) => Promise<T>;
@@ -1 +1 @@
1
- {"version":3,"file":"handleMessage.d.ts","sourceRoot":"","sources":["../src/handleMessage.ts"],"names":[],"mappings":"AAaA,eAAO,MAAM,aAAa,GAAU,CAAC,QAAQ;IAC3C,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,KAAK,EAAE,YAAY,CAAA;IACnB,WAAW,EAAE,CAAC,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAAO,CAAC,CAAC,CAoCZ,CAAA"}
1
+ {"version":3,"file":"handleMessage.d.ts","sourceRoot":"","sources":["../src/handleMessage.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAoBzD,eAAO,MAAM,aAAa,GAAU,CAAC,QAAQ;IAC3C,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,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAAO,CAAC,CAAC,CAoCZ,CAAA"}
@@ -1,22 +1,25 @@
1
1
  import { isLivePreviewEvent } from './isLivePreviewEvent.js';
2
2
  import { mergeData } from './mergeData.js';
3
- // For performance reasons, `fieldSchemaJSON` will only be sent once on the initial message
4
- // We need to cache this value so that it can be used across subsequent messages
5
- // To do this, save `fieldSchemaJSON` when it arrives as a global variable
6
- // Send this cached value to `mergeData`, instead of `eventData.fieldSchemaJSON` directly
7
- let payloadLivePreviewFieldSchema = undefined // TODO: type this from `fieldSchemaToJSON` return type
8
- ;
9
- // Each time the data is merged, cache the result as a `previousData` variable
10
- // This will ensure changes compound overtop of each other
11
- let payloadLivePreviewPreviousData = undefined;
3
+ const _payloadLivePreview = {
4
+ /**
5
+ * For performance reasons, `fieldSchemaJSON` will only be sent once on the initial message
6
+ * We need to cache this value so that it can be used across subsequent messages
7
+ * To do this, save `fieldSchemaJSON` when it arrives as a global variable
8
+ * Send this cached value to `mergeData`, instead of `eventData.fieldSchemaJSON` directly
9
+ */ fieldSchema: undefined,
10
+ /**
11
+ * Each time the data is merged, cache the result as a `previousData` variable
12
+ * This will ensure changes compound overtop of each other
13
+ */ previousData: undefined
14
+ };
12
15
  export const handleMessage = async (args)=>{
13
16
  const { apiRoute, depth, event, initialData, serverURL } = args;
14
17
  if (isLivePreviewEvent(event, serverURL)) {
15
- const { data, externallyUpdatedRelationship, fieldSchemaJSON } = event.data;
16
- if (!payloadLivePreviewFieldSchema && fieldSchemaJSON) {
17
- payloadLivePreviewFieldSchema = fieldSchemaJSON;
18
+ const { data, externallyUpdatedRelationship, fieldSchemaJSON, locale } = event.data;
19
+ if (!_payloadLivePreview?.fieldSchema && fieldSchemaJSON) {
20
+ _payloadLivePreview.fieldSchema = fieldSchemaJSON;
18
21
  }
19
- if (!payloadLivePreviewFieldSchema) {
22
+ if (!_payloadLivePreview?.fieldSchema) {
20
23
  // eslint-disable-next-line no-console
21
24
  console.warn('Payload Live Preview: No `fieldSchemaJSON` was received from the parent window. Unable to merge data.');
22
25
  return initialData;
@@ -25,13 +28,13 @@ export const handleMessage = async (args)=>{
25
28
  apiRoute,
26
29
  depth,
27
30
  externallyUpdatedRelationship,
28
- fieldSchema: payloadLivePreviewFieldSchema,
31
+ fieldSchema: _payloadLivePreview.fieldSchema,
29
32
  incomingData: data,
30
- initialData: payloadLivePreviewPreviousData || initialData,
31
- locale: event.data.locale,
33
+ initialData: _payloadLivePreview?.previousData || initialData,
34
+ locale,
32
35
  serverURL
33
36
  });
34
- payloadLivePreviewPreviousData = mergedData;
37
+ _payloadLivePreview.previousData = mergedData;
35
38
  return mergedData;
36
39
  }
37
40
  return initialData;
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/handleMessage.ts"],"sourcesContent":["import { isLivePreviewEvent } from './isLivePreviewEvent.js'\nimport { mergeData } from './mergeData.js'\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\nlet payloadLivePreviewFieldSchema = undefined // TODO: type this from `fieldSchemaToJSON` return type\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\nlet payloadLivePreviewPreviousData = undefined\n\nexport const handleMessage = async <T>(args: {\n apiRoute?: string\n depth?: number\n event: MessageEvent\n initialData: T\n serverURL: string\n}): Promise<T> => {\n const { apiRoute, depth, event, initialData, serverURL } = args\n\n if (isLivePreviewEvent(event, serverURL)) {\n const { data, externallyUpdatedRelationship, fieldSchemaJSON } = event.data\n\n if (!payloadLivePreviewFieldSchema && fieldSchemaJSON) {\n payloadLivePreviewFieldSchema = fieldSchemaJSON\n }\n\n if (!payloadLivePreviewFieldSchema) {\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: payloadLivePreviewFieldSchema,\n incomingData: data,\n initialData: payloadLivePreviewPreviousData || initialData,\n locale: event.data.locale,\n serverURL,\n })\n\n payloadLivePreviewPreviousData = mergedData\n\n return mergedData\n }\n\n return initialData\n}\n"],"names":["isLivePreviewEvent","mergeData","payloadLivePreviewFieldSchema","undefined","payloadLivePreviewPreviousData","handleMessage","args","apiRoute","depth","event","initialData","serverURL","data","externallyUpdatedRelationship","fieldSchemaJSON","console","warn","mergedData","fieldSchema","incomingData","locale"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,2FAA2F;AAC3F,gFAAgF;AAChF,0EAA0E;AAC1E,yFAAyF;AACzF,IAAIC,gCAAgCC,UAAU,uDAAuD;;AAErG,8EAA8E;AAC9E,0DAA0D;AAC1D,IAAIC,iCAAiCD;AAErC,OAAO,MAAME,gBAAgB,OAAUC;IAOrC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGL;IAE3D,IAAIN,mBAAmBS,OAAOE,YAAY;QACxC,MAAM,EAAEC,IAAI,EAAEC,6BAA6B,EAAEC,eAAe,EAAE,GAAGL,MAAMG,IAAI;QAE3E,IAAI,CAACV,iCAAiCY,iBAAiB;YACrDZ,gCAAgCY;QAClC;QAEA,IAAI,CAACZ,+BAA+B;YAClC,sCAAsC;YACtCa,QAAQC,IAAI,CACV;YAGF,OAAON;QACT;QAEA,MAAMO,aAAa,MAAMhB,UAAa;YACpCM;YACAC;YACAK;YACAK,aAAahB;YACbiB,cAAcP;YACdF,aAAaN,kCAAkCM;YAC/CU,QAAQX,MAAMG,IAAI,CAACQ,MAAM;YACzBT;QACF;QAEAP,iCAAiCa;QAEjC,OAAOA;IACT;IAEA,OAAOP;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/handleMessage.ts"],"sourcesContent":["import type { LivePreviewMessageEvent } from './types.js'\n\nimport { isLivePreviewEvent } from './isLivePreviewEvent.js'\nimport { mergeData } from './mergeData.js'\n\nconst _payloadLivePreview = {\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>(args: {\n apiRoute?: string\n depth?: number\n event: LivePreviewMessageEvent<T>\n initialData: T\n serverURL: string\n}): Promise<T> => {\n const { apiRoute, depth, event, initialData, 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 serverURL,\n })\n\n _payloadLivePreview.previousData = mergedData\n\n return mergedData\n }\n\n return initialData\n}\n"],"names":["isLivePreviewEvent","mergeData","_payloadLivePreview","fieldSchema","undefined","previousData","handleMessage","args","apiRoute","depth","event","initialData","serverURL","data","externallyUpdatedRelationship","fieldSchemaJSON","locale","console","warn","mergedData","incomingData"],"mappings":"AAEA,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,SAAS,QAAQ,iBAAgB;AAE1C,MAAMC,sBAAsB;IAC1B;;;;;GAKC,GACDC,aAAaC;IACb;;;GAGC,GACDC,cAAcD;AAChB;AAEA,OAAO,MAAME,gBAAgB,OAAUC;IAOrC,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,KAAK,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGL;IAE3D,IAAIP,mBAAmBU,OAAOE,YAAY;QACxC,MAAM,EAAEC,IAAI,EAAEC,6BAA6B,EAAEC,eAAe,EAAEC,MAAM,EAAE,GAAGN,MAAMG,IAAI;QAEnF,IAAI,CAACX,qBAAqBC,eAAeY,iBAAiB;YACxDb,oBAAoBC,WAAW,GAAGY;QACpC;QAEA,IAAI,CAACb,qBAAqBC,aAAa;YACrC,sCAAsC;YACtCc,QAAQC,IAAI,CACV;YAGF,OAAOP;QACT;QAEA,MAAMQ,aAAa,MAAMlB,UAAa;YACpCO;YACAC;YACAK;YACAX,aAAaD,oBAAoBC,WAAW;YAC5CiB,cAAcP;YACdF,aAAaT,qBAAqBG,gBAAgBM;YAClDK;YACAJ;QACF;QAEAV,oBAAoBG,YAAY,GAAGc;QAEnC,OAAOA;IACT;IAEA,OAAOR;AACT,EAAC"}
package/dist/index.d.ts CHANGED
@@ -5,5 +5,6 @@ export { mergeData } from './mergeData.js';
5
5
  export { ready } from './ready.js';
6
6
  export { subscribe } from './subscribe.js';
7
7
  export { traverseRichText } from './traverseRichText.js';
8
+ export type { LivePreviewMessageEvent } from './types.js';
8
9
  export { unsubscribe } from './unsubscribe.js';
9
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAA;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAA;AAClC,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAA;AACxD,YAAY,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAA"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { handleMessage } from './handleMessage.js'\nexport { isDocumentEvent } from './isDocumentEvent.js'\nexport { isLivePreviewEvent } from './isLivePreviewEvent.js'\nexport { mergeData } from './mergeData.js'\nexport { ready } from './ready.js'\nexport { subscribe } from './subscribe.js'\nexport { traverseRichText } from './traverseRichText.js'\nexport { unsubscribe } from './unsubscribe.js'\n"],"names":["handleMessage","isDocumentEvent","isLivePreviewEvent","mergeData","ready","subscribe","traverseRichText","unsubscribe"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAClD,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,gBAAgB,QAAQ,wBAAuB;AACxD,SAASC,WAAW,QAAQ,mBAAkB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { handleMessage } from './handleMessage.js'\nexport { isDocumentEvent } from './isDocumentEvent.js'\nexport { isLivePreviewEvent } from './isLivePreviewEvent.js'\nexport { mergeData } from './mergeData.js'\nexport { ready } from './ready.js'\nexport { subscribe } from './subscribe.js'\nexport { traverseRichText } from './traverseRichText.js'\nexport type { LivePreviewMessageEvent } from './types.js'\nexport { unsubscribe } from './unsubscribe.js'\n"],"names":["handleMessage","isDocumentEvent","isLivePreviewEvent","mergeData","ready","subscribe","traverseRichText","unsubscribe"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAClD,SAASC,eAAe,QAAQ,uBAAsB;AACtD,SAASC,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,KAAK,QAAQ,aAAY;AAClC,SAASC,SAAS,QAAQ,iBAAgB;AAC1C,SAASC,gBAAgB,QAAQ,wBAAuB;AAExD,SAASC,WAAW,QAAQ,mBAAkB"}
@@ -1,5 +1,4 @@
1
- import type { fieldSchemaToJSON } from 'payload/shared';
2
- import type { UpdatedDocument } from './types.js';
1
+ import type { DocumentEvent, FieldSchemaJSON } from 'payload';
3
2
  export declare const mergeData: <T>(args: {
4
3
  apiRoute?: string;
5
4
  collectionPopulationRequestHandler?: ({ apiPath, endpoint, serverURL, }: {
@@ -8,8 +7,8 @@ export declare const mergeData: <T>(args: {
8
7
  serverURL: string;
9
8
  }) => Promise<Response>;
10
9
  depth?: number;
11
- externallyUpdatedRelationship?: UpdatedDocument;
12
- fieldSchema: ReturnType<typeof fieldSchemaToJSON>;
10
+ externallyUpdatedRelationship?: DocumentEvent;
11
+ fieldSchema: FieldSchemaJSON;
13
12
  incomingData: Partial<T>;
14
13
  initialData: T;
15
14
  locale?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"mergeData.d.ts","sourceRoot":"","sources":["../src/mergeData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAE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6B,CAAC,EAAE,aAAa,CAAA;IAC7C,WAAW,EAAE,eAAe,CAAA;IAC5B,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACxB,WAAW,EAAE,CAAC,CAAA;IACd,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAAO,CACT;IACE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,GAAG,CAAC,CAkEN,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mergeData.ts"],"sourcesContent":["import type { PaginatedDocs } from 'payload'\nimport type { fieldSchemaToJSON } from 'payload/shared'\n\nimport type { PopulationsByCollection, UpdatedDocument } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\nconst defaultRequestHandler = ({ apiPath, endpoint, serverURL }) => {\n const url = `${serverURL}${apiPath}/${endpoint}`\n return fetch(url, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n}\n\n// Relationships are only updated when their `id` or `relationTo` changes, by comparing the old and new values\n// This needs to also happen when locale changes, except this is not not part of the API response\n// Instead, we keep track of the old locale ourselves and trigger a re-population when it changes\nlet prevLocale: string | undefined\n\nexport const mergeData = async <T>(args: {\n apiRoute?: string\n collectionPopulationRequestHandler?: ({\n apiPath,\n endpoint,\n serverURL,\n }: {\n apiPath: string\n endpoint: string\n serverURL: string\n }) => Promise<Response>\n depth?: number\n externallyUpdatedRelationship?: UpdatedDocument\n fieldSchema: ReturnType<typeof fieldSchemaToJSON>\n incomingData: Partial<T>\n initialData: T\n locale?: string\n returnNumberOfRequests?: boolean\n serverURL: string\n}): Promise<\n {\n _numberOfRequests?: number\n } & T\n> => {\n const {\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n initialData,\n locale,\n returnNumberOfRequests,\n serverURL,\n } = args\n\n const result = { ...initialData }\n\n const populationsByCollection: PopulationsByCollection = {}\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n localeChanged: prevLocale !== locale,\n populationsByCollection,\n result,\n })\n\n await Promise.all(\n Object.entries(populationsByCollection).map(async ([collection, populations]) => {\n let res: PaginatedDocs\n\n const ids = new Set(populations.map(({ id }) => id))\n const requestHandler = args.collectionPopulationRequestHandler || defaultRequestHandler\n\n try {\n res = await requestHandler({\n apiPath: apiRoute || '/api',\n endpoint: encodeURI(\n `${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,\n ),\n serverURL,\n }).then((res) => res.json())\n\n if (res?.docs?.length > 0) {\n res.docs.forEach((doc) => {\n populationsByCollection[collection].forEach((population) => {\n if (population.id === doc.id) {\n population.ref[population.accessor] = doc\n }\n })\n })\n }\n } catch (err) {\n console.error(err) // eslint-disable-line no-console\n }\n }),\n )\n\n prevLocale = locale\n\n return {\n ...result,\n ...(returnNumberOfRequests\n ? { _numberOfRequests: Object.keys(populationsByCollection).length }\n : {}),\n }\n}\n"],"names":["traverseFields","defaultRequestHandler","apiPath","endpoint","serverURL","url","fetch","credentials","headers","prevLocale","mergeData","args","apiRoute","depth","externallyUpdatedRelationship","fieldSchema","incomingData","initialData","locale","returnNumberOfRequests","result","populationsByCollection","localeChanged","Promise","all","Object","entries","map","collection","populations","res","ids","Set","id","requestHandler","collectionPopulationRequestHandler","encodeURI","Array","from","join","then","json","docs","length","forEach","doc","population","ref","accessor","err","console","error","_numberOfRequests","keys"],"mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,wBAAwB,CAAC,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,SAAS,EAAE;IAC7D,MAAMC,MAAM,GAAGD,YAAYF,QAAQ,CAAC,EAAEC,UAAU;IAChD,OAAOG,MAAMD,KAAK;QAChBE,aAAa;QACbC,SAAS;YACP,gBAAgB;QAClB;IACF;AACF;AAEA,8GAA8G;AAC9G,iGAAiG;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;QACtD;IACF;IAGFxC,aAAaS;IAEb,OAAO;QACL,GAAGE,MAAM;QACT,GAAID,yBACA;YAAEiC,mBAAmB3B,OAAO4B,IAAI,CAAChC,yBAAyBsB,MAAM;QAAC,IACjE,CAAC,CAAC;IACR;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/mergeData.ts"],"sourcesContent":["import type { DocumentEvent, FieldSchemaJSON, PaginatedDocs } from 'payload'\n\nimport type { PopulationsByCollection } from './types.js'\n\nimport { traverseFields } from './traverseFields.js'\n\nconst defaultRequestHandler = ({ apiPath, endpoint, serverURL }) => {\n const url = `${serverURL}${apiPath}/${endpoint}`\n return fetch(url, {\n credentials: 'include',\n headers: {\n 'Content-Type': 'application/json',\n },\n })\n}\n\n// Relationships are only updated when their `id` or `relationTo` changes, by comparing the old and new values\n// This needs to also happen when locale changes, except this is not not part of the API response\n// Instead, we keep track of the old locale ourselves and trigger a re-population when it changes\nlet prevLocale: string | undefined\n\nexport const mergeData = async <T>(args: {\n apiRoute?: string\n collectionPopulationRequestHandler?: ({\n apiPath,\n endpoint,\n serverURL,\n }: {\n apiPath: string\n endpoint: string\n serverURL: string\n }) => Promise<Response>\n depth?: number\n externallyUpdatedRelationship?: DocumentEvent\n fieldSchema: FieldSchemaJSON\n incomingData: Partial<T>\n initialData: T\n locale?: string\n returnNumberOfRequests?: boolean\n serverURL: string\n}): Promise<\n {\n _numberOfRequests?: number\n } & T\n> => {\n const {\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n initialData,\n locale,\n returnNumberOfRequests,\n serverURL,\n } = args\n\n const result = { ...initialData }\n\n const populationsByCollection: PopulationsByCollection = {}\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n localeChanged: prevLocale !== locale,\n populationsByCollection,\n result,\n })\n\n await Promise.all(\n Object.entries(populationsByCollection).map(async ([collection, populations]) => {\n let res: PaginatedDocs\n\n const ids = new Set(populations.map(({ id }) => id))\n const requestHandler = args.collectionPopulationRequestHandler || defaultRequestHandler\n\n try {\n res = await requestHandler({\n apiPath: apiRoute || '/api',\n endpoint: encodeURI(\n `${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,\n ),\n serverURL,\n }).then((res) => res.json())\n\n if (res?.docs?.length > 0) {\n res.docs.forEach((doc) => {\n populationsByCollection[collection].forEach((population) => {\n if (population.id === doc.id) {\n population.ref[population.accessor] = doc\n }\n })\n })\n }\n } catch (err) {\n console.error(err) // eslint-disable-line no-console\n }\n }),\n )\n\n prevLocale = locale\n\n return {\n ...result,\n ...(returnNumberOfRequests\n ? { _numberOfRequests: Object.keys(populationsByCollection).length }\n : {}),\n }\n}\n"],"names":["traverseFields","defaultRequestHandler","apiPath","endpoint","serverURL","url","fetch","credentials","headers","prevLocale","mergeData","args","apiRoute","depth","externallyUpdatedRelationship","fieldSchema","incomingData","initialData","locale","returnNumberOfRequests","result","populationsByCollection","localeChanged","Promise","all","Object","entries","map","collection","populations","res","ids","Set","id","requestHandler","collectionPopulationRequestHandler","encodeURI","Array","from","join","then","json","docs","length","forEach","doc","population","ref","accessor","err","console","error","_numberOfRequests","keys"],"mappings":"AAIA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,wBAAwB,CAAC,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,SAAS,EAAE;IAC7D,MAAMC,MAAM,GAAGD,YAAYF,QAAQ,CAAC,EAAEC,UAAU;IAChD,OAAOG,MAAMD,KAAK;QAChBE,aAAa;QACbC,SAAS;YACP,gBAAgB;QAClB;IACF;AACF;AAEA,8GAA8G;AAC9G,iGAAiG;AACjG,iGAAiG;AACjG,IAAIC;AAEJ,OAAO,MAAMC,YAAY,OAAUC;IAwBjC,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLC,6BAA6B,EAC7BC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,MAAM,EACNC,sBAAsB,EACtBf,SAAS,EACV,GAAGO;IAE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ent } from 'payload';
1
2
  import type { fieldSchemaToJSON } from 'payload/shared';
2
- import type { PopulationsByCollection, UpdatedDocument } from './types.js';
3
+ import type { PopulationsByCollection } from './types.js';
3
4
  export declare const traverseFields: <T>(args: {
4
- externallyUpdatedRelationship?: UpdatedDocument;
5
+ externallyUpdatedRelationship?: DocumentEvent;
5
6
  fieldSchema: ReturnType<typeof fieldSchemaToJSON>;
6
7
  incomingData: T;
7
8
  localeChanged: boolean;
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../src/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAI1E,eAAO,MAAM,cAAc,GAAI,CAAC,QAAQ;IACtC,6BAA6B,CAAC,EAAE,eAAe,CAAA;IAC/C,WAAW,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;IACjD,YAAY,EAAE,CAAC,CAAA;IACf,aAAa,EAAE,OAAO,CAAA;IACtB,uBAAuB,EAAE,uBAAuB,CAAA;IAChD,MAAM,EAAE,CAAC,CAAA;CACV,KAAG,IA6RH,CAAA"}
1
+ {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../src/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAC5C,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAIzD,eAAO,MAAM,cAAc,GAAI,CAAC,QAAQ;IACtC,6BAA6B,CAAC,EAAE,aAAa,CAAA;IAC7C,WAAW,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;IACjD,YAAY,EAAE,CAAC,CAAA;IACf,aAAa,EAAE,OAAO,CAAA;IACtB,uBAAuB,EAAE,uBAAuB,CAAA;IAChD,MAAM,EAAE,CAAC,CAAA;CACV,KAAG,IA6RH,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/traverseFields.ts"],"sourcesContent":["import type { fieldSchemaToJSON } from 'payload/shared'\n\nimport type { PopulationsByCollection, UpdatedDocument } from './types.js'\n\nimport { traverseRichText } from './traverseRichText.js'\n\nexport const traverseFields = <T>(args: {\n externallyUpdatedRelationship?: UpdatedDocument\n fieldSchema: ReturnType<typeof fieldSchemaToJSON>\n incomingData: T\n localeChanged: boolean\n populationsByCollection: PopulationsByCollection\n result: T\n}): void => {\n const {\n externallyUpdatedRelationship,\n fieldSchema: fieldSchemas,\n incomingData,\n localeChanged,\n populationsByCollection,\n result,\n } = args\n\n fieldSchemas.forEach((fieldSchema) => {\n if ('name' in fieldSchema && typeof fieldSchema.name === 'string') {\n const fieldName = fieldSchema.name\n\n switch (fieldSchema.type) {\n case 'array':\n if (\n !incomingData[fieldName] &&\n incomingData[fieldName] !== undefined &&\n result?.[fieldName] !== undefined\n ) {\n result[fieldName] = []\n }\n\n if (Array.isArray(incomingData[fieldName])) {\n result[fieldName] = incomingData[fieldName].map((incomingRow, i) => {\n if (!result[fieldName]) {\n result[fieldName] = []\n }\n\n if (!result[fieldName][i]) {\n result[fieldName][i] = {}\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: fieldSchema.fields,\n incomingData: incomingRow,\n localeChanged,\n populationsByCollection,\n result: result[fieldName][i],\n })\n\n return result[fieldName][i]\n })\n }\n\n break\n\n case 'blocks':\n if (Array.isArray(incomingData[fieldName])) {\n result[fieldName] = incomingData[fieldName].map((incomingBlock, i) => {\n const incomingBlockJSON = fieldSchema.blocks[incomingBlock.blockType]\n\n if (!result[fieldName]) {\n result[fieldName] = []\n }\n\n if (\n !result[fieldName][i] ||\n result[fieldName][i].id !== incomingBlock.id ||\n result[fieldName][i].blockType !== incomingBlock.blockType\n ) {\n result[fieldName][i] = {\n blockType: incomingBlock.blockType,\n }\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: incomingBlockJSON.fields,\n incomingData: incomingBlock,\n localeChanged,\n populationsByCollection,\n result: result[fieldName][i],\n })\n\n return result[fieldName][i]\n })\n } else {\n result[fieldName] = []\n }\n\n break\n\n case 'group':\n // falls through\n case 'tabs':\n if (!result[fieldName]) {\n result[fieldName] = {}\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: fieldSchema.fields,\n incomingData: incomingData[fieldName] || {},\n localeChanged,\n populationsByCollection,\n result: result[fieldName],\n })\n\n break\n\n case 'relationship':\n // falls through\n case 'upload':\n // Handle `hasMany` relationships\n if (fieldSchema.hasMany && Array.isArray(incomingData[fieldName])) {\n if (!result[fieldName] || !incomingData[fieldName].length) {\n result[fieldName] = []\n }\n\n incomingData[fieldName].forEach((incomingRelation, i) => {\n // Handle `hasMany` polymorphic\n if (Array.isArray(fieldSchema.relationTo)) {\n // if the field doesn't exist on the result, create it\n // the value will be populated later\n if (!result[fieldName][i]) {\n result[fieldName][i] = {\n relationTo: incomingRelation.relationTo,\n }\n }\n\n const oldID = result[fieldName][i]?.value?.id\n const oldRelation = result[fieldName][i]?.relationTo\n const newID = incomingRelation.value\n const newRelation = incomingRelation.relationTo\n\n const hasChanged = newID !== oldID || newRelation !== oldRelation\n\n const hasUpdated =\n newRelation === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated || localeChanged) {\n if (!populationsByCollection[newRelation]) {\n populationsByCollection[newRelation] = []\n }\n\n populationsByCollection[newRelation].push({\n id: incomingRelation.value,\n accessor: 'value',\n ref: result[fieldName][i],\n })\n }\n } else {\n // Handle `hasMany` monomorphic\n const hasChanged = incomingRelation !== result[fieldName][i]?.id\n\n const hasUpdated =\n fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&\n incomingRelation === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated || localeChanged) {\n if (!populationsByCollection[fieldSchema.relationTo]) {\n populationsByCollection[fieldSchema.relationTo] = []\n }\n\n populationsByCollection[fieldSchema.relationTo].push({\n id: incomingRelation,\n accessor: i,\n ref: result[fieldName],\n })\n }\n }\n })\n } else {\n // Handle `hasOne` polymorphic\n if (Array.isArray(fieldSchema.relationTo)) {\n // if the field doesn't exist on the result, create it\n // the value will be populated later\n if (!result[fieldName]) {\n result[fieldName] = {\n relationTo: incomingData[fieldName]?.relationTo,\n }\n }\n\n const hasNewValue =\n incomingData[fieldName] &&\n typeof incomingData[fieldName] === 'object' &&\n incomingData[fieldName] !== null\n\n const hasOldValue =\n result[fieldName] &&\n typeof result[fieldName] === 'object' &&\n result[fieldName] !== null\n\n const newID = hasNewValue\n ? typeof incomingData[fieldName].value === 'object'\n ? incomingData[fieldName].value.id\n : incomingData[fieldName].value\n : ''\n\n const oldID = hasOldValue\n ? typeof result[fieldName].value === 'object'\n ? result[fieldName].value.id\n : result[fieldName].value\n : ''\n\n const newRelation = hasNewValue ? incomingData[fieldName].relationTo : ''\n const oldRelation = hasOldValue ? result[fieldName].relationTo : ''\n\n const hasChanged = newID !== oldID || newRelation !== oldRelation\n\n const hasUpdated =\n newRelation === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n // if the new value/relation is different from the old value/relation\n // populate the new value, otherwise leave it alone\n if (hasChanged || hasUpdated || localeChanged) {\n // if the new value is not empty, populate it\n // otherwise set the value to null\n if (newID) {\n if (!populationsByCollection[newRelation]) {\n populationsByCollection[newRelation] = []\n }\n\n populationsByCollection[newRelation].push({\n id: newID,\n accessor: 'value',\n ref: result[fieldName],\n })\n } else {\n result[fieldName] = null\n }\n }\n } else {\n // Handle `hasOne` monomorphic\n const newID: number | string | undefined =\n (incomingData[fieldName] &&\n typeof incomingData[fieldName] === 'object' &&\n incomingData[fieldName].id) ||\n incomingData[fieldName]\n\n const oldID: number | string | undefined =\n (result[fieldName] &&\n typeof result[fieldName] === 'object' &&\n result[fieldName].id) ||\n result[fieldName]\n\n const hasChanged = newID !== oldID\n\n const hasUpdated =\n fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n // if the new value is different from the old value\n // populate the new value, otherwise leave it alone\n if (hasChanged || hasUpdated || localeChanged) {\n // if the new value is not empty, populate it\n // otherwise set the value to null\n if (newID) {\n if (!populationsByCollection[fieldSchema.relationTo]) {\n populationsByCollection[fieldSchema.relationTo] = []\n }\n\n populationsByCollection[fieldSchema.relationTo].push({\n id: newID,\n accessor: fieldName,\n ref: result as Record<string, unknown>,\n })\n } else {\n result[fieldName] = null\n }\n }\n }\n }\n\n break\n case 'richText':\n result[fieldName] = traverseRichText({\n externallyUpdatedRelationship,\n incomingData: incomingData[fieldName],\n populationsByCollection,\n result: result[fieldName],\n })\n\n break\n\n default:\n result[fieldName] = incomingData[fieldName]\n }\n }\n })\n}\n"],"names":["traverseRichText","traverseFields","args","externallyUpdatedRelationship","fieldSchema","fieldSchemas","incomingData","localeChanged","populationsByCollection","result","forEach","name","fieldName","type","undefined","Array","isArray","map","incomingRow","i","fields","incomingBlock","incomingBlockJSON","blocks","blockType","id","hasMany","length","incomingRelation","relationTo","oldID","value","oldRelation","newID","newRelation","hasChanged","hasUpdated","entitySlug","push","accessor","ref","hasNewValue","hasOldValue"],"mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AAExD,OAAO,MAAMC,iBAAiB,CAAIC;IAQhC,MAAM,EACJC,6BAA6B,EAC7BC,aAAaC,YAAY,EACzBC,YAAY,EACZC,aAAa,EACbC,uBAAuB,EACvBC,MAAM,EACP,GAAGP;IAEJG,aAAaK,OAAO,CAAC,CAACN;QACpB,IAAI,UAAUA,eAAe,OAAOA,YAAYO,IAAI,KAAK,UAAU;YACjE,MAAMC,YAAYR,YAAYO,IAAI;YAElC,OAAQP,YAAYS,IAAI;gBACtB,KAAK;oBACH,IACE,CAACP,YAAY,CAACM,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{ DocumentEvent } from 'payload'\nimport type { fieldSchemaToJSON } from 'payload/shared'\n\nimport type { PopulationsByCollection } from './types.js'\n\nimport { traverseRichText } from './traverseRichText.js'\n\nexport const traverseFields = <T>(args: {\n externallyUpdatedRelationship?: DocumentEvent\n fieldSchema: ReturnType<typeof fieldSchemaToJSON>\n incomingData: T\n localeChanged: boolean\n populationsByCollection: PopulationsByCollection\n result: T\n}): void => {\n const {\n externallyUpdatedRelationship,\n fieldSchema: fieldSchemas,\n incomingData,\n localeChanged,\n populationsByCollection,\n result,\n } = args\n\n fieldSchemas.forEach((fieldSchema) => {\n if ('name' in fieldSchema && typeof fieldSchema.name === 'string') {\n const fieldName = fieldSchema.name\n\n switch (fieldSchema.type) {\n case 'array':\n if (\n !incomingData[fieldName] &&\n incomingData[fieldName] !== undefined &&\n result?.[fieldName] !== undefined\n ) {\n result[fieldName] = []\n }\n\n if (Array.isArray(incomingData[fieldName])) {\n result[fieldName] = incomingData[fieldName].map((incomingRow, i) => {\n if (!result[fieldName]) {\n result[fieldName] = []\n }\n\n if (!result[fieldName][i]) {\n result[fieldName][i] = {}\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: fieldSchema.fields,\n incomingData: incomingRow,\n localeChanged,\n populationsByCollection,\n result: result[fieldName][i],\n })\n\n return result[fieldName][i]\n })\n }\n\n break\n\n case 'blocks':\n if (Array.isArray(incomingData[fieldName])) {\n result[fieldName] = incomingData[fieldName].map((incomingBlock, i) => {\n const incomingBlockJSON = fieldSchema.blocks[incomingBlock.blockType]\n\n if (!result[fieldName]) {\n result[fieldName] = []\n }\n\n if (\n !result[fieldName][i] ||\n result[fieldName][i].id !== incomingBlock.id ||\n result[fieldName][i].blockType !== incomingBlock.blockType\n ) {\n result[fieldName][i] = {\n blockType: incomingBlock.blockType,\n }\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: incomingBlockJSON.fields,\n incomingData: incomingBlock,\n localeChanged,\n populationsByCollection,\n result: result[fieldName][i],\n })\n\n return result[fieldName][i]\n })\n } else {\n result[fieldName] = []\n }\n\n break\n\n case 'group':\n // falls through\n case 'tabs':\n if (!result[fieldName]) {\n result[fieldName] = {}\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: fieldSchema.fields,\n incomingData: incomingData[fieldName] || {},\n localeChanged,\n populationsByCollection,\n result: result[fieldName],\n })\n\n break\n\n case 'relationship':\n // falls through\n case 'upload':\n // Handle `hasMany` relationships\n if (fieldSchema.hasMany && Array.isArray(incomingData[fieldName])) {\n if (!result[fieldName] || !incomingData[fieldName].length) {\n result[fieldName] = []\n }\n\n incomingData[fieldName].forEach((incomingRelation, i) => {\n // Handle `hasMany` polymorphic\n if (Array.isArray(fieldSchema.relationTo)) {\n // if the field doesn't exist on the result, create it\n // the value will be populated later\n if (!result[fieldName][i]) {\n result[fieldName][i] = {\n relationTo: incomingRelation.relationTo,\n }\n }\n\n const oldID = result[fieldName][i]?.value?.id\n const oldRelation = result[fieldName][i]?.relationTo\n const newID = incomingRelation.value\n const newRelation = incomingRelation.relationTo\n\n const hasChanged = newID !== oldID || newRelation !== oldRelation\n\n const hasUpdated =\n newRelation === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated || localeChanged) {\n if (!populationsByCollection[newRelation]) {\n populationsByCollection[newRelation] = []\n }\n\n populationsByCollection[newRelation].push({\n id: incomingRelation.value,\n accessor: 'value',\n ref: result[fieldName][i],\n })\n }\n } else {\n // Handle `hasMany` monomorphic\n const hasChanged = incomingRelation !== result[fieldName][i]?.id\n\n const hasUpdated =\n fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&\n incomingRelation === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated || localeChanged) {\n if (!populationsByCollection[fieldSchema.relationTo]) {\n populationsByCollection[fieldSchema.relationTo] = []\n }\n\n populationsByCollection[fieldSchema.relationTo].push({\n id: incomingRelation,\n accessor: i,\n ref: result[fieldName],\n })\n }\n }\n })\n } else {\n // Handle `hasOne` polymorphic\n if (Array.isArray(fieldSchema.relationTo)) {\n // if the field doesn't exist on the result, create it\n // the value will be populated later\n if (!result[fieldName]) {\n result[fieldName] = {\n relationTo: incomingData[fieldName]?.relationTo,\n }\n }\n\n const hasNewValue =\n incomingData[fieldName] &&\n typeof incomingData[fieldName] === 'object' &&\n incomingData[fieldName] !== null\n\n const hasOldValue =\n result[fieldName] &&\n typeof result[fieldName] === 'object' &&\n result[fieldName] !== null\n\n const newID = hasNewValue\n ? typeof incomingData[fieldName].value === 'object'\n ? incomingData[fieldName].value.id\n : incomingData[fieldName].value\n : ''\n\n const oldID = hasOldValue\n ? typeof result[fieldName].value === 'object'\n ? result[fieldName].value.id\n : result[fieldName].value\n : ''\n\n const newRelation = hasNewValue ? incomingData[fieldName].relationTo : ''\n const oldRelation = hasOldValue ? result[fieldName].relationTo : ''\n\n const hasChanged = newID !== oldID || newRelation !== oldRelation\n\n const hasUpdated =\n newRelation === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n // if the new value/relation is different from the old value/relation\n // populate the new value, otherwise leave it alone\n if (hasChanged || hasUpdated || localeChanged) {\n // if the new value is not empty, populate it\n // otherwise set the value to null\n if (newID) {\n if (!populationsByCollection[newRelation]) {\n populationsByCollection[newRelation] = []\n }\n\n populationsByCollection[newRelation].push({\n id: newID,\n accessor: 'value',\n ref: result[fieldName],\n })\n } else {\n result[fieldName] = null\n }\n }\n } else {\n // Handle `hasOne` monomorphic\n const newID: number | string | undefined =\n (incomingData[fieldName] &&\n typeof incomingData[fieldName] === 'object' &&\n incomingData[fieldName].id) ||\n incomingData[fieldName]\n\n const oldID: number | string | undefined =\n (result[fieldName] &&\n typeof result[fieldName] === 'object' &&\n result[fieldName].id) ||\n result[fieldName]\n\n const hasChanged = newID !== oldID\n\n const hasUpdated =\n fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n // if the new value is different from the old value\n // populate the new value, otherwise leave it alone\n if (hasChanged || hasUpdated || localeChanged) {\n // if the new value is not empty, populate it\n // otherwise set the value to null\n if (newID) {\n if (!populationsByCollection[fieldSchema.relationTo]) {\n populationsByCollection[fieldSchema.relationTo] = []\n }\n\n populationsByCollection[fieldSchema.relationTo].push({\n id: newID,\n accessor: fieldName,\n ref: result as Record<string, unknown>,\n })\n } else {\n result[fieldName] = null\n }\n }\n }\n }\n\n break\n case 'richText':\n result[fieldName] = traverseRichText({\n externallyUpdatedRelationship,\n incomingData: incomingData[fieldName],\n populationsByCollection,\n result: result[fieldName],\n })\n\n break\n\n default:\n result[fieldName] = incomingData[fieldName]\n }\n }\n })\n}\n"],"names":["traverseRichText","traverseFields","args","externallyUpdatedRelationship","fieldSchema","fieldSchemas","incomingData","localeChanged","populationsByCollection","result","forEach","name","fieldName","type","undefined","Array","isArray","map","incomingRow","i","fields","incomingBlock","incomingBlockJSON","blocks","blockType","id","hasMany","length","incomingRelation","relationTo","oldID","value","oldRelation","newID","newRelation","hasChanged","hasUpdated","entitySlug","push","accessor","ref","hasNewValue","hasOldValue"],"mappings":"AAKA,SAASA,gBAAgB,QAAQ,wBAAuB;AAExD,OAAO,MAAMC,iBAAiB,CAAIC;IAQhC,MAAM,EACJC,6BAA6B,EAC7BC,aAAaC,YAAY,EACzBC,YAAY,EACZC,aAAa,EACbC,uBAAuB,EACvBC,MAAM,EACP,GAAGP;IAEJG,aAAaK,OAAO,CAAC,CAACN;QACpB,IAAI,UAAUA,eAAe,OAAOA,YAAYO,IAAI,KAAK,UAAU;YACjE,MAAMC,YAAYR,YAAYO,IAAI;YAElC,OAAQP,YAAYS,IAAI;gBACtB,KAAK;oBACH,IACE,CAACP,YAAY,CAACM,UAAU,IACxBN,YAAY,CAACM,UAAU,KAAKE,aAC5BL,QAAQ,CAACG,UAAU,KAAKE,WACxB;wBACAL,MAAM,CAACG,UAAU,GAAG,EAAE;oBACxB;oBAEA,IAAIG,MAAMC,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AAY,CAACM,UAAU,KAAK,YACnCN,YAAY,CAACM,UAAU,CAACa,EAAE,IAC5BnB,YAAY,CAACM,UAAU;4BAEzB,MAAMkB,QACJ,AAACrB,MAAM,CAACG,UAAU,IAChB,OAAOH,MAAM,CAACG,UAAU,KAAK,YAC7BH,MAAM,CAACG,UAAU,CAACa,EAAE,IACtBhB,MAAM,CAACG,UAAU;4BAEnB,MAAMuB,aAAaF,UAAUH;4BAE7B,MAAMM,aACJhC,YAAYyB,UAAU,KAAK1B,+BAA+BkC,cAC1DJ,UAAU9B,+BAA+BsB;4BAE3C,mDAAmD;4BACnD,mDAAmD;4BACnD,IAAIU,cAAcC,cAAc7B,eAAe;gCAC7C,6CAA6C;gCAC7C,kCAAkC;gCAClC,IAAI0B,OAAO;oCACT,IAAI,CAACzB,uBAAuB,CAACJ,YAAYyB,UAAU,CAAC,EAAE;wCACpDrB,uBAAuB,CAACJ,YAAYyB,UAAU,CAAC,GAAG,EAAE;oCACtD;oCAEArB,uBAAuB,CAACJ,YAAYyB,UAAU,CAAC,CAACS,IAAI,CAAC;wCACnDb,IAAIQ;wCACJM,UAAU3B;wCACV4B,KAAK/B;oCACP;gCACF,OAAO;oCACLA,MAAM,CAACG,UAAU,GAAG;gCACtB;4BACF;wBACF;oBACF;oBAEA;gBACF,KAAK;oBACHH,MAAM,CAACG,UAAU,GAAGZ,iBAAiB;wBACnCG;wBACAG,cAAcA,YAAY,CAACM,UAAU;wBACrCJ;wBACAC,QAAQA,MAAM,CAACG,UAAU;oBAC3B;oBAEA;gBAEF;oBACEH,MAAM,CAACG,UAAU,GAAGN,YAAY,CAACM,UAAU;YAC/C;QACF;IACF;AACF,EAAC"}
@@ -1,6 +1,7 @@
1
- import type { PopulationsByCollection, UpdatedDocument } from './types.js';
1
+ import type { DocumentEvent } from 'payload';
2
+ import type { PopulationsByCollection } from './types.js';
2
3
  export declare const traverseRichText: ({ externallyUpdatedRelationship, incomingData, populationsByCollection, result, }: {
3
- externallyUpdatedRelationship?: UpdatedDocument;
4
+ externallyUpdatedRelationship?: DocumentEvent;
4
5
  incomingData: any;
5
6
  populationsByCollection: PopulationsByCollection;
6
7
  result: any;
@@ -1 +1 @@
1
- {"version":3,"file":"traverseRichText.d.ts","sourceRoot":"","sources":["../src/traverseRichText.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE1E,eAAO,MAAM,gBAAgB,sFAK1B;IACD,6BAA6B,CAAC,EAAE,eAAe,CAAA;IAC/C,YAAY,EAAE,GAAG,CAAA;IACjB,uBAAuB,EAAE,uBAAuB,CAAA;IAChD,MAAM,EAAE,GAAG,CAAA;CACZ,KAAG,GA0FH,CAAA"}
1
+ {"version":3,"file":"traverseRichText.d.ts","sourceRoot":"","sources":["../src/traverseRichText.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,SAAS,CAAA;AAE5C,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,YAAY,CAAA;AAEzD,eAAO,MAAM,gBAAgB,sFAK1B;IACD,6BAA6B,CAAC,EAAE,aAAa,CAAA;IAC7C,YAAY,EAAE,GAAG,CAAA;IACjB,uBAAuB,EAAE,uBAAuB,CAAA;IAChD,MAAM,EAAE,GAAG,CAAA;CACZ,KAAG,GA0FH,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/traverseRichText.ts"],"sourcesContent":["import type { PopulationsByCollection, UpdatedDocument } from './types.js'\n\nexport const traverseRichText = ({\n externallyUpdatedRelationship,\n incomingData,\n populationsByCollection,\n result,\n}: {\n externallyUpdatedRelationship?: UpdatedDocument\n incomingData: any\n populationsByCollection: PopulationsByCollection\n result: any\n}): any => {\n if (Array.isArray(incomingData)) {\n if (!result) {\n result = []\n }\n\n result = incomingData.map((item, index) => {\n if (!result[index]) {\n result[index] = item\n }\n\n return traverseRichText({\n externallyUpdatedRelationship,\n incomingData: item,\n populationsByCollection,\n result: result[index],\n })\n })\n } else if (incomingData && typeof incomingData === 'object') {\n if (!result) {\n result = {}\n }\n\n // Remove keys from `result` that do not appear in `incomingData`\n // There's likely another way to do this,\n // But recursion and references make this very difficult\n Object.keys(result).forEach((key) => {\n if (!(key in incomingData)) {\n delete result[key]\n }\n })\n\n // Iterate over the keys of `incomingData` and populate `result`\n Object.keys(incomingData).forEach((key) => {\n if (!result[key]) {\n // Instantiate the key in `result` if it doesn't exist\n // Ensure its type matches the type of the `incomingData`\n // We don't have a schema to check against here\n result[key] =\n incomingData[key] && typeof incomingData[key] === 'object'\n ? Array.isArray(incomingData[key])\n ? []\n : {}\n : undefined\n }\n\n const isRelationship = key === 'value' && 'relationTo' in incomingData\n\n if (isRelationship) {\n // or if there are no keys besides id\n const needsPopulation =\n !result.value ||\n typeof result.value !== 'object' ||\n (typeof result.value === 'object' &&\n Object.keys(result.value).length === 1 &&\n 'id' in result.value)\n\n const hasChanged =\n result &&\n typeof result === 'object' &&\n result.value.id === externallyUpdatedRelationship?.id\n\n if (needsPopulation || hasChanged) {\n if (!populationsByCollection[incomingData.relationTo]) {\n populationsByCollection[incomingData.relationTo] = []\n }\n\n populationsByCollection[incomingData.relationTo].push({\n id:\n incomingData[key] && typeof incomingData[key] === 'object'\n ? incomingData[key].id\n : incomingData[key],\n accessor: 'value',\n ref: result,\n })\n }\n } else {\n result[key] = traverseRichText({\n externallyUpdatedRelationship,\n incomingData: incomingData[key],\n populationsByCollection,\n result: result[key],\n })\n }\n })\n } else {\n result = incomingData\n }\n\n return result\n}\n"],"names":["traverseRichText","externallyUpdatedRelationship","incomingData","populationsByCollection","result","Array","isArray","map","item","index","Object","keys","forEach","key","undefined","isRelationship","needsPopulation","value","length","hasChanged","id","relationTo","push","accessor","ref"],"mappings":"AAEA,OAAO,MAAMA,mBAAmB,CAAC,EAC/BC,6BAA6B,EAC7BC,YAAY,EACZC,uBAAuB,EACvBC,MAAM,EAMP;IACC,IAAIC,MAAMC,OAAO,CAACJ,eAAe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KAAKnB,+BAA+BmB;gBAErD,IAAIJ,mBAAmBG,YAAY;oBACjC,IAAI,CAAChB,uBAAuB,CAACD,aAAamB,UAAU,CAAC,EAAE;wBACrDlB,uBAAuB,CAACD,aAAamB,UAAU,CAAC,GAAG,EAAE;oBACvD;oBAEAlB,uBAAuB,CAACD,aAAamB,UAAU,CAAC,CAACC,IAAI,CAAC;wBACpDF,IACElB,YAAY,CAACW,IAAI,IAAI,OAAOX,YAAY,CAACW,IAAI,KAAK,WAC9CX,YAAY,CAACW,IAAI,CAACO,EAAE,GACpBlB,YAAY,CAACW,IAAI;wBACvBU,UAAU;wBACVC,KAAKpB;oBACP;gBACF;YACF,OAAO;gBACLA,MAAM,CAACS,IAAI,GAAGb,iBAAiB;oBAC7BC;oBACAC,cAAcA,YAAY,CAACW,IAAI;oBAC/BV;oBACAC,QAAQA,MAAM,CAACS,IAAI;gBACrB;YACF;QACF;IACF,OAAO;QACLT,SAASF;IACX;IAEA,OAAOE;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/traverseRichText.ts"],"sourcesContent":["import type { DocumentEvent } from 'payload'\n\nimport type { PopulationsByCollection } from './types.js'\n\nexport const traverseRichText = ({\n externallyUpdatedRelationship,\n incomingData,\n populationsByCollection,\n result,\n}: {\n externallyUpdatedRelationship?: DocumentEvent\n incomingData: any\n populationsByCollection: PopulationsByCollection\n result: any\n}): any => {\n if (Array.isArray(incomingData)) {\n if (!result) {\n result = []\n }\n\n result = incomingData.map((item, index) => {\n if (!result[index]) {\n result[index] = item\n }\n\n return traverseRichText({\n externallyUpdatedRelationship,\n incomingData: item,\n populationsByCollection,\n result: result[index],\n })\n })\n } else if (incomingData && typeof incomingData === 'object') {\n if (!result) {\n result = {}\n }\n\n // Remove keys from `result` that do not appear in `incomingData`\n // There's likely another way to do this,\n // But recursion and references make this very difficult\n Object.keys(result).forEach((key) => {\n if (!(key in incomingData)) {\n delete result[key]\n }\n })\n\n // Iterate over the keys of `incomingData` and populate `result`\n Object.keys(incomingData).forEach((key) => {\n if (!result[key]) {\n // Instantiate the key in `result` if it doesn't exist\n // Ensure its type matches the type of the `incomingData`\n // We don't have a schema to check against here\n result[key] =\n incomingData[key] && typeof incomingData[key] === 'object'\n ? Array.isArray(incomingData[key])\n ? []\n : {}\n : undefined\n }\n\n const isRelationship = key === 'value' && 'relationTo' in incomingData\n\n if (isRelationship) {\n // or if there are no keys besides id\n const needsPopulation =\n !result.value ||\n typeof result.value !== 'object' ||\n (typeof result.value === 'object' &&\n Object.keys(result.value).length === 1 &&\n 'id' in result.value)\n\n const hasChanged =\n result &&\n typeof result === 'object' &&\n result.value.id === externallyUpdatedRelationship?.id\n\n if (needsPopulation || hasChanged) {\n if (!populationsByCollection[incomingData.relationTo]) {\n populationsByCollection[incomingData.relationTo] = []\n }\n\n populationsByCollection[incomingData.relationTo].push({\n id:\n incomingData[key] && typeof incomingData[key] === 'object'\n ? incomingData[key].id\n : incomingData[key],\n accessor: 'value',\n ref: result,\n })\n }\n } else {\n result[key] = traverseRichText({\n externallyUpdatedRelationship,\n incomingData: incomingData[key],\n populationsByCollection,\n result: result[key],\n })\n }\n })\n } else {\n result = incomingData\n }\n\n return result\n}\n"],"names":["traverseRichText","externallyUpdatedRelationship","incomingData","populationsByCollection","result","Array","isArray","map","item","index","Object","keys","forEach","key","undefined","isRelationship","needsPopulation","value","length","hasChanged","id","relationTo","push","accessor","ref"],"mappings":"AAIA,OAAO,MAAMA,mBAAmB,CAAC,EAC/BC,6BAA6B,EAC7BC,YAAY,EACZC,uBAAuB,EACvBC,MAAM,EAMP;IACC,IAAIC,MAAMC,OAAO,CAACJ,eAAe;QAC/B,IAAI,CAACE,QAAQ;YACXA,SAAS,EAAE;QACb;QAEAA,SAASF,aAAaK,GAAG,CAAC,CAACC,MAAMC;YAC/B,IAAI,CAACL,MAAM,CAACK,MAAM,EAAE;gBAClBL,MAAM,CAACK,MAAM,GAAGD;YAClB;YAEA,OAAOR,iBAAiB;gBACtBC;gBACAC,cAAcM;gB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I,CAAC;wBACpDF,IACElB,YAAY,CAACW,IAAI,IAAI,OAAOX,YAAY,CAACW,IAAI,KAAK,WAC9CX,YAAY,CAACW,IAAI,CAACO,EAAE,GACpBlB,YAAY,CAACW,IAAI;wBACvBU,UAAU;wBACVC,KAAKpB;oBACP;gBACF;YACF,OAAO;gBACLA,MAAM,CAACS,IAAI,GAAGb,iBAAiB;oBAC7BC;oBACAC,cAAcA,YAAY,CAACW,IAAI;oBAC/BV;oBACAC,QAAQA,MAAM,CAACS,IAAI;gBACrB;YACF;QACF;IACF,OAAO;QACLT,SAASF;IACX;IAEA,OAAOE;AACT,EAAC"}
package/dist/types.d.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import type { DocumentEvent, FieldSchemaJSON } from 'payload';
1
2
  export type LivePreviewArgs = {};
2
3
  export type LivePreview = void;
3
4
  export type PopulationsByCollection = {
@@ -7,9 +8,11 @@ export type PopulationsByCollection = {
7
8
  ref: Record<string, unknown>;
8
9
  }>;
9
10
  };
10
- export type UpdatedDocument = {
11
- entitySlug: string;
12
- id?: number | string;
13
- updatedAt: string;
14
- };
11
+ export type LivePreviewMessageEvent<T> = MessageEvent<{
12
+ data: T;
13
+ externallyUpdatedRelationship?: DocumentEvent;
14
+ fieldSchemaJSON: FieldSchemaJSON;
15
+ locale?: string;
16
+ type: 'payload-live-preview';
17
+ }>;
15
18
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,EAAE,CAAA;AAEhC,MAAM,MAAM,WAAW,GAAG,IAAI,CAAA;AAE9B,MAAM,MAAM,uBAAuB,GAAG;IACpC,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;QACpB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;QACzB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;QACnB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC7B,CAAC,CAAA;CACH,CAAA;AAGD,MAAM,MAAM,eAAe,GAAG;IAC5B,UAAU,EAAE,MAAM,CAAA;IAClB,EAAE,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACpB,SAAS,EAAE,MAAM,CAAA;CAClB,CAAA"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,SAAS,CAAA;AAE7D,MAAM,MAAM,eAAe,GAAG,EAAE,CAAA;AAEhC,MAAM,MAAM,WAAW,GAAG,IAAI,CAAA;AAE9B,MAAM,MAAM,uBAAuB,GAAG;IACpC,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,CAAC;QACpB,QAAQ,EAAE,MAAM,GAAG,MAAM,CAAA;QACzB,EAAE,EAAE,MAAM,GAAG,MAAM,CAAA;QACnB,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;KAC7B,CAAC,CAAA;CACH,CAAA;AAED,MAAM,MAAM,uBAAuB,CAAC,CAAC,IAAI,YAAY,CAAC;IACpD,IAAI,EAAE,CAAC,CAAA;IACP,6BAA6B,CAAC,EAAE,aAAa,CAAA;IAC7C,eAAe,EAAE,eAAe,CAAA;IAChC,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,sBAAsB,CAAA;CAC7B,CAAC,CAAA"}
package/dist/types.js CHANGED
@@ -1,4 +1,3 @@
1
- // TODO: import this from `payload/admin/components/utilities/DocumentEvents/types.ts`
2
1
  export { };
3
2
 
4
3
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/types.ts"],"sourcesContent":["export type LivePreviewArgs = {}\n\nexport type LivePreview = void\n\nexport type PopulationsByCollection = {\n [slug: string]: Array<{\n accessor: number | string\n id: number | string\n ref: Record<string, unknown>\n }>\n}\n\n// TODO: import this from `payload/admin/components/utilities/DocumentEvents/types.ts`\nexport type UpdatedDocument = {\n entitySlug: string\n id?: number | string\n updatedAt: string\n}\n"],"names":[],"mappings":"AAYA,sFAAsF;AACtF,WAIC"}
1
+ {"version":3,"sources":["../src/types.ts"],"sourcesContent":["import type { DocumentEvent, FieldSchemaJSON } from 'payload'\n\nexport type LivePreviewArgs = {}\n\nexport type LivePreview = void\n\nexport type PopulationsByCollection = {\n [slug: string]: Array<{\n accessor: number | string\n id: number | string\n ref: Record<string, unknown>\n }>\n}\n\nexport type LivePreviewMessageEvent<T> = MessageEvent<{\n data: T\n externallyUpdatedRelationship?: DocumentEvent\n fieldSchemaJSON: FieldSchemaJSON\n locale?: string\n type: 'payload-live-preview'\n}>\n"],"names":[],"mappings":"AAcA,WAME"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/live-preview",
3
- "version": "3.11.0",
3
+ "version": "3.11.1-canary.053fca8",
4
4
  "description": "The official live preview JavaScript SDK for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -32,7 +32,7 @@
32
32
  ],
33
33
  "devDependencies": {
34
34
  "@payloadcms/eslint-config": "3.9.0",
35
- "payload": "3.11.0"
35
+ "payload": "3.11.1-canary.053fca8"
36
36
  },
37
37
  "publishConfig": {
38
38
  "registry": "https://registry.npmjs.org/"
@@ -41,7 +41,7 @@
41
41
  "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
42
42
  "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
43
43
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
44
- "clean": "rimraf {dist,*.tsbuildinfo}",
44
+ "clean": "rimraf -g {dist,*.tsbuildinfo}",
45
45
  "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
46
46
  "lint": "eslint .",
47
47
  "lint:fix": "eslint . --fix"