@uniformdev/canvas-next-rsc 19.58.2-alpha.0 → 19.59.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.
@@ -11,7 +11,7 @@ jest.mock('../getUniformContext', () => ({
11
11
  },
12
12
  }));
13
13
  describe('evaluateComposition', () => {
14
- it('should localize a compoisition when dynmaic inputs include locale token', async () => {
14
+ it('should localize a composition when dynmaic inputs include locale token', async () => {
15
15
  var _a, _b;
16
16
  const root = {
17
17
  _id: 'root',
@@ -1,4 +1,4 @@
1
- import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_TYPE, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, walkComponentTree, } from '@uniformdev/canvas';
1
+ import { CANVAS_PERSONALIZATION_PARAM, CANVAS_PERSONALIZE_TYPE, CANVAS_TEST_TYPE, localize, mapSlotToPersonalizedVariations, mapSlotToTestVariations, walkNodeTree, } from '@uniformdev/canvas';
2
2
  import { UNIFORM_DEFAULT_COOKIE_NAME } from '@uniformdev/context';
3
3
  import { getServerConfig } from '../config/helpers';
4
4
  import { serializeCookie } from '../score';
@@ -56,8 +56,13 @@ export const evaluateComposition = async ({ root, params, searchParams, dynamicI
56
56
  }
57
57
  const enrichmentTags = [];
58
58
  const seenComponents = [];
59
- walkComponentTree(composition, (component, _ancestors, actions) => {
59
+ walkNodeTree(composition, ({ type, node: component, actions }) => {
60
60
  var _a, _b, _c, _d, _e, _f;
61
+ if (type !== 'component') {
62
+ // we ignore blocks for now
63
+ actions.stopProcessingDescendants();
64
+ return;
65
+ }
61
66
  let replacementComponents;
62
67
  // evaluate personalization components
63
68
  if (component.type === CANVAS_PERSONALIZE_TYPE) {
@@ -119,12 +124,12 @@ export const evaluateComposition = async ({ root, params, searchParams, dynamicI
119
124
  if (typeof replacementComponents !== 'undefined') {
120
125
  // if no variants were selected, just remove the current component. no matches.
121
126
  if (replacementComponents.length === 0) {
122
- actions.removeComponent();
127
+ actions.remove();
123
128
  }
124
129
  else {
125
130
  const [first, ...rest] = replacementComponents;
126
131
  // replace the first component
127
- actions.replaceComponent(first);
132
+ actions.replace(first);
128
133
  // if there are other components, insert them after the first
129
134
  if (rest.length) {
130
135
  actions.insertAfter(rest);
@@ -145,7 +150,11 @@ export const evaluateComposition = async ({ root, params, searchParams, dynamicI
145
150
  // to pass API validation. walk the composition and add them back in, assume
146
151
  // everything is editable.
147
152
  if (isIncontextEditingEnabled({ searchParams })) {
148
- walkComponentTree(composition, (component) => {
153
+ walkNodeTree(composition, ({ node: component, actions, type }) => {
154
+ if (type !== 'component') {
155
+ actions.stopProcessingDescendants();
156
+ return;
157
+ }
149
158
  if (component.parameters) {
150
159
  const params = Object.keys(component.parameters);
151
160
  params.forEach((key) => {
@@ -1,14 +1,25 @@
1
- import { walkComponentTree } from '@uniformdev/canvas';
1
+ import { walkNodeTree } from '@uniformdev/canvas';
2
2
  export const getAllComponents = (composition) => {
3
3
  const ids = {};
4
- walkComponentTree(composition, (component, ancestors) => {
5
- if (component._id) {
6
- const [self, parent] = ancestors;
7
- ids[component._id] = {
8
- parentId: parent === null || parent === void 0 ? void 0 : parent.component._id,
9
- slot: self === null || self === void 0 ? void 0 : self.parentSlot,
10
- slotIndex: self === null || self === void 0 ? void 0 : self.parentSlotIndex,
11
- component,
4
+ walkNodeTree(composition, ({ type, actions, node, ancestorsAndSelf }) => {
5
+ if (type !== 'component') {
6
+ // don't want blocks here
7
+ actions.stopProcessingDescendants();
8
+ return;
9
+ }
10
+ if (node._id) {
11
+ const [self, parent] = ancestorsAndSelf;
12
+ if (self.type === 'block') {
13
+ // just to make TS happy, we already know this is true due to the preceding type-prop check
14
+ return;
15
+ }
16
+ const slotIndex = self.type === 'root' ? undefined : self.parentSlotIndex;
17
+ const slot = self.type === 'root' ? undefined : self.parentSlot;
18
+ ids[node._id] = {
19
+ parentId: parent === null || parent === void 0 ? void 0 : parent.node._id,
20
+ slot,
21
+ slotIndex,
22
+ component: node,
12
23
  };
13
24
  }
14
25
  });
@@ -16,9 +27,16 @@ export const getAllComponents = (composition) => {
16
27
  };
17
28
  export const getComponent = (composition, id) => {
18
29
  let result;
19
- walkComponentTree(composition, (component) => {
20
- if (component._id === id) {
21
- result = component;
30
+ walkNodeTree(composition, ({ type, node, actions }) => {
31
+ // note: does not work on blocks because it didn't before - so leaving that for back compat
32
+ // no technical reason I know of why we can't let it find blocks by ID
33
+ if (type !== 'component') {
34
+ actions.stopProcessingDescendants();
35
+ return;
36
+ }
37
+ if (node._id === id) {
38
+ result = node;
39
+ actions.stopProcessingDescendants();
22
40
  }
23
41
  });
24
42
  return result;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@uniformdev/canvas-next-rsc",
3
- "version": "19.58.2-alpha.0+68d890cf9",
3
+ "version": "19.59.0",
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.58.2-alpha.0+68d890cf9",
59
- "@uniformdev/canvas-react": "19.58.2-alpha.0+68d890cf9",
60
- "@uniformdev/context": "19.58.2-alpha.0+68d890cf9",
61
- "@uniformdev/project-map": "19.58.2-alpha.0+68d890cf9",
62
- "@uniformdev/redirect": "19.58.2-alpha.0+68d890cf9",
63
- "@uniformdev/richtext": "19.58.2-alpha.0+68d890cf9",
64
- "@uniformdev/webhooks": "19.58.2-alpha.0+68d890cf9",
58
+ "@uniformdev/canvas": "19.59.0",
59
+ "@uniformdev/canvas-react": "19.59.0",
60
+ "@uniformdev/context": "19.59.0",
61
+ "@uniformdev/project-map": "19.59.0",
62
+ "@uniformdev/redirect": "19.59.0",
63
+ "@uniformdev/richtext": "19.59.0",
64
+ "@uniformdev/webhooks": "19.59.0",
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": "68d890cf94dc44136dd88bcc2d703248bae10bea"
81
+ "gitHead": "912b2badf364d2959cb0b664ba16d9741f16add5"
82
82
  }