@easy-cms/core 0.4.0 → 0.6.0
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.
- package/dist/index.d.ts +249 -14
- package/dist/index.js +1056 -113
- package/dist/live-preview.d.ts +8 -1
- package/dist/live-preview.js +7 -0
- package/package.json +1 -1
package/dist/live-preview.d.ts
CHANGED
|
@@ -18,6 +18,13 @@ interface LivePreviewOptions {
|
|
|
18
18
|
*/
|
|
19
19
|
readonly origin?: string | readonly string[];
|
|
20
20
|
}
|
|
21
|
+
/** Query parameter with the preview token that the admin adds to preview URLs. */
|
|
22
|
+
declare const PREVIEW_PARAM = "easy-cms-preview";
|
|
23
|
+
/**
|
|
24
|
+
* The preview token from the page URL, or `null`. Pass it on to read the document's draft
|
|
25
|
+
* without a login, e.g. `fetch(\`${api}/posts/${id}?preview=${token}&depth=2\`)`.
|
|
26
|
+
*/
|
|
27
|
+
declare function getPreviewToken(): string | null;
|
|
21
28
|
/** True when the page is shown inside a frame (e.g. the admin's preview). */
|
|
22
29
|
declare function isLivePreview(): boolean;
|
|
23
30
|
/**
|
|
@@ -30,4 +37,4 @@ declare function isLivePreview(): boolean;
|
|
|
30
37
|
*/
|
|
31
38
|
declare function subscribeLivePreview<T = Record<string, unknown>>(onChange: (doc: T, message: LivePreviewMessage<T>) => void, options?: LivePreviewOptions): () => void;
|
|
32
39
|
|
|
33
|
-
export { type LivePreviewMessage, type LivePreviewOptions, READY_MESSAGE, isLivePreview, subscribeLivePreview };
|
|
40
|
+
export { type LivePreviewMessage, type LivePreviewOptions, PREVIEW_PARAM, READY_MESSAGE, getPreviewToken, isLivePreview, subscribeLivePreview };
|
package/dist/live-preview.js
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
// src/live-preview.ts
|
|
2
2
|
var READY_MESSAGE = "easy-cms:preview-ready";
|
|
3
|
+
var PREVIEW_PARAM = "easy-cms-preview";
|
|
4
|
+
function getPreviewToken() {
|
|
5
|
+
if (typeof window === "undefined") return null;
|
|
6
|
+
return new URLSearchParams(window.location.search).get(PREVIEW_PARAM);
|
|
7
|
+
}
|
|
3
8
|
function isLivePreview() {
|
|
4
9
|
return typeof window !== "undefined" && window.parent !== window;
|
|
5
10
|
}
|
|
@@ -18,7 +23,9 @@ function subscribeLivePreview(onChange, options = {}) {
|
|
|
18
23
|
return () => window.removeEventListener("message", listener);
|
|
19
24
|
}
|
|
20
25
|
export {
|
|
26
|
+
PREVIEW_PARAM,
|
|
21
27
|
READY_MESSAGE,
|
|
28
|
+
getPreviewToken,
|
|
22
29
|
isLivePreview,
|
|
23
30
|
subscribeLivePreview
|
|
24
31
|
};
|