@payloadcms/live-preview-react 3.41.0-canary.0 → 3.41.0-canary.2

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,10 +1,23 @@
1
- export declare const useLivePreview: <T extends Record<string, unknown>>(props: {
1
+ /**
2
+ * This is a React hook to implement {@link https://payloadcms.com/docs/live-preview/overview Payload Live Preview}.
3
+ *
4
+ * @link https://payloadcms.com/docs/live-preview/frontend
5
+ */
6
+ export declare const useLivePreview: <T extends Record<string, any>>(props: {
2
7
  apiRoute?: string;
3
8
  depth?: number;
9
+ /**
10
+ * To prevent the flicker of missing data on initial load,
11
+ * you can pass in the initial page data from the server.
12
+ */
4
13
  initialData: T;
5
14
  serverURL: string;
6
15
  }) => {
7
16
  data: T;
17
+ /**
18
+ * To prevent the flicker of stale data while the post message is being sent,
19
+ * you can conditionally render loading UI based on the `isLoading` state.
20
+ */
8
21
  isLoading: boolean;
9
22
  };
10
23
  //# sourceMappingURL=useLivePreview.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useLivePreview.d.ts","sourceRoot":"","sources":["../src/useLivePreview.ts"],"names":[],"mappings":"AASA,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,SAAS;IACvE,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":"AAIA;;;;GAIG;AAEH,eAAO,MAAM,cAAc,GAAI,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,SAAS;IACnE,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd;;;OAGG;IACH,WAAW,EAAE,CAAC,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB,KAAG;IACF,IAAI,EAAE,CAAC,CAAA;IACP;;;OAGG;IACH,SAAS,EAAE,OAAO,CAAA;CAsCnB,CAAA"}
@@ -1,10 +1,11 @@
1
1
  'use client';
2
2
  import { ready, subscribe, unsubscribe } from '@payloadcms/live-preview';
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
- // To prevent the flicker of missing data on initial load,
5
- // you can pass in the initial page data from the server
6
- // To prevent the flicker of stale data while the post message is being sent,
7
- // you can conditionally render loading UI based on the `isLoading` state
4
+ /**
5
+ * This is a React hook to implement {@link https://payloadcms.com/docs/live-preview/overview Payload Live Preview}.
6
+ *
7
+ * @link https://payloadcms.com/docs/live-preview/frontend
8
+ */ // NOTE: cannot use Record<string, unknown> here bc generated interfaces will not satisfy the type constraint
8
9
  export const useLivePreview = (props)=>{
9
10
  const { apiRoute, depth, initialData, serverURL } = props;
10
11
  const [data, setData] = useState(initialData);
@@ -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 Record<string, unknown>>(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: T) => {\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,CAAoCC;IAShE,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/**\n * This is a React hook to implement {@link https://payloadcms.com/docs/live-preview/overview Payload Live Preview}.\n *\n * @link https://payloadcms.com/docs/live-preview/frontend\n */\n// NOTE: cannot use Record<string, unknown> here bc generated interfaces will not satisfy the type constraint\nexport const useLivePreview = <T extends Record<string, any>>(props: {\n apiRoute?: string\n depth?: number\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 */\n initialData: T\n serverURL: string\n}): {\n data: T\n /**\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 */\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: T) => {\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;;;;CAIC,GACD,6GAA6G;AAC7G,OAAO,MAAMC,iBAAiB,CAAgCC;IAiB5D,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,6 +1,6 @@
1
1
  {
2
2
  "name": "@payloadcms/live-preview-react",
3
- "version": "3.41.0-canary.0",
3
+ "version": "3.41.0-canary.2",
4
4
  "description": "The official React SDK for Payload Live Preview",
5
5
  "homepage": "https://payloadcms.com",
6
6
  "repository": {
@@ -18,6 +18,7 @@
18
18
  }
19
19
  ],
20
20
  "type": "module",
21
+ "sideEffects": false,
21
22
  "exports": {
22
23
  ".": {
23
24
  "import": "./dist/index.js",
@@ -31,13 +32,13 @@
31
32
  "dist"
32
33
  ],
33
34
  "dependencies": {
34
- "@payloadcms/live-preview": "3.41.0-canary.0"
35
+ "@payloadcms/live-preview": "3.41.0-canary.2"
35
36
  },
36
37
  "devDependencies": {
37
38
  "@types/react": "19.1.0",
38
39
  "@types/react-dom": "19.1.2",
39
40
  "@payloadcms/eslint-config": "3.28.0",
40
- "payload": "3.41.0-canary.0"
41
+ "payload": "3.41.0-canary.2"
41
42
  },
42
43
  "peerDependencies": {
43
44
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 || ^19.0.0-rc-65a56d0e-20241020",