@uniformdev/canvas-next-rsc 19.51.1-alpha.1 → 19.51.1-alpha.26

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,4 +1,4 @@
1
- import { RouteClient } from '@uniformdev/canvas';
1
+ import { CANVAS_EDITOR_STATE, RouteClient } from '@uniformdev/canvas';
2
2
  import { isDevelopmentEnvironment } from '../utils/draft';
3
3
  import { buildPathTag } from '../utils/tag';
4
4
  export const getRouteClient = (options) => {
@@ -18,10 +18,13 @@ export const getRouteClient = (options) => {
18
18
  requestedUrl = new URL(req.url);
19
19
  }
20
20
  const tags = [];
21
+ let state;
21
22
  if (requestedUrl) {
22
23
  // this is here so this code breaks if parameters change here
23
24
  const pathKey = 'path';
25
+ const stateKey = 'state';
24
26
  const path = requestedUrl.searchParams.get(pathKey);
27
+ state = parseInt(requestedUrl.searchParams.get(stateKey) || '', 10);
25
28
  if (path) {
26
29
  // at this point, we do not know if this path is dynamic or not
27
30
  // so apply each segment as a tag so we can clear any segment, ie:
@@ -43,6 +46,10 @@ export const getRouteClient = (options) => {
43
46
  noCache = true;
44
47
  revalidate = undefined;
45
48
  }
49
+ const extraHeaders = {};
50
+ if (state === CANVAS_EDITOR_STATE) {
51
+ extraHeaders['x-bypass-cache'] = 'true';
52
+ }
46
53
  return fetch(req, {
47
54
  ...init,
48
55
  cache: noCache ? 'no-cache' : 'force-cache',
@@ -50,6 +57,10 @@ export const getRouteClient = (options) => {
50
57
  revalidate,
51
58
  tags: tags.length ? tags : undefined,
52
59
  },
60
+ headers: {
61
+ ...((init === null || init === void 0 ? void 0 : init.headers) || {}),
62
+ ...extraHeaders,
63
+ },
53
64
  });
54
65
  },
55
66
  });
@@ -8,6 +8,8 @@ export type CompositionContext = Omit<RouteGetResponseComposition, 'compositionA
8
8
  [key: string]: string | undefined;
9
9
  } | undefined;
10
10
  cookieValue: string | undefined;
11
+ isDraftMode: boolean;
12
+ isContextualEditing: boolean;
11
13
  };
12
14
  export type ComponentProps<TProps = unknown> = TProps & {
13
15
  component: ComponentInstance;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Suspense } from 'react';
3
+ import { isDraftModeEnabled, isIncontextEditingEnabled } from '../utils/draft';
3
4
  import { resolveComposition } from './retrieveRoute';
4
5
  import { UniformComponent } from './UniformComponent';
5
6
  import { UniformProvider } from './UniformContext';
@@ -24,6 +25,10 @@ const UniformCompositionInner = async ({ params, searchParams, update, children,
24
25
  path,
25
26
  searchParams,
26
27
  cookieValue,
28
+ isDraftMode: isDraftModeEnabled({ searchParams }),
29
+ isContextualEditing: isIncontextEditingEnabled({
30
+ searchParams,
31
+ }),
27
32
  ...rest,
28
33
  };
29
34
  return (_jsxs(UniformProvider, { cookieValue: cookieValue, seenComponents: seenComponents, children: [_jsx(UniformScript, { enabled: isCanvasEditing }), _jsx(UniformComponent, { data: evaluatedComposition, context: context }), Boolean(children) && children] }));
@@ -1,7 +1,5 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { PureUniformText } from '@uniformdev/canvas-react/core';
3
- import { isIncontextEditingEnabled } from '../utils/draft';
4
3
  export const UniformText = ({ context, ...rest }) => {
5
- const isEditing = isIncontextEditingEnabled(context);
6
- return _jsx(PureUniformText, { ...rest, isContextualEditing: isEditing, skipCustomRendering: isEditing });
4
+ return (_jsx(PureUniformText, { ...rest, isContextualEditing: context.isContextualEditing, skipCustomRendering: context.isContextualEditing }));
7
5
  };
@@ -1,11 +1,11 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { CANVAS_LOCALE_TAG_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, PLACEHOLDER_ID, } from '@uniformdev/canvas';
2
+ import { CANVAS_LOCALE_TAG_PARAM, CANVAS_PERSONALIZE_SLOT, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_SLOT, CANVAS_TEST_TYPE, IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, isComponentPlaceholderId, } from '@uniformdev/canvas';
3
3
  import { componentStoreResolver } from '../register/componentStoreResolver';
4
4
  import { isIncontextEditingEnabled } from '../utils/draft';
5
5
  import { convertComponentToProps } from './convertComponentToProps';
6
6
  import { UniformComponent } from './UniformComponent';
7
7
  export function renderComponent({ component, context, resolveSystem, key = 0, indexInSlot, slotName, parentComponent, slotChildrenCount, emptyPlaceholder, }) {
8
- var _a, _b, _c, _d, _e;
8
+ var _a, _b, _c, _d;
9
9
  const RenderComponent = componentStoreResolver(component);
10
10
  // custom handling for tests and personalizes
11
11
  if (component.type === CANVAS_TEST_TYPE) {
@@ -44,11 +44,9 @@ export function renderComponent({ component, context, resolveSystem, key = 0, in
44
44
  context,
45
45
  });
46
46
  const shouldRenderContextualEditingTags = Boolean(component._id) && isIncontextEditingEnabled(context);
47
- const isPlaceholder = component._id === PLACEHOLDER_ID;
48
- const isReadOnly = ((_a = component === null || component === void 0 ? void 0 : component._contextualEditing) === null || _a === void 0 ? void 0 : _a.isEditable)
49
- ? undefined
50
- : 'true';
51
- return (_jsx(UniformComponent, { data: component, context: context, children: _jsxs(_Fragment, { children: [!shouldRenderContextualEditingTags ? null : (_jsx("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, "data-parent-id": parentComponent === null || parentComponent === void 0 ? void 0 : parentComponent._id, "data-parent-type": parentComponent === null || parentComponent === void 0 ? void 0 : parentComponent.type, "data-component-id": component._id, "data-slot-name": slotName !== null && slotName !== void 0 ? slotName : '', "data-component-index": indexInSlot !== null && indexInSlot !== void 0 ? indexInSlot : '', "data-total-components": slotChildrenCount !== null && slotChildrenCount !== void 0 ? slotChildrenCount : '', "data-component-name": component.type, "data-is-placeholder": isPlaceholder ? 'true' : undefined, "data-is-localized": ((_b = component.parameters) === null || _b === void 0 ? void 0 : _b[CANVAS_LOCALE_TAG_PARAM]) ? 'true' : undefined, "data-component-title": (_e = (_d = (_c = component.parameters) === null || _c === void 0 ? void 0 : _c.title) === null || _d === void 0 ? void 0 : _d.value) !== null && _e !== void 0 ? _e : '', "data-is-readonly": isReadOnly }, key)), isPlaceholder && emptyPlaceholder !== undefined ? (emptyPlaceholder) : (_jsx(RenderComponent, { ...props })), !shouldRenderContextualEditingTags ? null : _jsx("script", { "data-role": "component-end" })] }) }, key));
47
+ const isPlaceholder = isComponentPlaceholderId(component._id);
48
+ const isReadOnly = false;
49
+ return (_jsx(UniformComponent, { data: component, context: context, children: _jsxs(_Fragment, { children: [!shouldRenderContextualEditingTags ? null : (_jsx("script", { "data-role": IN_CONTEXT_EDITOR_COMPONENT_START_ROLE, "data-parent-id": parentComponent === null || parentComponent === void 0 ? void 0 : parentComponent._id, "data-parent-type": parentComponent === null || parentComponent === void 0 ? void 0 : parentComponent.type, "data-component-id": component._id, "data-slot-name": slotName !== null && slotName !== void 0 ? slotName : '', "data-component-index": indexInSlot !== null && indexInSlot !== void 0 ? indexInSlot : '', "data-total-components": slotChildrenCount !== null && slotChildrenCount !== void 0 ? slotChildrenCount : '', "data-component-name": component.type, "data-is-placeholder": isPlaceholder ? 'true' : undefined, "data-is-localized": ((_a = component.parameters) === null || _a === void 0 ? void 0 : _a[CANVAS_LOCALE_TAG_PARAM]) ? 'true' : undefined, "data-component-title": (_d = (_c = (_b = component.parameters) === null || _b === void 0 ? void 0 : _b.title) === null || _c === void 0 ? void 0 : _c.value) !== null && _d !== void 0 ? _d : '', "data-is-readonly": isReadOnly }, key)), isPlaceholder && emptyPlaceholder !== undefined ? (emptyPlaceholder) : (_jsx(RenderComponent, { ...props })), !shouldRenderContextualEditingTags ? null : _jsx("script", { "data-role": "component-end" })] }) }, key));
52
50
  }
53
51
  return null;
54
52
  }
@@ -6,16 +6,13 @@ export const isDraftModeEnabled = ({ searchParams, }) => {
6
6
  if (isDevelopmentEnvironment()) {
7
7
  return isIncontextEditingEnabled({ searchParams });
8
8
  }
9
- return draftMode().isEnabled;
9
+ return draftMode().isEnabled || isIncontextEditingEnabled({ searchParams });
10
10
  };
11
11
  export const isIncontextEditingEnabled = ({ searchParams, }) => {
12
- // workaround for this https://github.com/vercel/next.js/issues/49927, as draftMode() is not working in dev mode
13
- // so we just need to check if the query string contains the IN_CONTEXT_EDITOR_QUERY_STRING_PARAM blindly
14
- if (isDevelopmentEnvironment() || draftMode().isEnabled) {
15
- const containsKey = typeof (searchParams === null || searchParams === void 0 ? void 0 : searchParams[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]) !== 'undefined';
16
- return containsKey;
17
- }
18
- return false;
12
+ // todo (adaml): draft mode can't be trusted in edge mode, consider in context editing if query string
13
+ // is present: https://github.com/vercel/next.js/issues/52080
14
+ const containsKey = typeof (searchParams === null || searchParams === void 0 ? void 0 : searchParams[IN_CONTEXT_EDITOR_QUERY_STRING_PARAM]) !== 'undefined';
15
+ return containsKey;
19
16
  };
20
17
  export const isOnVercelPreviewEnvironment = () => {
21
18
  return process.env.VERCEL_ENV === 'preview';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next-rsc",
3
- "version": "19.51.1-alpha.1+e55ae6c1e",
3
+ "version": "19.51.1-alpha.26+87b6d6f43",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "scripts": {
6
6
  "dev": "tsc --watch",
@@ -55,13 +55,13 @@
55
55
  "react-dom": "18.2.0"
56
56
  },
57
57
  "dependencies": {
58
- "@uniformdev/canvas": "19.51.1-alpha.1+e55ae6c1e",
59
- "@uniformdev/canvas-react": "19.51.1-alpha.1+e55ae6c1e",
60
- "@uniformdev/context": "19.51.1-alpha.1+e55ae6c1e",
61
- "@uniformdev/project-map": "19.51.1-alpha.1+e55ae6c1e",
62
- "@uniformdev/redirect": "19.51.1-alpha.1+e55ae6c1e",
63
- "@uniformdev/richtext": "19.51.1-alpha.1+e55ae6c1e",
64
- "@uniformdev/webhooks": "19.51.1-alpha.1+e55ae6c1e",
58
+ "@uniformdev/canvas": "19.51.1-alpha.26+87b6d6f43",
59
+ "@uniformdev/canvas-react": "19.51.1-alpha.26+87b6d6f43",
60
+ "@uniformdev/context": "19.51.1-alpha.26+87b6d6f43",
61
+ "@uniformdev/project-map": "19.51.1-alpha.26+87b6d6f43",
62
+ "@uniformdev/redirect": "19.51.1-alpha.26+87b6d6f43",
63
+ "@uniformdev/richtext": "19.51.1-alpha.26+87b6d6f43",
64
+ "@uniformdev/webhooks": "19.51.1-alpha.26+87b6d6f43",
65
65
  "@vercel/edge-config": "^0.2.0",
66
66
  "dequal": "^2.0.3",
67
67
  "js-cookie": "^3.0.5",
@@ -78,5 +78,5 @@
78
78
  "publishConfig": {
79
79
  "access": "public"
80
80
  },
81
- "gitHead": "e55ae6c1ea8df19f04a9dba22769d76e16d28d70"
81
+ "gitHead": "87b6d6f43ac5ed3bf05fbdba51dc239e04601dd1"
82
82
  }