@uniformdev/canvas-next-rsc 19.45.0 → 19.45.1
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,5 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { CANVAS_DRAFT_STATE, CANVAS_PUBLISHED_STATE } from '@uniformdev/canvas';
|
|
2
|
+
import { CANVAS_DRAFT_STATE, CANVAS_EDITOR_STATE, CANVAS_PUBLISHED_STATE } from '@uniformdev/canvas';
|
|
3
3
|
import { notFound, redirect } from 'next/navigation';
|
|
4
4
|
import { Suspense } from 'react';
|
|
5
5
|
import { getManifestFromApi } from '../client/manifestClient';
|
|
@@ -34,10 +34,17 @@ const UniformCompositionInner = async ({ params, searchParams, children }) => {
|
|
|
34
34
|
const path = resolvePath({
|
|
35
35
|
params,
|
|
36
36
|
});
|
|
37
|
+
let state;
|
|
38
|
+
if (isCanvasEditing) {
|
|
39
|
+
state = CANVAS_EDITOR_STATE;
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
state = draftMode || previewEnvironment || isDevelopment ? CANVAS_DRAFT_STATE : CANVAS_PUBLISHED_STATE;
|
|
43
|
+
}
|
|
37
44
|
// resolve the route from the path
|
|
38
45
|
const resolveResult = await retrieveRoute({
|
|
39
46
|
path,
|
|
40
|
-
state
|
|
47
|
+
state,
|
|
41
48
|
searchParams,
|
|
42
49
|
});
|
|
43
50
|
// if the route is a redirect, redirect
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
'use client';
|
|
2
2
|
import { Fragment as _Fragment, jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
-
import { createCanvasChannel
|
|
3
|
+
import { createCanvasChannel } from '@uniformdev/canvas';
|
|
4
|
+
import { useRouter } from 'next/navigation';
|
|
4
5
|
import { useEffect, useMemo } from 'react';
|
|
5
6
|
export const UniformScript = ({ enabled }) => {
|
|
7
|
+
const router = useRouter();
|
|
6
8
|
const channel = useMemo(() => {
|
|
7
9
|
var _a;
|
|
8
10
|
if (typeof window === 'undefined') {
|
|
@@ -18,39 +20,13 @@ export const UniformScript = ({ enabled }) => {
|
|
|
18
20
|
if (!channel) {
|
|
19
21
|
return;
|
|
20
22
|
}
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
if (isUpdateCompositionInternalMessage(data)) {
|
|
24
|
-
const url = new URL(window.location.href);
|
|
25
|
-
if (url.searchParams.get('vcdiffhash') === ((_a = data.hash) === null || _a === void 0 ? void 0 : _a.toString())) {
|
|
26
|
-
// eslint-disable-next-line no-console
|
|
27
|
-
console.log("Skipping composition update because it's already been applied.");
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const response = await fetch('/api/uniform', {
|
|
31
|
-
method: 'POST',
|
|
32
|
-
body: JSON.stringify(data),
|
|
33
|
-
});
|
|
34
|
-
if (!response.ok) {
|
|
35
|
-
// eslint-disable-next-line no-console
|
|
36
|
-
console.error(response);
|
|
37
|
-
return;
|
|
38
|
-
}
|
|
39
|
-
const json = (await response.json());
|
|
40
|
-
if (json.diff.length) {
|
|
41
|
-
const serialized = Buffer.from(JSON.stringify(json.diff)).toString('base64');
|
|
42
|
-
// set serialized as query string param
|
|
43
|
-
url.searchParams.set('vcdiff', serialized);
|
|
44
|
-
url.searchParams.set('vcdiffhash', (_c = (_b = data.hash) === null || _b === void 0 ? void 0 : _b.toString()) !== null && _c !== void 0 ? _c : '');
|
|
45
|
-
// set url
|
|
46
|
-
window.location.href = url.toString();
|
|
47
|
-
}
|
|
48
|
-
}
|
|
23
|
+
const unsubscribeFromEditorUpdates = channel.on('editor-state-updated', () => {
|
|
24
|
+
router.refresh();
|
|
49
25
|
});
|
|
50
26
|
return () => {
|
|
51
|
-
|
|
27
|
+
unsubscribeFromEditorUpdates();
|
|
52
28
|
};
|
|
53
|
-
}, [channel]);
|
|
29
|
+
}, [channel, router]);
|
|
54
30
|
useEffect(() => {
|
|
55
31
|
if (typeof window === 'undefined') {
|
|
56
32
|
return;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CANVAS_DRAFT_STATE } from '@uniformdev/canvas';
|
|
1
|
+
import { CANVAS_DRAFT_STATE, CANVAS_EDITOR_STATE, } from '@uniformdev/canvas';
|
|
2
2
|
import { RedirectClient } from '@uniformdev/redirect';
|
|
3
3
|
import { get } from '@vercel/edge-config';
|
|
4
4
|
import { getRouteClient } from '../client/routeClient';
|
|
@@ -19,6 +19,13 @@ export const retrieveRoute = async (data) => {
|
|
|
19
19
|
const routeApiValue = await resolveRouteByRouteApi(data);
|
|
20
20
|
result = routeApiValue;
|
|
21
21
|
}
|
|
22
|
+
// fall back to draft if requesting editor state
|
|
23
|
+
if (result.type === 'notFound' && data.state === CANVAS_EDITOR_STATE) {
|
|
24
|
+
return retrieveRoute({
|
|
25
|
+
...data,
|
|
26
|
+
state: CANVAS_DRAFT_STATE,
|
|
27
|
+
});
|
|
28
|
+
}
|
|
22
29
|
return result;
|
|
23
30
|
};
|
|
24
31
|
export const resolveRedirectHref = (resolveResult, path) => {
|
|
@@ -63,7 +70,7 @@ const resolveRouteByRouteApi = async (data) => {
|
|
|
63
70
|
const routeResult = await routeClient.getRoute({
|
|
64
71
|
path: data.path,
|
|
65
72
|
state: data.state,
|
|
66
|
-
withComponentIDs: data.state === CANVAS_DRAFT_STATE,
|
|
73
|
+
withComponentIDs: data.state === CANVAS_DRAFT_STATE || data.state === CANVAS_EDITOR_STATE,
|
|
67
74
|
withContentSourceMap: isOnVercelPreviewEnvironment(),
|
|
68
75
|
});
|
|
69
76
|
return routeResult;
|
package/dist/utils/draft.js
CHANGED
|
@@ -11,7 +11,7 @@ export const isDraftModeEnabled = ({ searchParams, }) => {
|
|
|
11
11
|
export const isIncontextEditingEnabled = ({ searchParams, }) => {
|
|
12
12
|
// workaround for this https://github.com/vercel/next.js/issues/49927, as draftMode() is not working in dev mode
|
|
13
13
|
// so we just need to check if the query string contains the IN_CONTEXT_EDITOR_QUERY_STRING_PARAM blindly
|
|
14
|
-
if (isDevelopmentEnvironment()) {
|
|
14
|
+
if (isDevelopmentEnvironment() || draftMode().isEnabled) {
|
|
15
15
|
const containsKey = typeof (searchParams === null || searchParams === void 0 ? void 0 : searchParams[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]) !== 'undefined';
|
|
16
16
|
return containsKey;
|
|
17
17
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uniformdev/canvas-next-rsc",
|
|
3
|
-
"version": "19.45.
|
|
3
|
+
"version": "19.45.1",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"dev": "pnpm build --watch",
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"typescript": "^5.0.4"
|
|
57
57
|
},
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@uniformdev/canvas": "19.45.
|
|
60
|
-
"@uniformdev/canvas-react": "19.45.
|
|
61
|
-
"@uniformdev/context": "19.45.
|
|
62
|
-
"@uniformdev/project-map": "19.45.
|
|
63
|
-
"@uniformdev/redirect": "19.45.
|
|
64
|
-
"@uniformdev/richtext": "19.45.
|
|
65
|
-
"@uniformdev/webhooks": "19.45.
|
|
59
|
+
"@uniformdev/canvas": "19.45.1",
|
|
60
|
+
"@uniformdev/canvas-react": "19.45.1",
|
|
61
|
+
"@uniformdev/context": "19.45.1",
|
|
62
|
+
"@uniformdev/project-map": "19.45.1",
|
|
63
|
+
"@uniformdev/redirect": "19.45.1",
|
|
64
|
+
"@uniformdev/richtext": "19.45.1",
|
|
65
|
+
"@uniformdev/webhooks": "19.45.1",
|
|
66
66
|
"@vercel/edge-config": "^0.2.0",
|
|
67
67
|
"dequal": "^2.0.3",
|
|
68
68
|
"js-cookie": "^3.0.5",
|
|
@@ -76,5 +76,5 @@
|
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
},
|
|
79
|
-
"gitHead": "
|
|
79
|
+
"gitHead": "27d329b913db64152e9d49bcfa7dddf8b3b31bb6"
|
|
80
80
|
}
|