@builder.io/sdk-react-native 3.0.1 → 3.0.2
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/lib/browser/commonjs/blocks/text/text.js +3 -17
- package/lib/browser/commonjs/blocks/text/text.js.map +1 -1
- package/lib/browser/commonjs/components/block/block.js +2 -3
- package/lib/browser/commonjs/components/block/block.js.map +1 -1
- package/lib/browser/commonjs/components/content/components/enable-editor.js +18 -6
- package/lib/browser/commonjs/components/content/components/enable-editor.js.map +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js +1 -1
- package/lib/browser/commonjs/functions/evaluate/edge-runtime/edge-runtime.js +1 -5
- package/lib/browser/commonjs/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
- package/lib/browser/commonjs/functions/get-block-component-options.js +19 -2
- package/lib/browser/commonjs/functions/get-block-component-options.js.map +1 -1
- package/lib/browser/commonjs/functions/get-content/generate-content-url.js +29 -2
- package/lib/browser/commonjs/functions/get-content/generate-content-url.js.map +1 -1
- package/lib/browser/commonjs/functions/get-processed-block.js +7 -12
- package/lib/browser/commonjs/functions/get-processed-block.js.map +1 -1
- package/lib/browser/commonjs/helpers/flatten.js +24 -0
- package/lib/browser/commonjs/helpers/flatten.js.map +1 -1
- package/lib/browser/module/blocks/text/text.js +3 -17
- package/lib/browser/module/blocks/text/text.js.map +1 -1
- package/lib/browser/module/components/block/block.js +2 -3
- package/lib/browser/module/components/block/block.js.map +1 -1
- package/lib/browser/module/components/content/components/enable-editor.js +18 -6
- package/lib/browser/module/components/content/components/enable-editor.js.map +1 -1
- package/lib/browser/module/constants/sdk-version.js +1 -1
- package/lib/browser/module/functions/evaluate/edge-runtime/edge-runtime.js +1 -5
- package/lib/browser/module/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
- package/lib/browser/module/functions/get-block-component-options.js +19 -2
- package/lib/browser/module/functions/get-block-component-options.js.map +1 -1
- package/lib/browser/module/functions/get-content/generate-content-url.js +30 -3
- package/lib/browser/module/functions/get-content/generate-content-url.js.map +1 -1
- package/lib/browser/module/functions/get-processed-block.js +7 -12
- package/lib/browser/module/functions/get-processed-block.js.map +1 -1
- package/lib/browser/module/helpers/flatten.js +23 -0
- package/lib/browser/module/helpers/flatten.js.map +1 -1
- package/lib/browser/typescript/blocks/text/text.d.ts.map +1 -1
- package/lib/browser/typescript/components/block/block.d.ts.map +1 -1
- package/lib/browser/typescript/components/content/components/enable-editor.d.ts.map +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/browser/typescript/functions/get-block-component-options.d.ts +2 -1
- package/lib/browser/typescript/functions/get-block-component-options.d.ts.map +1 -1
- package/lib/browser/typescript/functions/get-content/generate-content-url.d.ts.map +1 -1
- package/lib/browser/typescript/functions/get-processed-block.d.ts +1 -6
- package/lib/browser/typescript/functions/get-processed-block.d.ts.map +1 -1
- package/lib/browser/typescript/helpers/flatten.d.ts +6 -0
- package/lib/browser/typescript/helpers/flatten.d.ts.map +1 -1
- package/lib/browser/typescript/server-index.d.ts +1 -1
- package/lib/browser/typescript/server-index.d.ts.map +1 -1
- package/lib/edge/commonjs/blocks/text/text.js +3 -17
- package/lib/edge/commonjs/blocks/text/text.js.map +1 -1
- package/lib/edge/commonjs/components/block/block.js +2 -3
- package/lib/edge/commonjs/components/block/block.js.map +1 -1
- package/lib/edge/commonjs/components/content/components/enable-editor.js +18 -6
- package/lib/edge/commonjs/components/content/components/enable-editor.js.map +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js +1 -1
- package/lib/edge/commonjs/functions/evaluate/edge-runtime/edge-runtime.js +1 -5
- package/lib/edge/commonjs/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
- package/lib/edge/commonjs/functions/get-block-component-options.js +19 -2
- package/lib/edge/commonjs/functions/get-block-component-options.js.map +1 -1
- package/lib/edge/commonjs/functions/get-content/generate-content-url.js +29 -2
- package/lib/edge/commonjs/functions/get-content/generate-content-url.js.map +1 -1
- package/lib/edge/commonjs/functions/get-processed-block.js +7 -12
- package/lib/edge/commonjs/functions/get-processed-block.js.map +1 -1
- package/lib/edge/commonjs/helpers/flatten.js +24 -0
- package/lib/edge/commonjs/helpers/flatten.js.map +1 -1
- package/lib/edge/module/blocks/text/text.js +3 -17
- package/lib/edge/module/blocks/text/text.js.map +1 -1
- package/lib/edge/module/components/block/block.js +2 -3
- package/lib/edge/module/components/block/block.js.map +1 -1
- package/lib/edge/module/components/content/components/enable-editor.js +18 -6
- package/lib/edge/module/components/content/components/enable-editor.js.map +1 -1
- package/lib/edge/module/constants/sdk-version.js +1 -1
- package/lib/edge/module/functions/evaluate/edge-runtime/edge-runtime.js +1 -5
- package/lib/edge/module/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
- package/lib/edge/module/functions/get-block-component-options.js +19 -2
- package/lib/edge/module/functions/get-block-component-options.js.map +1 -1
- package/lib/edge/module/functions/get-content/generate-content-url.js +30 -3
- package/lib/edge/module/functions/get-content/generate-content-url.js.map +1 -1
- package/lib/edge/module/functions/get-processed-block.js +7 -12
- package/lib/edge/module/functions/get-processed-block.js.map +1 -1
- package/lib/edge/module/helpers/flatten.js +23 -0
- package/lib/edge/module/helpers/flatten.js.map +1 -1
- package/lib/edge/typescript/blocks/text/text.d.ts.map +1 -1
- package/lib/edge/typescript/components/block/block.d.ts.map +1 -1
- package/lib/edge/typescript/components/content/components/enable-editor.d.ts.map +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/edge/typescript/functions/get-block-component-options.d.ts +2 -1
- package/lib/edge/typescript/functions/get-block-component-options.d.ts.map +1 -1
- package/lib/edge/typescript/functions/get-content/generate-content-url.d.ts.map +1 -1
- package/lib/edge/typescript/functions/get-processed-block.d.ts +1 -6
- package/lib/edge/typescript/functions/get-processed-block.d.ts.map +1 -1
- package/lib/edge/typescript/helpers/flatten.d.ts +6 -0
- package/lib/edge/typescript/helpers/flatten.d.ts.map +1 -1
- package/lib/edge/typescript/server-index.d.ts +1 -1
- package/lib/edge/typescript/server-index.d.ts.map +1 -1
- package/lib/node/commonjs/blocks/text/text.js +3 -17
- package/lib/node/commonjs/blocks/text/text.js.map +1 -1
- package/lib/node/commonjs/components/block/block.js +2 -3
- package/lib/node/commonjs/components/block/block.js.map +1 -1
- package/lib/node/commonjs/components/content/components/enable-editor.js +18 -6
- package/lib/node/commonjs/components/content/components/enable-editor.js.map +1 -1
- package/lib/node/commonjs/constants/sdk-version.js +1 -1
- package/lib/node/commonjs/functions/evaluate/edge-runtime/edge-runtime.js +1 -5
- package/lib/node/commonjs/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
- package/lib/node/commonjs/functions/get-block-component-options.js +19 -2
- package/lib/node/commonjs/functions/get-block-component-options.js.map +1 -1
- package/lib/node/commonjs/functions/get-content/generate-content-url.js +29 -2
- package/lib/node/commonjs/functions/get-content/generate-content-url.js.map +1 -1
- package/lib/node/commonjs/functions/get-processed-block.js +7 -12
- package/lib/node/commonjs/functions/get-processed-block.js.map +1 -1
- package/lib/node/commonjs/helpers/flatten.js +24 -0
- package/lib/node/commonjs/helpers/flatten.js.map +1 -1
- package/lib/node/module/blocks/text/text.js +3 -17
- package/lib/node/module/blocks/text/text.js.map +1 -1
- package/lib/node/module/components/block/block.js +2 -3
- package/lib/node/module/components/block/block.js.map +1 -1
- package/lib/node/module/components/content/components/enable-editor.js +18 -6
- package/lib/node/module/components/content/components/enable-editor.js.map +1 -1
- package/lib/node/module/constants/sdk-version.js +1 -1
- package/lib/node/module/functions/evaluate/edge-runtime/edge-runtime.js +1 -5
- package/lib/node/module/functions/evaluate/edge-runtime/edge-runtime.js.map +1 -1
- package/lib/node/module/functions/get-block-component-options.js +19 -2
- package/lib/node/module/functions/get-block-component-options.js.map +1 -1
- package/lib/node/module/functions/get-content/generate-content-url.js +30 -3
- package/lib/node/module/functions/get-content/generate-content-url.js.map +1 -1
- package/lib/node/module/functions/get-processed-block.js +7 -12
- package/lib/node/module/functions/get-processed-block.js.map +1 -1
- package/lib/node/module/helpers/flatten.js +23 -0
- package/lib/node/module/helpers/flatten.js.map +1 -1
- package/lib/node/typescript/blocks/text/text.d.ts.map +1 -1
- package/lib/node/typescript/components/block/block.d.ts.map +1 -1
- package/lib/node/typescript/components/content/components/enable-editor.d.ts.map +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/node/typescript/functions/get-block-component-options.d.ts +2 -1
- package/lib/node/typescript/functions/get-block-component-options.d.ts.map +1 -1
- package/lib/node/typescript/functions/get-content/generate-content-url.d.ts.map +1 -1
- package/lib/node/typescript/functions/get-processed-block.d.ts +1 -6
- package/lib/node/typescript/functions/get-processed-block.d.ts.map +1 -1
- package/lib/node/typescript/helpers/flatten.d.ts +6 -0
- package/lib/node/typescript/helpers/flatten.d.ts.map +1 -1
- package/lib/node/typescript/server-index.d.ts +1 -1
- package/lib/node/typescript/server-index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/blocks/text/text.tsx +3 -25
- package/src/components/block/block.tsx +1 -2
- package/src/components/content/components/enable-editor.tsx +26 -8
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/evaluate/edge-runtime/edge-runtime.ts +1 -5
- package/src/functions/get-block-component-options.ts +19 -2
- package/src/functions/get-content/generate-content-url.ts +30 -3
- package/src/functions/get-processed-block.ts +7 -17
- package/src/helpers/flatten.ts +23 -0
- package/src/server-index.ts +1 -1
|
@@ -15,7 +15,7 @@ export type { ContentVariantsPrps as ContentProps } from './components/content-v
|
|
|
15
15
|
/**
|
|
16
16
|
* General Builder types
|
|
17
17
|
*/
|
|
18
|
-
export type { RegisteredComponent } from './context/types';
|
|
18
|
+
export type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from './context/types';
|
|
19
19
|
export type { BuilderBlock } from './types/builder-block';
|
|
20
20
|
export type { BuilderContent } from './types/builder-content';
|
|
21
21
|
export type { ComponentInfo } from './types/components';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server-index.d.ts","sourceRoot":"","sources":["../../../src/server-index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAE5C;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,YAAY,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACpE,YAAY,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,sDAAsD,CAAC;AAEhH;;GAEG;AACH,YAAY,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"server-index.d.ts","sourceRoot":"","sources":["../../../src/server-index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAE5C;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,YAAY,EAAE,aAAa,EAAE,MAAM,kCAAkC,CAAC;AACtE,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,YAAY,EAAE,MAAM,gCAAgC,CAAC;AACnE,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAC1D,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAC7D,YAAY,EAAE,WAAW,EAAE,MAAM,kCAAkC,CAAC;AACpE,YAAY,EAAE,mBAAmB,IAAI,YAAY,EAAE,MAAM,sDAAsD,CAAC;AAEhH;;GAEG;AACH,YAAY,EAAE,uBAAuB,EAAE,mBAAmB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC1G,YAAY,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAC9D,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAExD;;GAEG;AACH,OAAO,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACnD,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,8BAA8B,EAAE,MAAM,gCAAgC,CAAC;AAChF,OAAO,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAChD,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,YAAY,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnG,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react-native",
|
|
3
3
|
"description": "Builder.io SDK for React Native",
|
|
4
|
-
"version": "3.0.
|
|
4
|
+
"version": "3.0.2",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/react-native",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
package/src/blocks/text/text.tsx
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
|
+
import { RenderHTML } from '@builder.io/react-native-render-html';
|
|
1
2
|
import * as React from 'react';
|
|
2
3
|
import { useWindowDimensions } from 'react-native';
|
|
3
|
-
import { RenderHTML } from '@builder.io/react-native-render-html';
|
|
4
4
|
import BuilderContext from '../../context/builder.context';
|
|
5
|
-
import { evaluate } from '../../functions/evaluate/index';
|
|
6
5
|
|
|
7
6
|
/**
|
|
8
7
|
* @typedef {{}} BuilderBlock
|
|
@@ -90,38 +89,17 @@ function getCss(block, inheritedStyles) {
|
|
|
90
89
|
/**
|
|
91
90
|
*
|
|
92
91
|
* @param {{ text: string; builderBlock: BuilderBlock, builderContext: BuilderContext}} props
|
|
93
|
-
* @returns
|
|
92
|
+
* @returns
|
|
94
93
|
*/
|
|
95
94
|
export default function Text(props) {
|
|
96
95
|
const { width } = useWindowDimensions();
|
|
97
96
|
const context = React.useContext(BuilderContext);
|
|
98
|
-
const {
|
|
99
|
-
context: contextContext,
|
|
100
|
-
localState,
|
|
101
|
-
rootState,
|
|
102
|
-
rootSetState,
|
|
103
|
-
} = context;
|
|
104
|
-
|
|
105
|
-
const processedText = String(props.text?.toString() || '').replace(
|
|
106
|
-
/{{([^}]+)}}/g,
|
|
107
|
-
(match, group) => evaluate({
|
|
108
|
-
code: group,
|
|
109
|
-
context: contextContext,
|
|
110
|
-
localState,
|
|
111
|
-
rootState,
|
|
112
|
-
rootSetState,
|
|
113
|
-
|
|
114
|
-
}).toString()
|
|
115
|
-
);
|
|
116
97
|
|
|
117
98
|
return (
|
|
118
99
|
<RenderHTML
|
|
119
100
|
contentWidth={width}
|
|
120
101
|
source={{
|
|
121
|
-
html: `<div style="${getCss(
|
|
122
|
-
props.builderBlock,
|
|
123
|
-
context.inheritedStyles
|
|
124
|
-
)}">${processedText}</div>`,
|
|
102
|
+
html: `<div style="${getCss(props.builderBlock, context.inheritedStyles)}">${props.text?.toString() || ''}</div>`,
|
|
125
103
|
}}
|
|
126
104
|
/>
|
|
127
105
|
);
|
|
@@ -72,7 +72,6 @@ function Block(props: BlockProps) {
|
|
|
72
72
|
rootState: props.context.rootState,
|
|
73
73
|
rootSetState: props.context.rootSetState,
|
|
74
74
|
context: props.context.context,
|
|
75
|
-
shouldEvaluateBindings: true,
|
|
76
75
|
});
|
|
77
76
|
_processedBlock.value = blockToUse;
|
|
78
77
|
_processedBlock.update = false;
|
|
@@ -129,7 +128,7 @@ function Block(props: BlockProps) {
|
|
|
129
128
|
blockChildren: processedBlock().children ?? [],
|
|
130
129
|
componentRef: blockComponent?.()?.component,
|
|
131
130
|
componentOptions: {
|
|
132
|
-
...getBlockComponentOptions(processedBlock()),
|
|
131
|
+
...getBlockComponentOptions(processedBlock(), props.context),
|
|
133
132
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
134
133
|
...provideBuilderContext(blockComponent(), props.context),
|
|
135
134
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
@@ -282,14 +282,23 @@ function EnableEditor(props: BuilderEditorProps) {
|
|
|
282
282
|
* TO-DO: should we only update the state when there is a change?
|
|
283
283
|
**/
|
|
284
284
|
if (
|
|
285
|
-
searchParamPreviewModel ===
|
|
286
|
-
|
|
287
|
-
|
|
285
|
+
searchParamPreviewModel === "BUILDER_STUDIO" ||
|
|
286
|
+
(searchParamPreviewModel === props.model &&
|
|
287
|
+
previewApiKey === props.apiKey &&
|
|
288
|
+
(!props.content || searchParamPreviewId === props.content.id))
|
|
288
289
|
) {
|
|
289
290
|
fetchOneEntry({
|
|
290
|
-
model: props.model,
|
|
291
|
+
model: props.model || "",
|
|
291
292
|
apiKey: props.apiKey,
|
|
292
293
|
apiVersion: props.builderContextSignal.apiVersion,
|
|
294
|
+
...(searchParamPreviewModel === "BUILDER_STUDIO" &&
|
|
295
|
+
props.context?.symbolId
|
|
296
|
+
? {
|
|
297
|
+
query: {
|
|
298
|
+
id: props.context.symbolId,
|
|
299
|
+
},
|
|
300
|
+
}
|
|
301
|
+
: {}),
|
|
293
302
|
}).then((content) => {
|
|
294
303
|
if (content) {
|
|
295
304
|
mergeNewContent(content);
|
|
@@ -382,14 +391,23 @@ function EnableEditor(props: BuilderEditorProps) {
|
|
|
382
391
|
* TO-DO: should we only update the state when there is a change?
|
|
383
392
|
**/
|
|
384
393
|
if (
|
|
385
|
-
searchParamPreviewModel ===
|
|
386
|
-
|
|
387
|
-
|
|
394
|
+
searchParamPreviewModel === "BUILDER_STUDIO" ||
|
|
395
|
+
(searchParamPreviewModel === props.model &&
|
|
396
|
+
previewApiKey === props.apiKey &&
|
|
397
|
+
(!props.content || searchParamPreviewId === props.content.id))
|
|
388
398
|
) {
|
|
389
399
|
fetchOneEntry({
|
|
390
|
-
model: props.model,
|
|
400
|
+
model: props.model || "",
|
|
391
401
|
apiKey: props.apiKey,
|
|
392
402
|
apiVersion: props.builderContextSignal.apiVersion,
|
|
403
|
+
...(searchParamPreviewModel === "BUILDER_STUDIO" &&
|
|
404
|
+
props.context?.symbolId
|
|
405
|
+
? {
|
|
406
|
+
query: {
|
|
407
|
+
id: props.context.symbolId,
|
|
408
|
+
},
|
|
409
|
+
}
|
|
410
|
+
: {}),
|
|
393
411
|
}).then((content) => {
|
|
394
412
|
if (content) {
|
|
395
413
|
mergeNewContent(content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "3.0.
|
|
1
|
+
export const SDK_VERSION = "3.0.2"
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../../../helpers/logger';
|
|
2
1
|
import type { ExecutorArgs } from '../helpers';
|
|
3
2
|
import { flattenState, getFunctionArguments } from '../helpers';
|
|
4
3
|
import Interpreter from './acorn-interpreter';
|
|
@@ -95,10 +94,7 @@ export const runInEdge = ({
|
|
|
95
94
|
return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
|
|
96
95
|
}).join('\n');
|
|
97
96
|
const cleanedCode = processCode(code);
|
|
98
|
-
if (cleanedCode === '')
|
|
99
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
97
|
+
if (cleanedCode === '') return;
|
|
102
98
|
const transformed = `
|
|
103
99
|
function theFunction() {
|
|
104
100
|
${prependedCode}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../context/types';
|
|
1
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
|
-
|
|
3
|
+
import { evaluate } from './evaluate/evaluate';
|
|
4
|
+
export function getBlockComponentOptions(block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>) {
|
|
3
5
|
return {
|
|
4
6
|
...block.component?.options,
|
|
5
|
-
...(block as any).options
|
|
7
|
+
...(block as any).options,
|
|
8
|
+
...evaluateTextComponentTextOption(block, context)
|
|
6
9
|
};
|
|
10
|
+
}
|
|
11
|
+
const evaluateTextComponentTextOption = (block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>) => {
|
|
12
|
+
if (block.component?.name === 'Text' && block.component.options?.text && typeof block.component.options.text === 'string') {
|
|
13
|
+
return {
|
|
14
|
+
...block.component.options,
|
|
15
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match: string, group: string) => (evaluate({
|
|
16
|
+
code: group,
|
|
17
|
+
context,
|
|
18
|
+
localState: context.localState,
|
|
19
|
+
rootState: context.rootState,
|
|
20
|
+
rootSetState: context.rootSetState
|
|
21
|
+
}) as string))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
7
24
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { flatten, flattenMongoQuery } from '../../helpers/flatten';
|
|
1
|
+
import { flatten, flattenMongoQuery, unflatten } from '../../helpers/flatten';
|
|
2
2
|
import { normalizeSearchParams } from '../../helpers/search/search';
|
|
3
3
|
import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
|
+
import { isBrowser } from '../is-browser';
|
|
5
6
|
import type { GetContentOptions } from './types';
|
|
6
7
|
const isPositiveNumber = (thing: unknown) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
7
8
|
export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
@@ -39,7 +40,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
39
40
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
40
41
|
url.searchParams.set('includeRefs', String(true));
|
|
41
42
|
const finalLocale = locale || userAttributes?.locale;
|
|
42
|
-
let finalUserAttributes = userAttributes;
|
|
43
|
+
let finalUserAttributes: Record<string, any> = userAttributes || {};
|
|
43
44
|
if (finalLocale) {
|
|
44
45
|
url.searchParams.set('locale', finalLocale);
|
|
45
46
|
finalUserAttributes = {
|
|
@@ -79,11 +80,15 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
79
80
|
...getBuilderSearchParamsFromWindow(),
|
|
80
81
|
...normalizeSearchParams(options.options || {})
|
|
81
82
|
};
|
|
83
|
+
finalUserAttributes = {
|
|
84
|
+
...finalUserAttributes,
|
|
85
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
86
|
+
};
|
|
82
87
|
const flattened = flatten(queryOptions);
|
|
83
88
|
for (const key in flattened) {
|
|
84
89
|
url.searchParams.set(key, String(flattened[key]));
|
|
85
90
|
}
|
|
86
|
-
if (finalUserAttributes) {
|
|
91
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
87
92
|
url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
|
|
88
93
|
}
|
|
89
94
|
if (query) {
|
|
@@ -95,4 +100,26 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
return url;
|
|
103
|
+
};
|
|
104
|
+
const getUserAttributesFromQueryOptions = (queryOptions: any) => {
|
|
105
|
+
const newUserAttributes: any = {};
|
|
106
|
+
for (const key in queryOptions) {
|
|
107
|
+
if (key.startsWith('userAttributes.')) {
|
|
108
|
+
newUserAttributes[key] = queryOptions[key];
|
|
109
|
+
delete queryOptions[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return newUserAttributes;
|
|
113
|
+
};
|
|
114
|
+
const getUserAttributesAsJSON = (queryOptions: any) => {
|
|
115
|
+
if (isBrowser() && queryOptions['preview'] === 'BUILDER_STUDIO') {
|
|
116
|
+
queryOptions['userAttributes.urlPath'] = window.location.pathname;
|
|
117
|
+
queryOptions['userAttributes.host'] = window.location.host;
|
|
118
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
119
|
+
const {
|
|
120
|
+
userAttributes
|
|
121
|
+
} = unflatten(queryOptionsForUserAttributes);
|
|
122
|
+
return userAttributes;
|
|
123
|
+
}
|
|
124
|
+
return {};
|
|
98
125
|
}
|
|
@@ -85,29 +85,19 @@ const evaluateBindings = ({
|
|
|
85
85
|
export function getProcessedBlock({
|
|
86
86
|
block,
|
|
87
87
|
context,
|
|
88
|
-
shouldEvaluateBindings,
|
|
89
88
|
localState,
|
|
90
89
|
rootState,
|
|
91
90
|
rootSetState
|
|
92
91
|
}: {
|
|
93
92
|
block: BuilderBlock;
|
|
94
|
-
/**
|
|
95
|
-
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
96
|
-
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
97
|
-
*/
|
|
98
|
-
shouldEvaluateBindings: boolean;
|
|
99
93
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock {
|
|
100
94
|
let transformedBlock = resolveLocalizedValues(block, (rootState.locale as string | undefined));
|
|
101
95
|
transformedBlock = transformBlock(transformedBlock);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
return transformedBlock;
|
|
112
|
-
}
|
|
96
|
+
return evaluateBindings({
|
|
97
|
+
block: transformedBlock,
|
|
98
|
+
localState,
|
|
99
|
+
rootState,
|
|
100
|
+
rootSetState,
|
|
101
|
+
context
|
|
102
|
+
});
|
|
113
103
|
}
|
package/src/helpers/flatten.ts
CHANGED
|
@@ -38,4 +38,27 @@ export function flattenMongoQuery(obj: any, _current?: any, _res: any = {}): {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return _res;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Unflatten a flat object with dot-separated keys back into a nested object.
|
|
45
|
+
*
|
|
46
|
+
* { 'foo.bar': 'baz' } -> { foo: { bar: 'baz' }}
|
|
47
|
+
*/
|
|
48
|
+
export function unflatten(obj: any): any {
|
|
49
|
+
const result: any = {};
|
|
50
|
+
for (const key in obj) {
|
|
51
|
+
const parts = key.split('.');
|
|
52
|
+
let current = result;
|
|
53
|
+
for (let i = 0; i < parts.length; i++) {
|
|
54
|
+
const part = parts[i];
|
|
55
|
+
if (i === parts.length - 1) {
|
|
56
|
+
current[part] = obj[key];
|
|
57
|
+
} else {
|
|
58
|
+
current[part] = current[part] || {};
|
|
59
|
+
current = current[part];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
41
64
|
}
|
package/src/server-index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type { ContentVariantsPrps as ContentProps } from './components/content-v
|
|
|
17
17
|
/**
|
|
18
18
|
* General Builder types
|
|
19
19
|
*/
|
|
20
|
-
export type { RegisteredComponent } from './context/types';
|
|
20
|
+
export type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from './context/types';
|
|
21
21
|
export type { BuilderBlock } from './types/builder-block';
|
|
22
22
|
export type { BuilderContent } from './types/builder-content';
|
|
23
23
|
export type { ComponentInfo } from './types/components';
|