@payloadcms/live-preview 3.0.0-canary.f6e77b8 → 3.0.0-canary.fb04843

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":"AAaA,eAAO,MAAM,aAAa,YAAmB;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,QAAQ,CAAC,CAmCZ,CAAA"}
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,CAmCZ,CAAA"}
@@ -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 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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","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/CC;QACF;QAEAP,iCAAiCa;QAEjC,OAAOA;IACT;IAEA,OAAOP;AACT,EAAC"}
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 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"],"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/CC;QACF;QAEAP,iCAAiCa;QAEjC,OAAOA;IACT;IAEA,OAAOP;AACT,EAAC"}
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"],"rangeMappings":";;;;;;;","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 { 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 +1 @@
1
- {"version":3,"sources":["../src/isDocumentEvent.ts"],"sourcesContent":["export const isDocumentEvent = (event: MessageEvent, serverURL: string): boolean =>\n event.origin === serverURL &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-document-event'\n"],"names":["isDocumentEvent","event","serverURL","origin","data","type"],"rangeMappings":"","mappings":"AAAA,OAAO,MAAMA,kBAAkB,CAACC,OAAqBC,YACnDD,MAAME,MAAM,KAAKD,aACjBD,MAAMG,IAAI,IACV,OAAOH,MAAMG,IAAI,KAAK,YACtBH,MAAMG,IAAI,CAACC,IAAI,KAAK,yBAAwB"}
1
+ {"version":3,"sources":["../src/isDocumentEvent.ts"],"sourcesContent":["export const isDocumentEvent = (event: MessageEvent, serverURL: string): boolean =>\n event.origin === serverURL &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-document-event'\n"],"names":["isDocumentEvent","event","serverURL","origin","data","type"],"mappings":"AAAA,OAAO,MAAMA,kBAAkB,CAACC,OAAqBC,YACnDD,MAAME,MAAM,KAAKD,aACjBD,MAAMG,IAAI,IACV,OAAOH,MAAMG,IAAI,KAAK,YACtBH,MAAMG,IAAI,CAACC,IAAI,KAAK,yBAAwB"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/isLivePreviewEvent.ts"],"sourcesContent":["export const isLivePreviewEvent = (event: MessageEvent, serverURL: string): boolean =>\n event.origin === serverURL &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n"],"names":["isLivePreviewEvent","event","serverURL","origin","data","type"],"rangeMappings":"","mappings":"AAAA,OAAO,MAAMA,qBAAqB,CAACC,OAAqBC,YACtDD,MAAME,MAAM,KAAKD,aACjBD,MAAMG,IAAI,IACV,OAAOH,MAAMG,IAAI,KAAK,YACtBH,MAAMG,IAAI,CAACC,IAAI,KAAK,uBAAsB"}
1
+ {"version":3,"sources":["../src/isLivePreviewEvent.ts"],"sourcesContent":["export const isLivePreviewEvent = (event: MessageEvent, serverURL: string): boolean =>\n event.origin === serverURL &&\n event.data &&\n typeof event.data === 'object' &&\n event.data.type === 'payload-live-preview'\n"],"names":["isLivePreviewEvent","event","serverURL","origin","data","type"],"mappings":"AAAA,OAAO,MAAMA,qBAAqB,CAACC,OAAqBC,YACtDD,MAAME,MAAM,KAAKD,aACjBD,MAAMG,IAAI,IACV,OAAOH,MAAMG,IAAI,KAAK,YACtBH,MAAMG,IAAI,CAACC,IAAI,KAAK,uBAAsB"}
@@ -1,4 +1,4 @@
1
- import type { fieldSchemaToJSON } from 'payload/utilities';
1
+ import type { fieldSchemaToJSON } from 'payload/shared';
2
2
  import type { UpdatedDocument } from './types.js';
3
3
  export declare const mergeData: <T>(args: {
4
4
  apiRoute?: string;
@@ -14,7 +14,7 @@ export declare const mergeData: <T>(args: {
14
14
  initialData: T;
15
15
  returnNumberOfRequests?: boolean;
16
16
  serverURL: string;
17
- }) => Promise<T & {
17
+ }) => Promise<{
18
18
  _numberOfRequests?: number;
19
- }>;
19
+ } & T>;
20
20
  //# sourceMappingURL=mergeData.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mergeData.d.ts","sourceRoot":"","sources":["../src/mergeData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,OAAO,KAAK,EAA2B,eAAe,EAAE,MAAM,YAAY,CAAA;AAc1E,eAAO,MAAM,SAAS,YAAmB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kCAAkC,CAAC,EAAE,CAAC,EACpC,OAAO,EACP,QAAQ,EACR,SAAS,GACV,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;KAClB,KAAK,QAAQ,QAAQ,CAAC,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6BAA6B,CAAC,EAAE,eAAe,CAAA;IAC/C,WAAW,EAAE,WAAW,wBAAwB,CAAC,CAAA;IACjD,YAAY,EAAE,QAAQ,CAAC,CAAC,CAAA;IACxB,WAAW,EAAE,CAAC,CAAA;IACd,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,QACF,CAAC,GAAG;IACF,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,CA4DF,CAAA"}
1
+ {"version":3,"file":"mergeData.d.ts","sourceRoot":"","sources":["../src/mergeData.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,KAAK,EAA2B,eAAe,EAAE,MAAM,YAAY,CAAA;AAc1E,eAAO,MAAM,SAAS,GAAU,CAAC,QAAQ;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,kCAAkC,CAAC,EAAE,CAAC,EACpC,OAAO,EACP,QAAQ,EACR,SAAS,GACV,EAAE;QACD,OAAO,EAAE,MAAM,CAAA;QACf,QAAQ,EAAE,MAAM,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;KAClB,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;IACvB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,6BAA6B,CAAC,EAAE,eAAe,CAAA;IAC/C,WAAW,EAAE,UAAU,CAAC,OAAO,iBAAiB,CAAC,CAAA;IACjD,YAAY,EAAE,OAAO,CAAC,CAAC,CAAC,CAAA;IACxB,WAAW,EAAE,CAAC,CAAA;IACd,sBAAsB,CAAC,EAAE,OAAO,CAAA;IAChC,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,OAAO,CACT;IACE,iBAAiB,CAAC,EAAE,MAAM,CAAA;CAC3B,GAAG,CAAC,CA8DN,CAAA"}
package/dist/mergeData.js CHANGED
@@ -28,7 +28,7 @@ export const mergeData = async (args)=>{
28
28
  try {
29
29
  res = await requestHandler({
30
30
  apiPath: apiRoute || '/api',
31
- endpoint: `${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}`,
31
+ endpoint: encodeURI(`${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}`),
32
32
  serverURL
33
33
  }).then((res)=>res.json());
34
34
  if (res?.docs?.length > 0) {
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/mergeData.ts"],"sourcesContent":["import type { PaginatedDocs } from 'payload/database'\nimport type { fieldSchemaToJSON } from 'payload/utilities'\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\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 returnNumberOfRequests?: boolean\n serverURL: string\n}): Promise<\n T & {\n _numberOfRequests?: number\n }\n> => {\n const {\n apiRoute,\n depth,\n externallyUpdatedRelationship,\n fieldSchema,\n incomingData,\n initialData,\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 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: `${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}`,\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 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","mergeData","args","apiRoute","depth","externallyUpdatedRelationship","fieldSchema","incomingData","initialData","returnNumberOfRequests","result","populationsByCollection","Promise","all","Object","entries","map","collection","populations","res","ids","Set","id","requestHandler","collectionPopulationRequestHandler","Array","from","join","then","json","docs","length","forEach","doc","population","ref","accessor","err","console","error","_numberOfRequests","keys"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAKA,SAASA,cAAc,QAAQ,sBAAqB;AAEpD,MAAMC,wBAAwB,CAAC,EAAEC,OAAO,EAAEC,QAAQ,EAAEC,SAAS,EAAE;IAC7D,MAAMC,MAAM,CAAC,EAAED,UAAU,EAAEF,QAAQ,CAAC,EAAEC,SAAS,CAAC;IAChD,OAAOG,MAAMD,KAAK;QAChBE,aAAa;QACbC,SAAS;YACP,gBAAgB;QAClB;IACF;AACF;AAEA,OAAO,MAAMC,YAAY,OAAUC;IAuBjC,MAAM,EACJC,QAAQ,EACRC,KAAK,EACLC,6BAA6B,EAC7BC,WAAW,EACXC,YAAY,EACZC,WAAW,EACXC,sBAAsB,EACtBb,SAAS,EACV,GAAGM;IAEJ,MAAMQ,SAAS;QAAE,GAAGF,WAAW;IAAC;IAEhC,MAAMG,0BAAmD,CAAC;IAE1DnB,eAAe;QACba;QACAC;QACAC;QACAI;QACAD;IACF;IAEA,MAAME,QAAQC,GAAG,CACfC,OAAOC,OAAO,CAACJ,yBAAyBK,GAAG,CAAC,OAAO,CAACC,YAAYC,YAAY;QAC1E,IAAIC;QAEJ,MAAMC,MAAM,IAAIC,IAAIH,YAAYF,GAAG,CAAC,CAAC,EAAEM,EAAE,EAAE,GAAKA;QAChD,MAAMC,iBAAiBrB,KAAKsB,kCAAkC,IAAI/B;QAElE,IAAI;YACF0B,MAAM,MAAMI,eAAe;gBACzB7B,SAASS,YAAY;gBACrBR,UAAU,CAAC,EAAEsB,WAAW,OAAO,EAAEb,MAAM,eAAe,EAAEqB,MAAMC,IAAI,CAACN,KAAKO,IAAI,CAAC,KAAK,CAAC;gBACnF/B;YACF,GAAGgC,IAAI,CAAC,CAACT,MAAQA,IAAIU,IAAI;YAEzB,IAAIV,KAAKW,MAAMC,SAAS,GAAG;gBACzBZ,IAAIW,IAAI,CAACE,OAAO,CAAC,CAACC;oBAChBtB,uBAAuB,CAACM,WAAW,CAACe,OAAO,CAAC,CAACE;wBAC3C,IAAIA,WAAWZ,EAAE,KAAKW,IAAIX,EAAE,EAAE;4BAC5BY,WAAWC,GAAG,CAACD,WAAWE,QAAQ,CAAC,GAAGH;wBACxC;oBACF;gBACF;YACF;QACF,EAAE,OAAOI,KAAK;YACZC,QAAQC,KAAK,CAACF,KAAK,iCAAiC;;QACtD;IACF;IAGF,OAAO;QACL,GAAG3B,MAAM;QACT,GAAID,yBACA;YAAE+B,mBAAmB1B,OAAO2B,IAAI,CAAC9B,yBAAyBoB,MAAM;QAAC,IACjE,CAAC,CAAC;IACR;AACF,EAAC"}
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\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 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 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 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(',')}`,\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 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","mergeData","args","apiRoute","depth","externallyUpdatedRelationship","fieldSchema","incomingData","initialData","returnNumberOfRequests","result","populationsByCollection","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,EAA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CAAC,GAAGH;wBACxC;oBACF;gBACF;YACF;QACF,EAAE,OAAOI,KAAK;YACZC,QAAQC,KAAK,CAACF,KAAK,iCAAiC;;QACtD;IACF;IAGF,OAAO;QACL,GAAG5B,MAAM;QACT,GAAID,yBACA;YAAEgC,mBAAmB3B,OAAO4B,IAAI,CAAC/B,yBAAyBqB,MAAM;QAAC,IACjE,CAAC,CAAC;IACR;AACF,EAAC"}
package/dist/ready.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/ready.ts"],"sourcesContent":["export const ready = (args: { serverURL: string }): void => {\n const { serverURL } = args\n\n if (typeof window !== 'undefined') {\n // This subscription may have been from either an iframe or a popup\n // We need to report 'ready' to the parent window, whichever it may be\n // i.e. `window?.opener` for popups, `window?.parent` for iframes\n const windowToPostTo: Window = window?.opener || window?.parent\n\n windowToPostTo?.postMessage(\n {\n type: 'payload-live-preview',\n ready: true,\n },\n serverURL,\n )\n }\n}\n"],"names":["ready","args","serverURL","window","windowToPostTo","opener","parent","postMessage","type"],"rangeMappings":";;;;;;;;;;;;","mappings":"AAAA,OAAO,MAAMA,QAAQ,CAACC;IACpB,MAAM,EAAEC,SAAS,EAAE,GAAGD;IAEtB,IAAI,OAAOE,WAAW,aAAa;QACjC,mEAAmE;QACnE,sEAAsE;QACtE,iEAAiE;QACjE,MAAMC,iBAAyBD,QAAQE,UAAUF,QAAQG;QAEzDF,gBAAgBG,YACd;YACEC,MAAM;YACNR,OAAO;QACT,GACAE;IAEJ;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/ready.ts"],"sourcesContent":["export const ready = (args: { serverURL: string }): void => {\n const { serverURL } = args\n\n if (typeof window !== 'undefined') {\n // This subscription may have been from either an iframe or a popup\n // We need to report 'ready' to the parent window, whichever it may be\n // i.e. `window?.opener` for popups, `window?.parent` for iframes\n const windowToPostTo: Window = window?.opener || window?.parent\n\n windowToPostTo?.postMessage(\n {\n type: 'payload-live-preview',\n ready: true,\n },\n serverURL,\n )\n }\n}\n"],"names":["ready","args","serverURL","window","windowToPostTo","opener","parent","postMessage","type"],"mappings":"AAAA,OAAO,MAAMA,QAAQ,CAACC;IACpB,MAAM,EAAEC,SAAS,EAAE,GAAGD;IAEtB,IAAI,OAAOE,WAAW,aAAa;QACjC,mEAAmE;QACnE,sEAAsE;QACtE,iEAAiE;QACjE,MAAMC,iBAAyBD,QAAQE,UAAUF,QAAQG;QAEzDF,gBAAgBG,YACd;YACEC,MAAM;YACNR,OAAO;QACT,GACAE;IAEJ;AACF,EAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../src/subscribe.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,YAAa;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAoBjC,CAAA"}
1
+ {"version":3,"file":"subscribe.d.ts","sourceRoot":"","sources":["../src/subscribe.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,SAAS,GAAI,CAAC,QAAQ;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAA;IAC3B,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG,CAAC,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAoBjC,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/subscribe.ts"],"sourcesContent":["import { handleMessage } from './handleMessage.js'\n\nexport const subscribe = <T>(args: {\n apiRoute?: string\n callback: (data: T) => void\n depth?: number\n initialData: T\n serverURL: string\n}): ((event: MessageEvent) => void) => {\n const { apiRoute, callback, depth, initialData, serverURL } = args\n\n const onMessage = async (event: MessageEvent) => {\n const mergedData = await handleMessage<T>({\n apiRoute,\n depth,\n event,\n initialData,\n serverURL,\n })\n\n callback(mergedData)\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', onMessage)\n }\n\n return onMessage\n}\n"],"names":["handleMessage","subscribe","args","apiRoute","callback","depth","initialData","serverURL","onMessage","event","mergedData","window","addEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;","mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAElD,OAAO,MAAMC,YAAY,CAAIC;IAO3B,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGL;IAE9D,MAAMM,YAAY,OAAOC;QACvB,MAAMC,aAAa,MAAMV,cAAiB;YACxCG;YACAE;YACAI;YACAH;YACAC;QACF;QAEAH,SAASM;IACX;IAEA,IAAI,OAAOC,WAAW,aAAa;QACjCA,OAAOC,gBAAgB,CAAC,WAAWJ;IACrC;IAEA,OAAOA;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/subscribe.ts"],"sourcesContent":["import { handleMessage } from './handleMessage.js'\n\nexport const subscribe = <T>(args: {\n apiRoute?: string\n callback: (data: T) => void\n depth?: number\n initialData: T\n serverURL: string\n}): ((event: MessageEvent) => void) => {\n const { apiRoute, callback, depth, initialData, serverURL } = args\n\n const onMessage = async (event: MessageEvent) => {\n const mergedData = await handleMessage<T>({\n apiRoute,\n depth,\n event,\n initialData,\n serverURL,\n })\n\n callback(mergedData)\n }\n\n if (typeof window !== 'undefined') {\n window.addEventListener('message', onMessage)\n }\n\n return onMessage\n}\n"],"names":["handleMessage","subscribe","args","apiRoute","callback","depth","initialData","serverURL","onMessage","event","mergedData","window","addEventListener"],"mappings":"AAAA,SAASA,aAAa,QAAQ,qBAAoB;AAElD,OAAO,MAAMC,YAAY,CAAIC;IAO3B,MAAM,EAAEC,QAAQ,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGL;IAE9D,MAAMM,YAAY,OAAOC;QACvB,MAAMC,aAAa,MAAMV,cAAiB;YACxCG;YACAE;YACAI;YACAH;YACAC;QACF;QAEAH,SAASM;IACX;IAEA,IAAI,OAAOC,WAAW,aAAa;QACjCA,OAAOC,gBAAgB,CAAC,WAAWJ;IACrC;IAEA,OAAOA;AACT,EAAC"}
@@ -1,4 +1,4 @@
1
- import type { fieldSchemaToJSON } from 'payload/utilities';
1
+ import type { fieldSchemaToJSON } from 'payload/shared';
2
2
  import type { PopulationsByCollection, UpdatedDocument } from './types.js';
3
3
  export declare const traverseFields: <T>(args: {
4
4
  externallyUpdatedRelationship?: UpdatedDocument;
@@ -1 +1 @@
1
- {"version":3,"file":"traverseFields.d.ts","sourceRoot":"","sources":["../src/traverseFields.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAA;AAE1D,OAAO,KAAK,EAAE,uBAAuB,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAI1E,eAAO,MAAM,cAAc,YAAa;IACtC,6BAA6B,CAAC,EAAE,eAAe,CAAA;IAC/C,WAAW,EAAE,WAAW,wBAAwB,CAAC,CAAA;IACjD,YAAY,EAAE,CAAC,CAAA;IACf,uBAAuB,EAAE,uBAAuB,CAAA;IAChD,MAAM,EAAE,CAAC,CAAA;CACV,KAAG,IA4QH,CAAA"}
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,uBAAuB,EAAE,uBAAuB,CAAA;IAChD,MAAM,EAAE,CAAC,CAAA;CACV,KAAG,IA4QH,CAAA"}
@@ -5,14 +5,6 @@ export const traverseFields = (args)=>{
5
5
  if ('name' in fieldSchema && typeof fieldSchema.name === 'string') {
6
6
  const fieldName = fieldSchema.name;
7
7
  switch(fieldSchema.type){
8
- case 'richText':
9
- result[fieldName] = traverseRichText({
10
- externallyUpdatedRelationship,
11
- incomingData: incomingData[fieldName],
12
- populationsByCollection,
13
- result: result[fieldName]
14
- });
15
- break;
16
8
  case 'array':
17
9
  if (Array.isArray(incomingData[fieldName])) {
18
10
  result[fieldName] = incomingData[fieldName].map((incomingRow, i)=>{
@@ -58,8 +50,8 @@ export const traverseFields = (args)=>{
58
50
  result[fieldName] = [];
59
51
  }
60
52
  break;
61
- case 'tabs':
62
53
  case 'group':
54
+ case 'tabs':
63
55
  if (!result[fieldName]) {
64
56
  result[fieldName] = {};
65
57
  }
@@ -71,8 +63,8 @@ export const traverseFields = (args)=>{
71
63
  result: result[fieldName]
72
64
  });
73
65
  break;
74
- case 'upload':
75
66
  case 'relationship':
67
+ case 'upload':
76
68
  // Handle `hasMany` relationships
77
69
  if (fieldSchema.hasMany && Array.isArray(incomingData[fieldName])) {
78
70
  if (!result[fieldName] || !incomingData[fieldName].length) {
@@ -183,6 +175,14 @@ export const traverseFields = (args)=>{
183
175
  }
184
176
  }
185
177
  break;
178
+ case 'richText':
179
+ result[fieldName] = traverseRichText({
180
+ externallyUpdatedRelationship,
181
+ incomingData: incomingData[fieldName],
182
+ populationsByCollection,
183
+ result: result[fieldName]
184
+ });
185
+ break;
186
186
  default:
187
187
  result[fieldName] = incomingData[fieldName];
188
188
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/traverseFields.ts"],"sourcesContent":["import type { fieldSchemaToJSON } from 'payload/utilities'\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 populationsByCollection: PopulationsByCollection\n result: T\n}): void => {\n const {\n externallyUpdatedRelationship,\n fieldSchema: fieldSchemas,\n incomingData,\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 'richText':\n result[fieldName] = traverseRichText({\n externallyUpdatedRelationship,\n incomingData: incomingData[fieldName],\n populationsByCollection,\n result: result[fieldName],\n })\n\n break\n\n case 'array':\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 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 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 'tabs':\n case 'group':\n if (!result[fieldName]) {\n result[fieldName] = {}\n }\n\n traverseFields({\n externallyUpdatedRelationship,\n fieldSchema: fieldSchema.fields,\n incomingData: incomingData[fieldName] || {},\n populationsByCollection,\n result: result[fieldName],\n })\n\n break\n\n case 'upload':\n case 'relationship':\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 const hasUpdated =\n newRelation === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated) {\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 const hasUpdated =\n fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&\n incomingRelation === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated) {\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 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) {\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 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) {\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\n default:\n result[fieldName] = incomingData[fieldName]\n }\n }\n })\n}\n"],"names":["traverseRichText","traverseFields","args","externallyUpdatedRelationship","fieldSchema","fieldSchemas","incomingData","populationsByCollection","result","forEach","name","fieldName","type","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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAIA,SAASA,gBAAgB,QAAQ,wBAAuB;AAExD,OAAO,MAAMC,iBAAiB,CAAIC;IAOhC,MAAM,EACJC,6BAA6B,EAC7BC,aAAaC,YAAY,EACzBC,YAAY,EACZC,uBAAuB,EACvBC,MAAM,EACP,GAAGN;IAEJG,aAAaI,OAAO,CAAC,CAACL;QACpB,IAAI,UAAUA,eAAe,OAAOA,YAAYM,IAAI,KAAK,UAAU;YACjE,MAAMC,YAAYP,YAAYM,IAAI;YAElC,OAAQN,YAAYQ,IAAI;gBACtB,KAAK;oBACHJ,MAAM,CAACG,UAAU,GAAGX,iBAAiB;wBACnCG;wBACAG,cAAcA,YAAY,CAACK,UAAU;wBACrCJ;wBACAC,QAAQA,MAAM,CAACG,UAAU;oBAC3B;oBAEA;gBAEF,KAAK;oBACH,IAAIE,MA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;4BAEzB,MAAMiB,QACJ,AAACpB,MAAM,CAACG,UAAU,IAChB,OAAOH,MAAM,CAACG,UAAU,KAAK,YAC7BH,MAAM,CAACG,UAAU,CAACY,EAAE,IACtBf,MAAM,CAACG,UAAU;4BAEnB,MAAMsB,aAAaF,UAAUH;4BAC7B,MAAMM,aACJ9B,YAAYuB,UAAU,KAAKxB,+BAA+BgC,cAC1DJ,UAAU5B,+BAA+BoB;4BAE3C,mDAAmD;4BACnD,mDAAmD;4BACnD,IAAIU,cAAcC,YAAY;gCAC5B,6CAA6C;gCAC7C,kCAAkC;gCAClC,IAAIH,OAAO;oCACT,IAAI,CAACxB,uBAAuB,CAACH,YAAYuB,UAAU,CAAC,EAAE;wCACpDpB,uBAAuB,CAACH,YAAYuB,UAAU,CAAC,GAAG,EAAE;oCACtD;oCAEApB,uBAAuB,CAACH,YAAYuB,UAAU,CAAC,CAACS,IAAI,CAAC;wCACnDb,IAAIQ;wCACJM,UAAU1B;wCACV2B,KAAK9B;oCACP;gCACF,OAAO;oCACLA,MAAM,CAACG,UAAU,GAAG;gCACtB;4BACF;wBACF;oBACF;oBAEA;gBAEF;oBACEH,MAAM,CAACG,UAAU,GAAGL,YAAY,CAACK,UAAU;YAC/C;QACF;IACF;AACF,EAAC"}
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 populationsByCollection: PopulationsByCollection\n result: T\n}): void => {\n const {\n externallyUpdatedRelationship,\n fieldSchema: fieldSchemas,\n incomingData,\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 (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 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 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\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 populationsByCollection,\n result: result[fieldName],\n })\n\n break\n case 'relationship':\n\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 const hasUpdated =\n newRelation === externallyUpdatedRelationship?.entitySlug &&\n newID === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated) {\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 const hasUpdated =\n fieldSchema.relationTo === externallyUpdatedRelationship?.entitySlug &&\n incomingRelation === externallyUpdatedRelationship?.id\n\n if (hasChanged || hasUpdated) {\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 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) {\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 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) {\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","populationsByCollection","result","forEach","name","fieldName","type","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;IAOhC,MAAM,EACJC,6BAA6B,EAC7BC,aAAaC,YAAY,EACzBC,YAAY,EACZC,uBAAuB,EACvBC,MAAM,EACP,GAAGN;IAEJG,aAAaI,OAAO,CAAC,CAACL;QACpB,IAAI,UAAUA,eAAe,OAAOA,YAAYM,IAAI,KAAK,UAAU;YACjE,MAAMC,YAAYP,YAAYM,IAAI;YAElC,OAAQN,YAAYQ,IAAI;gBACtB,KAAK;oBACH,IAAIC,MAAMC,OAAO,CAACR,YAAY,CAACK,UAAU,GAAG;wBAC1CH,MAAM,CAACG,UAAU,GAAGL,YAAY,CAACK,UAAU,CAACI,GAAG,CAAC,CAACC,aAAaC;4BAC5D,IAAI,CAACT,MAAM,CAACG,UAAU,EAAE;gCACtBH,MAAM,CAACG,UAAU,GAAG,EAAE;4BACxB;4BAEA,IAAI,CAACH,MAAM,CAACG,UAAU,CAACM,EAAE,EAAE;gCACzBT,MAAM,CAACG,UAAU,CAACM,EAAE,GAAG,CAAC;4BAC1B;4BAEAhB,eAAe;gCACbE;gCACAC,aAAaA,YAAYc,MAAM;gCAC/BZ,cAAcU;gCACdT;gCACAC,QAAQA,MAAM,CAACG,UAAU,CAACM,EAAE;4BAC9B;4BAEA,OAAOT,MAAM,CAACG,UAAU,CAACM,EAAE;wBAC7B;oBACF;oBAEA;gBAEF,KAAK;oBACH,IAAIJ,MAAMC,OAAO,CAACR,YAAY,CAACK,UAAU,GAAG;wBAC1CH,MAAM,CAACG,UAAU,GAAGL,YAAY,CAACK,UAAU,CAACI,GAAG,CAAC,CAACI,eAAeF;4BAC9D,MAAMG,oBAAoBhB,YAAYiB,MAAM,CAACF,cAAcG,SAAS,CAAC;4BAErE,IAAI,CAACd,MAAM,CAACG,UAAU,E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ACK,UAAU;wBACrCJ;wBACAC,QAAQA,MAAM,CAACG,UAAU;oBAC3B;oBAEA;gBAEF;oBACEH,MAAM,CAACG,UAAU,GAAGL,YAAY,CAACK,UAAU;YAC/C;QACF;IACF;AACF,EAAC"}
@@ -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"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAEA,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;gBACdL;gBACAC,QAAQA,MAAM,CAACK,MAAM;YACvB;QACF;IACF,OAAO,IAAIP,gBAAgB,OAAOA,iBAAiB,UAAU;QAC3D,IAAI,CAACE,QAAQ;YACXA,SAAS,CAAC;QACZ;QAEA,iEAAiE;QACjE,yCAAyC;QACzC,wDAAwD;QACxDM,OAAOC,IAAI,CAACP,QAAQQ,OAAO,CAAC,CAACC;YAC3B,IAAI,CAAEA,CAAAA,OAAOX,YAAW,GAAI;gBAC1B,OAAOE,MAAM,CAACS,IAAI;YACpB;QACF;QAEA,gEAAgE;QAChEH,OAAOC,IAAI,CAACT,cA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;AACT,EAAC"}
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;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;gBACdL;gBACAC,QAAQA,MAAM,CAACK,MAAM;YACvB;QACF;IACF,OAAO,IAAIP,gBAAgB,OAAOA,iBAAiB,UAAU;QAC3D,IAAI,CAACE,QAAQ;YACXA,SAAS,CAAC;QACZ;QAEA,iEAAiE;QACjE,yCAAyC;QACzC,wDAAwD;QACxDM,OAAOC,IAAI,CAACP,QAAQQ,OAAO,CAAC,CAACC;YAC3B,IAAI,CAAEA,CAAAA,OAAOX,YAAW,GAAI;gBAC1B,OAAOE,MAAM,CAACS,IAAI;YACpB;QACF;QAEA,gEAAgE;QAChEH,OAAOC,IAAI,CAACT,cAAcU,OAAO,CAAC,CAACC;YACjC,IAAI,CAACT,MAAM,CAACS,IAAI,EAAE;gBAChB,sDAAsD;gBACtD,yDAAyD;gBACzD,+CAA+C;gBAC/CT,MAAM,CAACS,IAAI,GACTX,YAAY,CAACW,IAAI,IAAI,OAAOX,YAAY,CAACW,IAAI,KAAK,WAC9CR,MAAMC,OAAO,CAACJ,YAAY,CAACW,IAAI,IAC7B,EAAE,GACF,CAAC,IACHC;YACR;YAEA,MAAMC,iBAAiBF,QAAQ,WAAW,gBAAgBX;YAE1D,IAAIa,gBAAgB;gBAClB,qCAAqC;gBACrC,MAAMC,kBACJ,CAACZ,OAAOa,KAAK,IACb,OAAOb,OAAOa,KAAK,KAAK,YACvB,OAAOb,OAAOa,KAAK,KAAK,YACvBP,OAAOC,IAAI,CAACP,OAAOa,KAAK,EAAEC,MAAM,KAAK,KACrC,QAAQd,OAAOa,KAAK;gBAExB,MAAME,aACJf,UACA,OAAOA,WAAW,YAClBA,OAAOa,KAAK,CAACG,EAAE,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"}
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":[],"rangeMappings":";","mappings":"AAYA,sFAAsF;AACtF,WAIC"}
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 +1 @@
1
- {"version":3,"sources":["../src/unsubscribe.ts"],"sourcesContent":["export const unsubscribe = (callback: (event: MessageEvent) => void) => {\n if (typeof window !== 'undefined') {\n window.removeEventListener('message', callback)\n }\n}\n"],"names":["unsubscribe","callback","window","removeEventListener"],"rangeMappings":";;;;","mappings":"AAAA,OAAO,MAAMA,cAAc,CAACC;IAC1B,IAAI,OAAOC,WAAW,aAAa;QACjCA,OAAOC,mBAAmB,CAAC,WAAWF;IACxC;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/unsubscribe.ts"],"sourcesContent":["export const unsubscribe = (callback: (event: MessageEvent) => void) => {\n if (typeof window !== 'undefined') {\n window.removeEventListener('message', callback)\n }\n}\n"],"names":["unsubscribe","callback","window","removeEventListener"],"mappings":"AAAA,OAAO,MAAMA,cAAc,CAACC;IAC1B,IAAI,OAAOC,WAAW,aAAa;QACjCA,OAAOC,mBAAmB,CAAC,WAAWF;IACxC;AACF,EAAC"}
package/license.md ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2018-2024 Payload CMS, Inc. <info@payloadcms.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ 'Software'), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/live-preview",
3
- "version": "3.0.0-canary.f6e77b8",
3
+ "version": "3.0.0-canary.fb04843",
4
4
  "description": "The official live preview JavaScript SDK for Payload",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -10,12 +10,19 @@
10
10
  },
11
11
  "license": "MIT",
12
12
  "author": "Payload <dev@payloadcms.com> (https://payloadcms.com)",
13
+ "maintainers": [
14
+ {
15
+ "name": "Payload",
16
+ "email": "info@payloadcms.com",
17
+ "url": "https://payloadcms.com"
18
+ }
19
+ ],
13
20
  "type": "module",
14
21
  "exports": {
15
22
  ".": {
16
23
  "import": "./dist/index.js",
17
- "require": "./dist/index.js",
18
- "types": "./dist/index.d.ts"
24
+ "types": "./dist/index.d.ts",
25
+ "default": "./dist/index.js"
19
26
  }
20
27
  },
21
28
  "main": "./dist/index.js",
@@ -24,17 +31,19 @@
24
31
  "dist"
25
32
  ],
26
33
  "devDependencies": {
27
- "@payloadcms/eslint-config": "1.1.1",
28
- "payload": "3.0.0-canary.f6e77b8"
34
+ "@payloadcms/eslint-config": "3.0.0-beta.112",
35
+ "payload": "3.0.0-canary.fb04843"
29
36
  },
30
37
  "publishConfig": {
31
38
  "registry": "https://registry.npmjs.org/"
32
39
  },
33
40
  "scripts": {
34
- "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
35
- "build:swc": "swc ./src -d ./dist --config-file .swcrc",
41
+ "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
42
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
36
43
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
37
44
  "clean": "rimraf {dist,*.tsbuildinfo}",
38
- "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/"
45
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
46
+ "lint": "eslint .",
47
+ "lint:fix": "eslint . --fix"
39
48
  }
40
49
  }