@builder.io/react 2.0.4-0 → 2.0.4
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/builder-react-lite.cjs.js +1 -15
- package/dist/builder-react-lite.cjs.js.map +1 -1
- package/dist/builder-react-lite.esm.js +1 -15
- package/dist/builder-react-lite.esm.js.map +1 -1
- package/dist/builder-react.browser.js +2 -16
- package/dist/builder-react.browser.js.map +1 -1
- package/dist/builder-react.cjs.js +1 -15
- package/dist/builder-react.cjs.js.map +1 -1
- package/dist/builder-react.es5.js +1 -15
- package/dist/builder-react.es5.js.map +1 -1
- package/dist/builder-react.unpkg.js +2 -16
- package/dist/builder-react.unpkg.js.map +1 -1
- package/dist/lib/package.json +1 -1
- package/dist/lib/src/blocks/Section.js +2 -0
- package/dist/lib/src/blocks/Section.js.map +1 -1
- package/dist/lib/src/components/builder-block.component.js +3 -10
- package/dist/lib/src/components/builder-block.component.js.map +1 -1
- package/dist/lib/src/components/builder-blocks.component.js.map +1 -1
- package/dist/lib/src/components/builder-component.component.js.map +1 -1
- package/dist/lib/src/components/builder-content.component.js +3 -3
- package/dist/lib/src/components/builder-content.component.js.map +1 -1
- package/dist/lib/src/functions/apply-patch-with-mutation.js +1 -1
- package/dist/lib/src/functions/apply-patch-with-mutation.js.map +1 -1
- package/dist/lib/src/functions/apply-patch-with-mutation.test.js +54 -0
- package/dist/lib/src/functions/apply-patch-with-mutation.test.js.map +1 -0
- package/dist/lib/src/scripts/init-editing.js +1 -1
- package/dist/types/src/functions/apply-patch-with-mutation.d.ts +2 -2
- package/dist/types/src/functions/apply-patch-with-mutation.test.d.ts +1 -0
- package/package.json +1 -1
- package/src/blocks/Section.tsx +16 -11
- package/src/components/builder-block.component.tsx +3 -10
- package/src/components/builder-blocks.component.tsx +10 -8
- package/src/components/builder-component.component.tsx +16 -17
- package/src/components/builder-content.component.tsx +3 -4
- package/src/functions/apply-patch-with-mutation.test.ts +55 -0
- package/src/functions/apply-patch-with-mutation.ts +5 -5
- package/src/scripts/init-editing.ts +1 -1
|
@@ -98,7 +98,6 @@ const sizeMap = {
|
|
|
98
98
|
mobile: 'small',
|
|
99
99
|
};
|
|
100
100
|
|
|
101
|
-
|
|
102
101
|
const fetchCache: { [key: string]: any } = {};
|
|
103
102
|
|
|
104
103
|
export interface BuilderComponentProps {
|
|
@@ -1358,22 +1357,22 @@ export class BuilderComponent extends React.Component<
|
|
|
1358
1357
|
const builderModelRe = /builder\.io\/api\/v2\/([^\/\?]+)/i;
|
|
1359
1358
|
const builderModelMatch = url.match(builderModelRe);
|
|
1360
1359
|
const model = builderModelMatch && builderModelMatch[1];
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1360
|
+
this.handleRequest(key, finalUrl);
|
|
1361
|
+
const currentSubscription = this.httpSubscriptionPerKey[key];
|
|
1362
|
+
if (currentSubscription) {
|
|
1363
|
+
currentSubscription.unsubscribe();
|
|
1364
|
+
}
|
|
1365
|
+
|
|
1366
|
+
// TODO: fix this
|
|
1367
|
+
const newSubscription = (this.httpSubscriptionPerKey[key] =
|
|
1368
|
+
this.onStateChange.subscribe(() => {
|
|
1369
|
+
const newUrl = this.evalExpression(url);
|
|
1370
|
+
if (newUrl !== finalUrl) {
|
|
1371
|
+
this.handleRequest(key, newUrl);
|
|
1372
|
+
this.lastHttpRequests[key] = newUrl;
|
|
1373
|
+
}
|
|
1374
|
+
}));
|
|
1375
|
+
this.subscriptions.add(newSubscription);
|
|
1377
1376
|
} else {
|
|
1378
1377
|
this.handleRequest(key, this.evalExpression(url));
|
|
1379
1378
|
}
|
|
@@ -140,18 +140,17 @@ export class BuilderContent<ContentType extends object = any> extends React.Comp
|
|
|
140
140
|
if (location.href.includes('builder.debug=true')) {
|
|
141
141
|
eval('debugger');
|
|
142
142
|
}
|
|
143
|
-
let newData;
|
|
143
|
+
let newData = this.state.data as any;
|
|
144
144
|
for (const patch of patches) {
|
|
145
|
-
newData = applyPatchWithMinimalMutationChain(
|
|
145
|
+
newData = applyPatchWithMinimalMutationChain(newData, patch, false);
|
|
146
146
|
}
|
|
147
147
|
this.setState({
|
|
148
148
|
updates: this.state.updates + 1,
|
|
149
149
|
data: newData,
|
|
150
150
|
});
|
|
151
151
|
if (this.props.contentLoaded) {
|
|
152
|
-
this.props.contentLoaded(newData,
|
|
152
|
+
this.props.contentLoaded(newData.data, newData);
|
|
153
153
|
}
|
|
154
|
-
|
|
155
154
|
break;
|
|
156
155
|
}
|
|
157
156
|
}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { applyPatchWithMinimalMutationChain } from './apply-patch-with-mutation';
|
|
2
|
+
|
|
3
|
+
describe('applyPatchWithMinimalMutationChain', () => {
|
|
4
|
+
test('Basic shallow update', () => {
|
|
5
|
+
const obj = {
|
|
6
|
+
foo: 'bar',
|
|
7
|
+
};
|
|
8
|
+
const patch = {
|
|
9
|
+
op: 'replace',
|
|
10
|
+
path: '/foo',
|
|
11
|
+
value: '60px',
|
|
12
|
+
} as const;
|
|
13
|
+
const applied = applyPatchWithMinimalMutationChain(obj, patch);
|
|
14
|
+
expect(applied.foo).toBe('60px');
|
|
15
|
+
expect(applied).not.toBe(obj);
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
test('Deep object updates', () => {
|
|
19
|
+
const obj = {
|
|
20
|
+
foo: {
|
|
21
|
+
bar: true,
|
|
22
|
+
},
|
|
23
|
+
baz: {},
|
|
24
|
+
};
|
|
25
|
+
const patch = {
|
|
26
|
+
op: 'replace',
|
|
27
|
+
path: '/foo/bar',
|
|
28
|
+
value: '60px',
|
|
29
|
+
} as const;
|
|
30
|
+
const applied = applyPatchWithMinimalMutationChain(obj, patch);
|
|
31
|
+
expect(applied.foo.bar).toBe('60px');
|
|
32
|
+
expect(applied).not.toBe(obj);
|
|
33
|
+
expect(applied.foo).not.toBe(obj.foo);
|
|
34
|
+
expect(applied.baz).toBe(obj.baz);
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
test('Deep array updates', () => {
|
|
38
|
+
const obj = {
|
|
39
|
+
foo: [{ bar: true }],
|
|
40
|
+
baz: {},
|
|
41
|
+
};
|
|
42
|
+
const patch = {
|
|
43
|
+
op: 'replace',
|
|
44
|
+
path: '/foo/0/bar',
|
|
45
|
+
value: '60px',
|
|
46
|
+
} as const;
|
|
47
|
+
|
|
48
|
+
const applied = applyPatchWithMinimalMutationChain(obj, patch);
|
|
49
|
+
expect(applied.foo[0].bar).toBe('60px');
|
|
50
|
+
expect(applied).not.toBe(obj);
|
|
51
|
+
expect(applied.foo).not.toBe(obj.foo);
|
|
52
|
+
expect(applied.foo[0]).not.toBe(obj.foo[0]);
|
|
53
|
+
expect(applied.baz).toBe(obj.baz);
|
|
54
|
+
});
|
|
55
|
+
});
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
export const applyPatchWithMinimalMutationChain = (
|
|
2
|
-
obj:
|
|
1
|
+
export const applyPatchWithMinimalMutationChain = <T extends object>(
|
|
2
|
+
obj: T,
|
|
3
3
|
patch: { path: string; op: 'add' | 'remove' | 'replace'; value: any },
|
|
4
|
-
preserveRoot =
|
|
5
|
-
) => {
|
|
4
|
+
preserveRoot = false
|
|
5
|
+
): T => {
|
|
6
6
|
if (Object(obj) !== obj) {
|
|
7
7
|
return obj;
|
|
8
8
|
}
|
|
@@ -13,7 +13,7 @@ export const applyPatchWithMinimalMutationChain = (
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
const newObj = preserveRoot ? obj : { ...obj };
|
|
16
|
-
let objPart = newObj;
|
|
16
|
+
let objPart = newObj as any;
|
|
17
17
|
for (let i = 0; i < pathArr.length; i++) {
|
|
18
18
|
const isLast = i === pathArr.length - 1;
|
|
19
19
|
const property = pathArr[i];
|