@builder.io/react 2.0.4-1 → 2.0.4-10
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 -1
- package/dist/builder-react-lite.cjs.js.map +1 -1
- package/dist/builder-react-lite.esm.js +1 -1
- package/dist/builder-react-lite.esm.js.map +1 -1
- package/dist/builder-react.browser.js +1 -10
- package/dist/builder-react.browser.js.map +1 -1
- package/dist/builder-react.cjs.js +1 -1
- package/dist/builder-react.cjs.js.map +1 -1
- package/dist/builder-react.es5.js +1 -1
- package/dist/builder-react.es5.js.map +1 -1
- package/dist/builder-react.unpkg.js +1 -10
- package/dist/builder-react.unpkg.js.map +1 -1
- package/dist/lib/package.json +4 -2
- package/dist/lib/src/blocks/Embed.js.map +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/blocks/Symbol.js +2 -2
- package/dist/lib/src/blocks/Symbol.js.map +1 -1
- package/dist/lib/src/components/builder-block.component.js +15 -6
- 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 +16 -6
- package/dist/lib/src/components/builder-component.component.js.map +1 -1
- package/dist/lib/src/components/builder-content.component.js +1 -1
- package/dist/lib/src/components/builder-content.component.js.map +1 -1
- package/dist/lib/src/constants/device-sizes.constant.js.map +1 -1
- package/dist/lib/src/scripts/init-editing.js +1 -1
- package/dist/types/src/blocks/Mutation.d.ts +1 -0
- package/dist/types/src/blocks/Slot.d.ts +1 -0
- package/dist/types/src/blocks/raw/RawText.d.ts +1 -0
- package/dist/types/src/components/builder-component.component.d.ts +6 -0
- package/package.json +4 -2
- package/src/blocks/Section.tsx +16 -11
- package/src/blocks/Symbol.tsx +1 -0
- package/src/components/builder-block.component.tsx +24 -9
- package/src/components/builder-blocks.component.tsx +10 -8
- package/src/components/builder-component.component.tsx +36 -21
- package/src/components/builder-content.component.tsx +1 -1
- package/src/scripts/init-editing.ts +1 -1
|
@@ -181,6 +181,10 @@ export interface BuilderComponentProps {
|
|
|
181
181
|
* navigation to other pages unintended
|
|
182
182
|
*/
|
|
183
183
|
stopClickPropagationWhenEditing?: boolean;
|
|
184
|
+
/**
|
|
185
|
+
* Locale code, should match one of the locales in your spaces locale, wll auto resolve the localized inputs to the localized value
|
|
186
|
+
*/
|
|
187
|
+
locale?: string;
|
|
184
188
|
}
|
|
185
189
|
export interface BuilderComponentState {
|
|
186
190
|
state: any;
|
|
@@ -247,6 +251,7 @@ export declare class BuilderComponent extends React.Component<BuilderComponentPr
|
|
|
247
251
|
url?: string | undefined;
|
|
248
252
|
isChild?: boolean | undefined;
|
|
249
253
|
stopClickPropagationWhenEditing?: boolean | undefined;
|
|
254
|
+
locale?: string | undefined;
|
|
250
255
|
children?: React.ReactNode;
|
|
251
256
|
};
|
|
252
257
|
get name(): string | undefined;
|
|
@@ -295,6 +300,7 @@ export declare class BuilderComponent extends React.Component<BuilderComponentPr
|
|
|
295
300
|
checkStyles(data: any): void;
|
|
296
301
|
reload(): void;
|
|
297
302
|
get content(): Content | undefined;
|
|
303
|
+
get externalState(): any;
|
|
298
304
|
get useContent(): any;
|
|
299
305
|
render(): JSX.Element;
|
|
300
306
|
evalExpression(expression: string): string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/react",
|
|
3
|
-
"version": "2.0.4-
|
|
3
|
+
"version": "2.0.4-10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"main": "dist/builder-react.cjs.js",
|
|
@@ -75,6 +75,7 @@
|
|
|
75
75
|
"@types/rollup-plugin-commonjs": "^9.2.0",
|
|
76
76
|
"@types/rollup-plugin-json": "^3.0.3",
|
|
77
77
|
"@types/rollup-plugin-node-resolve": "^4.1.0",
|
|
78
|
+
"@types/traverse": "^0.6.32",
|
|
78
79
|
"colors": "^1.1.2",
|
|
79
80
|
"commitizen": "^4.2.4",
|
|
80
81
|
"coveralls": "^3.0.0",
|
|
@@ -123,10 +124,11 @@
|
|
|
123
124
|
"react-dom": ">=16.8.0"
|
|
124
125
|
},
|
|
125
126
|
"dependencies": {
|
|
126
|
-
"@builder.io/sdk": "^1.1.
|
|
127
|
+
"@builder.io/sdk": "^1.1.28-1",
|
|
127
128
|
"@emotion/core": "^10.0.17",
|
|
128
129
|
"hash-sum": "^2.0.0",
|
|
129
130
|
"preact": "^10.1.0",
|
|
131
|
+
"traverse": "^0.6.6",
|
|
130
132
|
"vm2": "^3.9.10"
|
|
131
133
|
},
|
|
132
134
|
"gitHead": "4d96fbc32864698afbb355ab991c6d90be991951"
|
package/src/blocks/Section.tsx
CHANGED
|
@@ -40,18 +40,23 @@ class SectionComponent extends React.Component<SectionProps, { inView?: boolean
|
|
|
40
40
|
if (typeof IntersectionObserver === 'undefined' || !this.ref) {
|
|
41
41
|
this.setState({ inView: true });
|
|
42
42
|
} else {
|
|
43
|
-
const observer = new IntersectionObserver(
|
|
44
|
-
entries
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
43
|
+
const observer = new IntersectionObserver(
|
|
44
|
+
(entries, observer) => {
|
|
45
|
+
entries.forEach(entry => {
|
|
46
|
+
if (entry.intersectionRatio > 0) {
|
|
47
|
+
this.setState({
|
|
48
|
+
inView: true,
|
|
49
|
+
});
|
|
50
|
+
if (this.ref) {
|
|
51
|
+
observer.unobserve(this.ref);
|
|
52
|
+
}
|
|
51
53
|
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
54
|
+
});
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
rootMargin: '10px',
|
|
58
|
+
}
|
|
59
|
+
);
|
|
55
60
|
|
|
56
61
|
observer.observe(this.ref);
|
|
57
62
|
|
package/src/blocks/Symbol.tsx
CHANGED
|
@@ -121,6 +121,7 @@ class SymbolComponent extends React.Component<SymbolProps> {
|
|
|
121
121
|
this.placeholder
|
|
122
122
|
) : (
|
|
123
123
|
<BuilderComponent
|
|
124
|
+
{...state.state?.locale && { locale: state.state.locale}}
|
|
124
125
|
isChild
|
|
125
126
|
ref={(ref: any) => (this.ref = ref)}
|
|
126
127
|
context={{ ...state.context, symbolId: this.props.builderBlock?.id }}
|
|
@@ -11,6 +11,7 @@ import { BuilderStoreContext } from '../store/builder-store';
|
|
|
11
11
|
import { applyPatchWithMinimalMutationChain } from '../functions/apply-patch-with-mutation';
|
|
12
12
|
import { blockToHtmlString } from '../functions/block-to-html-string';
|
|
13
13
|
import { Link } from './Link';
|
|
14
|
+
import traverse from 'traverse';
|
|
14
15
|
|
|
15
16
|
const camelCaseToKebabCase = (str?: string) =>
|
|
16
17
|
str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
@@ -18,6 +19,21 @@ const camelCaseToKebabCase = (str?: string) =>
|
|
|
18
19
|
const kebabCaseToCamelCase = (str = '') =>
|
|
19
20
|
str.replace(/-([a-z])/g, match => match[1].toUpperCase());
|
|
20
21
|
|
|
22
|
+
const localizedType = '@builder.io/core:LocalizedValue';
|
|
23
|
+
const resolveLocalizedOptions = (options?: any, locale?: string) => {
|
|
24
|
+
if (!locale || !options) {
|
|
25
|
+
return options;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const result = traverse(options).map(function (el) {
|
|
29
|
+
if (el && el['@type'] === localizedType) {
|
|
30
|
+
this.update(el[locale] || el.Default);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
|
|
21
37
|
const Device = { desktop: 0, tablet: 1, mobile: 2 };
|
|
22
38
|
|
|
23
39
|
const voidElements = new Set([
|
|
@@ -248,13 +264,9 @@ export class BuilderBlock extends React.Component<
|
|
|
248
264
|
}
|
|
249
265
|
|
|
250
266
|
if (location.href.includes('builder.debug=true')) {
|
|
251
|
-
|
|
267
|
+
eval('debugger');
|
|
252
268
|
}
|
|
253
269
|
for (const patch of patches) {
|
|
254
|
-
// TODO: soehow mark this.block as a new object,
|
|
255
|
-
// e.g. access it's parent hm. maybe do the listning mutations
|
|
256
|
-
// on hte parent element not the child (or rather
|
|
257
|
-
// send the message to the parent)
|
|
258
270
|
applyPatchWithMinimalMutationChain(this.props.block, patch, true);
|
|
259
271
|
}
|
|
260
272
|
this.setState({ updates: this.state.updates + 1 });
|
|
@@ -456,10 +468,13 @@ export class BuilderBlock extends React.Component<
|
|
|
456
468
|
}
|
|
457
469
|
}
|
|
458
470
|
|
|
459
|
-
const innerComponentProperties = (
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
471
|
+
const innerComponentProperties = resolveLocalizedOptions(
|
|
472
|
+
(options.component || options.options) && {
|
|
473
|
+
...options.options,
|
|
474
|
+
...(options.component.options || options.component.data),
|
|
475
|
+
},
|
|
476
|
+
this.privateState.state.locale
|
|
477
|
+
);
|
|
463
478
|
|
|
464
479
|
const isVoid = voidElements.has(TagName);
|
|
465
480
|
|
|
@@ -108,14 +108,16 @@ export class BuilderBlocks extends React.Component<BuilderBlocksProps, BuilderBl
|
|
|
108
108
|
// TODO: only fi in iframe?
|
|
109
109
|
builder-path={Builder.isIframe ? this.path : undefined}
|
|
110
110
|
builder-parent-id={this.parentId}
|
|
111
|
-
css={
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
css={
|
|
112
|
+
{
|
|
113
|
+
...(!this.props.emailMode && {
|
|
114
|
+
display: 'flex',
|
|
115
|
+
flexDirection: 'column',
|
|
116
|
+
alignItems: 'stretch',
|
|
117
|
+
}),
|
|
118
|
+
...this.props.style,
|
|
119
|
+
} as any
|
|
120
|
+
}
|
|
119
121
|
onClick={() => {
|
|
120
122
|
if (this.noBlocks) {
|
|
121
123
|
this.onClickEmptyBlocks();
|
|
@@ -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 {
|
|
@@ -277,6 +276,11 @@ export interface BuilderComponentProps {
|
|
|
277
276
|
* navigation to other pages unintended
|
|
278
277
|
*/
|
|
279
278
|
stopClickPropagationWhenEditing?: boolean;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Locale code, should match one of the locales in your spaces locale, wll auto resolve the localized inputs to the localized value
|
|
282
|
+
*/
|
|
283
|
+
locale?: string;
|
|
280
284
|
}
|
|
281
285
|
|
|
282
286
|
export interface BuilderComponentState {
|
|
@@ -841,7 +845,7 @@ export class BuilderComponent extends React.Component<
|
|
|
841
845
|
get data() {
|
|
842
846
|
const data = {
|
|
843
847
|
...(this.inlinedContent && this.inlinedContent.data?.state),
|
|
844
|
-
...this.
|
|
848
|
+
...this.externalState,
|
|
845
849
|
...this.state.state,
|
|
846
850
|
};
|
|
847
851
|
Object.assign(this.rootState, data);
|
|
@@ -852,7 +856,7 @@ export class BuilderComponent extends React.Component<
|
|
|
852
856
|
// TODO: shallow diff
|
|
853
857
|
if (this.props.data && prevProps.data !== this.props.data) {
|
|
854
858
|
this.state.update((state: any) => {
|
|
855
|
-
Object.assign(state, this.
|
|
859
|
+
Object.assign(state, this.externalState);
|
|
856
860
|
});
|
|
857
861
|
}
|
|
858
862
|
|
|
@@ -892,6 +896,13 @@ export class BuilderComponent extends React.Component<
|
|
|
892
896
|
return content;
|
|
893
897
|
}
|
|
894
898
|
|
|
899
|
+
get externalState() {
|
|
900
|
+
return {
|
|
901
|
+
...this.props.data,
|
|
902
|
+
...(this.props.locale ? { locale: this.props.locale } : {}),
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
|
|
895
906
|
get useContent() {
|
|
896
907
|
return this.content || this.state.context.builderContent;
|
|
897
908
|
}
|
|
@@ -900,7 +911,10 @@ export class BuilderComponent extends React.Component<
|
|
|
900
911
|
const content = this.content;
|
|
901
912
|
|
|
902
913
|
const dataString =
|
|
903
|
-
Builder.isBrowser &&
|
|
914
|
+
Builder.isBrowser &&
|
|
915
|
+
this.externalState &&
|
|
916
|
+
size(this.externalState) &&
|
|
917
|
+
hash(this.externalState);
|
|
904
918
|
let key = Builder.isEditing ? this.name : this.props.entry;
|
|
905
919
|
if (key && !Builder.isEditing && dataString && dataString.length < 300) {
|
|
906
920
|
key += ':' + dataString;
|
|
@@ -971,6 +985,7 @@ export class BuilderComponent extends React.Component<
|
|
|
971
985
|
!this.isPreviewing && { initialContent: [] }),
|
|
972
986
|
...(this.props.url && { url: this.props.url }),
|
|
973
987
|
...this.props.options,
|
|
988
|
+
...(this.props.locale ? { locale: this.props.locale } : {}),
|
|
974
989
|
...(this.options.codegen && {
|
|
975
990
|
format: 'react',
|
|
976
991
|
}),
|
|
@@ -1272,7 +1287,7 @@ export class BuilderComponent extends React.Component<
|
|
|
1272
1287
|
deviceSize: this.deviceSizeState,
|
|
1273
1288
|
device: this.device,
|
|
1274
1289
|
...data.state,
|
|
1275
|
-
...this.
|
|
1290
|
+
...this.externalState,
|
|
1276
1291
|
}),
|
|
1277
1292
|
};
|
|
1278
1293
|
if (this.mounted) {
|
|
@@ -1358,22 +1373,22 @@ export class BuilderComponent extends React.Component<
|
|
|
1358
1373
|
const builderModelRe = /builder\.io\/api\/v2\/([^\/\?]+)/i;
|
|
1359
1374
|
const builderModelMatch = url.match(builderModelRe);
|
|
1360
1375
|
const model = builderModelMatch && builderModelMatch[1];
|
|
1361
|
-
|
|
1362
|
-
|
|
1363
|
-
|
|
1364
|
-
|
|
1365
|
-
|
|
1366
|
-
|
|
1367
|
-
|
|
1368
|
-
|
|
1369
|
-
|
|
1370
|
-
|
|
1371
|
-
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1376
|
+
this.handleRequest(key, finalUrl);
|
|
1377
|
+
const currentSubscription = this.httpSubscriptionPerKey[key];
|
|
1378
|
+
if (currentSubscription) {
|
|
1379
|
+
currentSubscription.unsubscribe();
|
|
1380
|
+
}
|
|
1381
|
+
|
|
1382
|
+
// TODO: fix this
|
|
1383
|
+
const newSubscription = (this.httpSubscriptionPerKey[key] =
|
|
1384
|
+
this.onStateChange.subscribe(() => {
|
|
1385
|
+
const newUrl = this.evalExpression(url);
|
|
1386
|
+
if (newUrl !== finalUrl) {
|
|
1387
|
+
this.handleRequest(key, newUrl);
|
|
1388
|
+
this.lastHttpRequests[key] = newUrl;
|
|
1389
|
+
}
|
|
1390
|
+
}));
|
|
1391
|
+
this.subscriptions.add(newSubscription);
|
|
1377
1392
|
} else {
|
|
1378
1393
|
this.handleRequest(key, this.evalExpression(url));
|
|
1379
1394
|
}
|
|
@@ -149,7 +149,7 @@ export class BuilderContent<ContentType extends object = any> extends React.Comp
|
|
|
149
149
|
data: newData,
|
|
150
150
|
});
|
|
151
151
|
if (this.props.contentLoaded) {
|
|
152
|
-
this.props.contentLoaded(newData.data,
|
|
152
|
+
this.props.contentLoaded(newData.data, newData);
|
|
153
153
|
}
|
|
154
154
|
break;
|
|
155
155
|
}
|