@payloadcms/live-preview-react 3.0.0-alpha.70 → 3.0.0-beta.100

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":"RefreshRouteOnSave.d.ts","sourceRoot":"","sources":["../src/RefreshRouteOnSave.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,CAuCA,CAAA"}
1
+ {"version":3,"file":"RefreshRouteOnSave.d.ts","sourceRoot":"","sources":["../src/RefreshRouteOnSave.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAK9B,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC;IACxC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,EAAE,MAAM,IAAI,CAAA;IACnB,SAAS,EAAE,MAAM,CAAA;CAClB,CA0CA,CAAA"}
@@ -26,6 +26,8 @@ export const RefreshRouteOnSave = (props)=>{
26
26
  ready({
27
27
  serverURL
28
28
  });
29
+ // refresh after the ready message is sent to get the latest data
30
+ refresh();
29
31
  }
30
32
  return ()=>{
31
33
  if (typeof window !== 'undefined') {
@@ -36,7 +38,8 @@ export const RefreshRouteOnSave = (props)=>{
36
38
  serverURL,
37
39
  onMessage,
38
40
  depth,
39
- apiRoute
41
+ apiRoute,
42
+ refresh
40
43
  ]);
41
44
  return null;
42
45
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/RefreshRouteOnSave.tsx"],"sourcesContent":["'use client'\n\nimport type React from 'react'\n\nimport { isDocumentEvent, ready } from '@payloadcms/live-preview'\nimport { useCallback, useEffect, useRef } from 'react'\n\nexport const RefreshRouteOnSave: React.FC<{\n apiRoute?: string\n depth?: number\n refresh: () => void\n serverURL: string\n}> = (props) => {\n const { apiRoute, depth, refresh, serverURL } = props\n const hasSentReadyMessage = useRef<boolean>(false)\n\n const onMessage = useCallback(\n (event: MessageEvent) => {\n if (isDocumentEvent(event, serverURL)) {\n if (typeof refresh === 'function') {\n refresh()\n } else {\n // eslint-disable-next-line no-console\n console.error('You must provide a refresh function to `RefreshRouteOnSave`')\n }\n }\n },\n [refresh, serverURL],\n )\n\n useEffect(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('message', onMessage)\n }\n\n if (!hasSentReadyMessage.current) {\n hasSentReadyMessage.current = true\n\n ready({\n serverURL,\n })\n }\n\n return () => {\n if (typeof window !== 'undefined') {\n window.removeEventListener('message', onMessage)\n }\n }\n }, [serverURL, onMessage, depth, apiRoute])\n\n return null\n}\n"],"names":["isDocumentEvent","ready","useCallback","useEffect","useRef","RefreshRouteOnSave","props","apiRoute","depth","refresh","serverURL","hasSentReadyMessage","onMessage","event","console","error","window","addEventListener","current","removeEventListener"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AAIA,SAASA,eAAe,EAAEC,KAAK,QAAQ,2BAA0B;AACjE,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,QAAO;AAEtD,OAAO,MAAMC,qBAKR,CAACC;IACJ,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGJ;IAChD,MAAMK,sBAAsBP,OAAgB;IAE5C,MAAMQ,YAAYV,YAChB,CAACW;QACC,IAAIb,gBAAgBa,OAAOH,YAAY;YACrC,IAAI,OAAOD,YAAY,YAAY;gBACjCA;YACF,OAAO;gBACL,sCAAsC;gBACtCK,QAAQC,KAAK,CAAC;YAChB;QACF;IACF,GACA;QAACN;QAASC;KAAU;IAGtBP,UAAU;QACR,IAAI,OAAOa,WAAW,aAAa;YACjCA,OAAOC,gBAAgB,CAAC,WAAWL;QACrC;QAEA,IAAI,CAACD,oBAAoBO,OAAO,EAAE;YAChCP,oBAAoBO,OAAO,GAAG;YAE9BjB,MAAM;gBACJS;YACF;QACF;QAEA,OAAO;YACL,IAAI,OAAOM,WAAW,aAAa;gBACjCA,OAAOG,mBAAmB,CAAC,WAAWP;YACxC;QACF;IACF,GAAG;QAACF;QAAWE;QAAWJ;QAAOD;KAAS;IAE1C,OAAO;AACT,EAAC"}
1
+ {"version":3,"sources":["../src/RefreshRouteOnSave.tsx"],"sourcesContent":["'use client'\n\nimport type React from 'react'\n\nimport { isDocumentEvent, ready } from '@payloadcms/live-preview'\nimport { useCallback, useEffect, useRef } from 'react'\n\nexport const RefreshRouteOnSave: React.FC<{\n apiRoute?: string\n depth?: number\n refresh: () => void\n serverURL: string\n}> = (props) => {\n const { apiRoute, depth, refresh, serverURL } = props\n const hasSentReadyMessage = useRef<boolean>(false)\n\n const onMessage = useCallback(\n (event: MessageEvent) => {\n if (isDocumentEvent(event, serverURL)) {\n if (typeof refresh === 'function') {\n refresh()\n } else {\n // eslint-disable-next-line no-console\n console.error('You must provide a refresh function to `RefreshRouteOnSave`')\n }\n }\n },\n [refresh, serverURL],\n )\n\n useEffect(() => {\n if (typeof window !== 'undefined') {\n window.addEventListener('message', onMessage)\n }\n\n if (!hasSentReadyMessage.current) {\n hasSentReadyMessage.current = true\n\n ready({\n serverURL,\n })\n\n // refresh after the ready message is sent to get the latest data\n refresh()\n }\n\n return () => {\n if (typeof window !== 'undefined') {\n window.removeEventListener('message', onMessage)\n }\n }\n }, [serverURL, onMessage, depth, apiRoute, refresh])\n\n return null\n}\n"],"names":["isDocumentEvent","ready","useCallback","useEffect","useRef","RefreshRouteOnSave","props","apiRoute","depth","refresh","serverURL","hasSentReadyMessage","onMessage","event","console","error","window","addEventListener","current","removeEventListener"],"mappings":"AAAA;AAIA,SAASA,eAAe,EAAEC,KAAK,QAAQ,2BAA0B;AACjE,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,QAAQ,QAAO;AAEtD,OAAO,MAAMC,qBAKR,CAACC;IACJ,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,OAAO,EAAEC,SAAS,EAAE,GAAGJ;IAChD,MAAMK,sBAAsBP,OAAgB;IAE5C,MAAMQ,YAAYV,YAChB,CAACW;QACC,IAAIb,gBAAgBa,OAAOH,YAAY;YACrC,IAAI,OAAOD,YAAY,YAAY;gBACjCA;YACF,OAAO;gBACL,sCAAsC;gBACtCK,QAAQC,KAAK,CAAC;YAChB;QACF;IACF,GACA;QAACN;QAASC;KAAU;IAGtBP,UAAU;QACR,IAAI,OAAOa,WAAW,aAAa;YACjCA,OAAOC,gBAAgB,CAAC,WAAWL;QACrC;QAEA,IAAI,CAACD,oBAAoBO,OAAO,EAAE;YAChCP,oBAAoBO,OAAO,GAAG;YAE9BjB,MAAM;gBACJS;YACF;YAEA,iEAAiE;YACjED;QACF;QAEA,OAAO;YACL,IAAI,OAAOO,WAAW,aAAa;gBACjCA,OAAOG,mBAAmB,CAAC,WAAWP;YACxC;QACF;IACF,GAAG;QAACF;QAAWE;QAAWJ;QAAOD;QAAUE;KAAQ;IAEnD,OAAO;AACT,EAAC"}
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { RefreshRouteOnSave } from './RefreshRouteOnSave.js'\nexport { useLivePreview } from './useLivePreview.js'\n"],"names":["RefreshRouteOnSave","useLivePreview"],"rangeMappings":";","mappings":"AAAA,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,cAAc,QAAQ,sBAAqB"}
1
+ {"version":3,"sources":["../src/index.ts"],"sourcesContent":["export { RefreshRouteOnSave } from './RefreshRouteOnSave.js'\nexport { useLivePreview } from './useLivePreview.js'\n"],"names":["RefreshRouteOnSave","useLivePreview"],"mappings":"AAAA,SAASA,kBAAkB,QAAQ,0BAAyB;AAC5D,SAASC,cAAc,QAAQ,sBAAqB"}
@@ -1 +1 @@
1
- {"version":3,"file":"useLivePreview.d.ts","sourceRoot":"","sources":["../src/useLivePreview.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,6BAA0B;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG;IACF,IAAI,EAAE,CAAC,CAAA;IACP,SAAS,EAAE,OAAO,CAAA;CAsCnB,CAAA"}
1
+ {"version":3,"file":"useLivePreview.d.ts","sourceRoot":"","sources":["../src/useLivePreview.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,GAAI,CAAC,yBAAqB;IACnD,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,EAAE,CAAC,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG;IACF,IAAI,EAAE,CAAC,CAAA;IACP,SAAS,EAAE,OAAO,CAAA;CAsCnB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/useLivePreview.ts"],"sourcesContent":["'use client'\nimport { ready, subscribe, unsubscribe } from '@payloadcms/live-preview'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\n// To prevent the flicker of missing data on initial load,\n// you can pass in the initial page data from the server\n// To prevent the flicker of stale data while the post message is being sent,\n// you can conditionally render loading UI based on the `isLoading` state\n\nexport const useLivePreview = <T extends any>(props: {\n apiRoute?: string\n depth?: number\n initialData: T\n serverURL: string\n}): {\n data: T\n isLoading: boolean\n} => {\n const { apiRoute, depth, initialData, serverURL } = props\n const [data, setData] = useState<T>(initialData)\n const [isLoading, setIsLoading] = useState<boolean>(true)\n const hasSentReadyMessage = useRef<boolean>(false)\n\n const onChange = useCallback((mergedData) => {\n setData(mergedData)\n setIsLoading(false)\n }, [])\n\n useEffect(() => {\n const subscription = subscribe({\n apiRoute,\n callback: onChange,\n depth,\n initialData,\n serverURL,\n })\n\n if (!hasSentReadyMessage.current) {\n hasSentReadyMessage.current = true\n\n ready({\n serverURL,\n })\n }\n\n return () => {\n unsubscribe(subscription)\n }\n }, [serverURL, onChange, depth, initialData, apiRoute])\n\n return {\n data,\n isLoading,\n }\n}\n"],"names":["ready","subscribe","unsubscribe","useCallback","useEffect","useRef","useState","useLivePreview","props","apiRoute","depth","initialData","serverURL","data","setData","isLoading","setIsLoading","hasSentReadyMessage","onChange","mergedData","subscription","callback","current"],"rangeMappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","mappings":"AAAA;AACA,SAASA,KAAK,EAAEC,SAAS,EAAEC,WAAW,QAAQ,2BAA0B;AACxE,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhE,0DAA0D;AAC1D,wDAAwD;AACxD,6EAA6E;AAC7E,yEAAyE;AAEzE,OAAO,MAAMC,iBAAiB,CAAgBC;IAS5C,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGJ;IACpD,MAAM,CAACK,MAAMC,QAAQ,GAAGR,SAAYK;IACpC,MAAM,CAACI,WAAWC,aAAa,GAAGV,SAAkB;IACpD,MAAMW,sBAAsBZ,OAAgB;IAE5C,MAAMa,WAAWf,YAAY,CAACgB;QAC5BL,QAAQK;QACRH,aAAa;IACf,GAAG,EAAE;IAELZ,UAAU;QACR,MAAMgB,eAAenB,UAAU;YAC7BQ;YACAY,UAAUH;YACVR;YACAC;YACAC;QACF;QAEA,IAAI,CAACK,oBAAoBK,OAAO,EAAE;YAChCL,oBAAoBK,OAAO,GAAG;YAE9BtB,MAAM;gBACJY;YACF;QACF;QAEA,OAAO;YACLV,YAAYkB;QACd;IACF,GAAG;QAACR;QAAWM;QAAUR;QAAOC;QAAaF;KAAS;IAEtD,OAAO;QACLI;QACAE;IACF;AACF,EAAC"}
1
+ {"version":3,"sources":["../src/useLivePreview.ts"],"sourcesContent":["'use client'\nimport { ready, subscribe, unsubscribe } from '@payloadcms/live-preview'\nimport { useCallback, useEffect, useRef, useState } from 'react'\n\n// To prevent the flicker of missing data on initial load,\n// you can pass in the initial page data from the server\n// To prevent the flicker of stale data while the post message is being sent,\n// you can conditionally render loading UI based on the `isLoading` state\n\nexport const useLivePreview = <T extends any>(props: {\n apiRoute?: string\n depth?: number\n initialData: T\n serverURL: string\n}): {\n data: T\n isLoading: boolean\n} => {\n const { apiRoute, depth, initialData, serverURL } = props\n const [data, setData] = useState<T>(initialData)\n const [isLoading, setIsLoading] = useState<boolean>(true)\n const hasSentReadyMessage = useRef<boolean>(false)\n\n const onChange = useCallback((mergedData) => {\n setData(mergedData)\n setIsLoading(false)\n }, [])\n\n useEffect(() => {\n const subscription = subscribe({\n apiRoute,\n callback: onChange,\n depth,\n initialData,\n serverURL,\n })\n\n if (!hasSentReadyMessage.current) {\n hasSentReadyMessage.current = true\n\n ready({\n serverURL,\n })\n }\n\n return () => {\n unsubscribe(subscription)\n }\n }, [serverURL, onChange, depth, initialData, apiRoute])\n\n return {\n data,\n isLoading,\n }\n}\n"],"names":["ready","subscribe","unsubscribe","useCallback","useEffect","useRef","useState","useLivePreview","props","apiRoute","depth","initialData","serverURL","data","setData","isLoading","setIsLoading","hasSentReadyMessage","onChange","mergedData","subscription","callback","current"],"mappings":"AAAA;AACA,SAASA,KAAK,EAAEC,SAAS,EAAEC,WAAW,QAAQ,2BAA0B;AACxE,SAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAO;AAEhE,0DAA0D;AAC1D,wDAAwD;AACxD,6EAA6E;AAC7E,yEAAyE;AAEzE,OAAO,MAAMC,iBAAiB,CAAgBC;IAS5C,MAAM,EAAEC,QAAQ,EAAEC,KAAK,EAAEC,WAAW,EAAEC,SAAS,EAAE,GAAGJ;IACpD,MAAM,CAACK,MAAMC,QAAQ,GAAGR,SAAYK;IACpC,MAAM,CAACI,WAAWC,aAAa,GAAGV,SAAkB;IACpD,MAAMW,sBAAsBZ,OAAgB;IAE5C,MAAMa,WAAWf,YAAY,CAACgB;QAC5BL,QAAQK;QACRH,aAAa;IACf,GAAG,EAAE;IAELZ,UAAU;QACR,MAAMgB,eAAenB,UAAU;YAC7BQ;YACAY,UAAUH;YACVR;YACAC;YACAC;QACF;QAEA,IAAI,CAACK,oBAAoBK,OAAO,EAAE;YAChCL,oBAAoBK,OAAO,GAAG;YAE9BtB,MAAM;gBACJY;YACF;QACF;QAEA,OAAO;YACLV,YAAYkB;QACd;IACF,GAAG;QAACR;QAAWM;QAAUR;QAAOC;QAAaF;KAAS;IAEtD,OAAO;QACLI;QACAE;IACF;AACF,EAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@payloadcms/live-preview-react",
3
- "version": "3.0.0-alpha.70",
4
- "description": "The official live preview React SDK for Payload",
3
+ "version": "3.0.0-beta.100",
4
+ "description": "The official React SDK for Payload Live Preview",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
7
7
  "type": "git",
@@ -14,8 +14,8 @@
14
14
  "exports": {
15
15
  ".": {
16
16
  "import": "./dist/index.js",
17
- "require": "./dist/index.js",
18
- "types": "./dist/index.d.ts"
17
+ "types": "./dist/index.d.ts",
18
+ "default": "./dist/index.js"
19
19
  }
20
20
  },
21
21
  "main": "./dist/index.js",
@@ -24,24 +24,32 @@
24
24
  "dist"
25
25
  ],
26
26
  "dependencies": {
27
- "@payloadcms/live-preview": "^0.x"
27
+ "@payloadcms/live-preview": "3.0.0-beta.100"
28
28
  },
29
29
  "devDependencies": {
30
- "@types/react": "18.2.74",
31
- "@payloadcms/eslint-config": "1.1.1",
32
- "payload": "3.0.0-alpha.70"
30
+ "@types/react": "npm:types-react@19.0.0-rc.0",
31
+ "@types/react-dom": "npm:types-react-dom@19.0.0-rc.0",
32
+ "payload": "3.0.0-beta.100",
33
+ "@payloadcms/eslint-config": "3.0.0-beta.97"
33
34
  },
34
35
  "peerDependencies": {
35
- "react": "^16.8.0 || ^17.0.0 || ^18.0.0"
36
+ "react": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801",
37
+ "react-dom": "^19.0.0 || ^19.0.0-rc-06d0b89e-20240801"
36
38
  },
37
39
  "publishConfig": {
38
40
  "registry": "https://registry.npmjs.org/"
39
41
  },
42
+ "overrides": {
43
+ "@types/react": "npm:types-react@19.0.0-rc.0",
44
+ "@types/react-dom": "npm:types-react-dom@19.0.0-rc.0"
45
+ },
40
46
  "scripts": {
41
- "build": "pnpm copyfiles && pnpm build:swc && pnpm build:types",
42
- "build:swc": "swc ./src -d ./dist --config-file .swcrc",
47
+ "build": "pnpm copyfiles && pnpm build:types && pnpm build:swc",
48
+ "build:swc": "swc ./src -d ./dist --config-file .swcrc --strip-leading-paths",
43
49
  "build:types": "tsc --emitDeclarationOnly --outDir dist",
44
50
  "clean": "rimraf {dist,*.tsbuildinfo}",
45
- "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/"
51
+ "copyfiles": "copyfiles -u 1 \"src/**/*.{html,css,scss,ttf,woff,woff2,eot,svg,jpg,png,json}\" dist/",
52
+ "lint": "eslint .",
53
+ "lint:fix": "eslint . --fix"
46
54
  }
47
55
  }