@builder.io/sdk-react 0.2.3-4 → 0.2.3
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/sdk/blocks/columns/columns.js +4 -4
- package/dist/sdk/blocks/image/image.js +8 -7
- package/dist/sdk/blocks/symbol/symbol.js +2 -1
- package/dist/sdk/blocks/video/video.js +4 -1
- package/dist/sdk/components/render-block/render-block.js +4 -1
- package/dist/sdk/components/render-content/render-content.js +19 -5
- package/dist/sdk/index.d.ts +1 -0
- package/package.json +4 -1
- package/CHANGELOG.md +0 -25
- package/packages/react/src/blocks/BaseText.tsx +0 -19
- package/packages/react/src/blocks/button/button.tsx +0 -45
- package/packages/react/src/blocks/button/component-info.ts +0 -42
- package/packages/react/src/blocks/columns/columns.tsx +0 -211
- package/packages/react/src/blocks/columns/component-info.ts +0 -254
- package/packages/react/src/blocks/custom-code/component-info.ts +0 -31
- package/packages/react/src/blocks/custom-code/custom-code.tsx +0 -76
- package/packages/react/src/blocks/embed/component-info.ts +0 -55
- package/packages/react/src/blocks/embed/embed.tsx +0 -59
- package/packages/react/src/blocks/embed/helpers.ts +0 -8
- package/packages/react/src/blocks/form/component-info.ts +0 -282
- package/packages/react/src/blocks/form/form.tsx +0 -320
- package/packages/react/src/blocks/fragment/component-info.ts +0 -10
- package/packages/react/src/blocks/fragment/fragment.tsx +0 -14
- package/packages/react/src/blocks/image/component-info.ts +0 -172
- package/packages/react/src/blocks/image/image.helpers.ts +0 -75
- package/packages/react/src/blocks/image/image.tsx +0 -144
- package/packages/react/src/blocks/img/component-info.ts +0 -21
- package/packages/react/src/blocks/img/img.tsx +0 -40
- package/packages/react/src/blocks/input/component-info.ts +0 -78
- package/packages/react/src/blocks/input/input.tsx +0 -33
- package/packages/react/src/blocks/raw-text/component-info.ts +0 -15
- package/packages/react/src/blocks/raw-text/raw-text.tsx +0 -18
- package/packages/react/src/blocks/section/component-info.ts +0 -50
- package/packages/react/src/blocks/section/section.tsx +0 -33
- package/packages/react/src/blocks/select/component-info.ts +0 -61
- package/packages/react/src/blocks/select/select.tsx +0 -35
- package/packages/react/src/blocks/submit-button/component-info.ts +0 -32
- package/packages/react/src/blocks/submit-button/submit-button.tsx +0 -17
- package/packages/react/src/blocks/symbol/component-info.ts +0 -43
- package/packages/react/src/blocks/symbol/symbol.tsx +0 -111
- package/packages/react/src/blocks/text/component-info.ts +0 -24
- package/packages/react/src/blocks/text/text.tsx +0 -20
- package/packages/react/src/blocks/textarea/component-info.ts +0 -48
- package/packages/react/src/blocks/textarea/textarea.tsx +0 -24
- package/packages/react/src/blocks/util.ts +0 -18
- package/packages/react/src/blocks/video/component-info.ts +0 -109
- package/packages/react/src/blocks/video/video.tsx +0 -84
- package/packages/react/src/components/render-block/block-styles.tsx +0 -98
- package/packages/react/src/components/render-block/render-block.helpers.ts +0 -138
- package/packages/react/src/components/render-block/render-block.tsx +0 -216
- package/packages/react/src/components/render-block/render-component.tsx +0 -52
- package/packages/react/src/components/render-block/render-repeated-block.tsx +0 -43
- package/packages/react/src/components/render-block/types.ts +0 -7
- package/packages/react/src/components/render-blocks.tsx +0 -97
- package/packages/react/src/components/render-content/builder-editing.tsx +0 -8
- package/packages/react/src/components/render-content/components/render-styles.helpers.ts +0 -79
- package/packages/react/src/components/render-content/components/render-styles.tsx +0 -45
- package/packages/react/src/components/render-content/index.ts +0 -1
- package/packages/react/src/components/render-content/render-content.helpers.ts +0 -48
- package/packages/react/src/components/render-content/render-content.tsx +0 -410
- package/packages/react/src/components/render-content/render-content.types.ts +0 -33
- package/packages/react/src/components/render-inlined-styles.tsx +0 -36
- package/packages/react/src/constants/builder-registered-components.ts +0 -42
- package/packages/react/src/constants/device-sizes.ts +0 -65
- package/packages/react/src/constants/target.ts +0 -2
- package/packages/react/src/context/builder.context.ts +0 -12
- package/packages/react/src/context/types.ts +0 -26
- package/packages/react/src/functions/camel-to-kebab-case.ts +0 -2
- package/packages/react/src/functions/evaluate.ts +0 -57
- package/packages/react/src/functions/event-handler-name.ts +0 -6
- package/packages/react/src/functions/extract-text-styles.ts +0 -39
- package/packages/react/src/functions/fast-clone.ts +0 -5
- package/packages/react/src/functions/get-block-actions-handler.ts +0 -20
- package/packages/react/src/functions/get-block-actions.ts +0 -25
- package/packages/react/src/functions/get-block-component-options.ts +0 -12
- package/packages/react/src/functions/get-block-properties.ts +0 -75
- package/packages/react/src/functions/get-builder-search-params/fn.test.ts +0 -19
- package/packages/react/src/functions/get-builder-search-params/index.ts +0 -50
- package/packages/react/src/functions/get-content/ab-testing.ts +0 -132
- package/packages/react/src/functions/get-content/generate-content-url.test.ts +0 -95
- package/packages/react/src/functions/get-content/generate-content-url.ts +0 -59
- package/packages/react/src/functions/get-content/index.ts +0 -62
- package/packages/react/src/functions/get-content/types.ts +0 -53
- package/packages/react/src/functions/get-fetch.ts +0 -18
- package/packages/react/src/functions/get-global-this.ts +0 -17
- package/packages/react/src/functions/get-processed-block.test.ts +0 -33
- package/packages/react/src/functions/get-processed-block.ts +0 -54
- package/packages/react/src/functions/get-react-native-block-styles.ts +0 -33
- package/packages/react/src/functions/if-target.ts +0 -20
- package/packages/react/src/functions/is-browser.ts +0 -3
- package/packages/react/src/functions/is-editing.ts +0 -10
- package/packages/react/src/functions/is-iframe.ts +0 -5
- package/packages/react/src/functions/is-previewing.ts +0 -14
- package/packages/react/src/functions/on-change.test.ts +0 -23
- package/packages/react/src/functions/on-change.ts +0 -29
- package/packages/react/src/functions/register-component.ts +0 -50
- package/packages/react/src/functions/register.ts +0 -46
- package/packages/react/src/functions/sanitize-react-native-block-styles.ts +0 -65
- package/packages/react/src/functions/set-editor-settings.ts +0 -16
- package/packages/react/src/functions/set.test.ts +0 -19
- package/packages/react/src/functions/set.ts +0 -26
- package/packages/react/src/functions/track/helpers.ts +0 -67
- package/packages/react/src/functions/track/index.ts +0 -136
- package/packages/react/src/functions/track/interaction.ts +0 -80
- package/packages/react/src/functions/transform-block-properties.ts +0 -3
- package/packages/react/src/functions/transform-block.ts +0 -6
- package/packages/react/src/helpers/ab-tests.ts +0 -22
- package/packages/react/src/helpers/cookie.ts +0 -107
- package/packages/react/src/helpers/css.ts +0 -42
- package/packages/react/src/helpers/flatten.ts +0 -24
- package/packages/react/src/helpers/localStorage.ts +0 -40
- package/packages/react/src/helpers/logger.ts +0 -6
- package/packages/react/src/helpers/nullable.ts +0 -4
- package/packages/react/src/helpers/sessionId.ts +0 -38
- package/packages/react/src/helpers/time.ts +0 -4
- package/packages/react/src/helpers/url.test.ts +0 -23
- package/packages/react/src/helpers/url.ts +0 -16
- package/packages/react/src/helpers/uuid.ts +0 -17
- package/packages/react/src/helpers/visitorId.ts +0 -40
- package/packages/react/src/index-helpers/blocks-exports.ts +0 -10
- package/packages/react/src/index-helpers/top-of-file.ts +0 -4
- package/packages/react/src/index.ts +0 -14
- package/packages/react/src/scripts/init-editing.ts +0 -123
- package/packages/react/src/types/api-version.ts +0 -2
- package/packages/react/src/types/builder-block.ts +0 -69
- package/packages/react/src/types/builder-content.ts +0 -46
- package/packages/react/src/types/can-track.ts +0 -3
- package/packages/react/src/types/components.ts +0 -117
- package/packages/react/src/types/deep-partial.ts +0 -7
- package/packages/react/src/types/element.ts +0 -60
- package/packages/react/src/types/input.ts +0 -125
- package/packages/react/src/types/targets.ts +0 -6
- package/packages/react/src/types/typescript.ts +0 -7
- package/packages/rsc/src/blocks/BaseText.jsx +0 -12
- package/packages/rsc/src/blocks/button/button.jsx +0 -37
- package/packages/rsc/src/blocks/button/component-info.js +0 -40
- package/packages/rsc/src/blocks/columns/columns.jsx +0 -172
- package/packages/rsc/src/blocks/columns/component-info.js +0 -241
- package/packages/rsc/src/blocks/custom-code/component-info.js +0 -30
- package/packages/rsc/src/blocks/custom-code/custom-code.jsx +0 -57
- package/packages/rsc/src/blocks/embed/component-info.js +0 -43
- package/packages/rsc/src/blocks/embed/embed.jsx +0 -45
- package/packages/rsc/src/blocks/embed/helpers.js +0 -9
- package/packages/rsc/src/blocks/form/component-info.js +0 -261
- package/packages/rsc/src/blocks/form/form.jsx +0 -260
- package/packages/rsc/src/blocks/fragment/component-info.js +0 -10
- package/packages/rsc/src/blocks/fragment/fragment.jsx +0 -9
- package/packages/rsc/src/blocks/image/component-info.js +0 -150
- package/packages/rsc/src/blocks/image/image.helpers.js +0 -48
- package/packages/rsc/src/blocks/image/image.jsx +0 -122
- package/packages/rsc/src/blocks/img/component-info.js +0 -19
- package/packages/rsc/src/blocks/img/img.jsx +0 -21
- package/packages/rsc/src/blocks/input/component-info.js +0 -73
- package/packages/rsc/src/blocks/input/input.jsx +0 -23
- package/packages/rsc/src/blocks/raw-text/component-info.js +0 -15
- package/packages/rsc/src/blocks/raw-text/raw-text.jsx +0 -14
- package/packages/rsc/src/blocks/section/component-info.js +0 -48
- package/packages/rsc/src/blocks/section/section.jsx +0 -27
- package/packages/rsc/src/blocks/select/component-info.js +0 -58
- package/packages/rsc/src/blocks/select/select.jsx +0 -24
- package/packages/rsc/src/blocks/submit-button/component-info.js +0 -27
- package/packages/rsc/src/blocks/submit-button/submit-button.jsx +0 -13
- package/packages/rsc/src/blocks/symbol/component-info.js +0 -42
- package/packages/rsc/src/blocks/symbol/symbol.jsx +0 -89
- package/packages/rsc/src/blocks/text/component-info.js +0 -23
- package/packages/rsc/src/blocks/text/text.jsx +0 -17
- package/packages/rsc/src/blocks/textarea/component-info.js +0 -46
- package/packages/rsc/src/blocks/textarea/textarea.jsx +0 -17
- package/packages/rsc/src/blocks/util.js +0 -8
- package/packages/rsc/src/blocks/video/component-info.js +0 -105
- package/packages/rsc/src/blocks/video/video.jsx +0 -63
- package/packages/rsc/src/components/render-block/block-styles.jsx +0 -88
- package/packages/rsc/src/components/render-block/render-block.helpers.js +0 -129
- package/packages/rsc/src/components/render-block/render-block.jsx +0 -201
- package/packages/rsc/src/components/render-block/render-component.jsx +0 -39
- package/packages/rsc/src/components/render-block/render-repeated-block.jsx +0 -27
- package/packages/rsc/src/components/render-block/types.js +0 -0
- package/packages/rsc/src/components/render-blocks.jsx +0 -92
- package/packages/rsc/src/components/render-content/builder-editing.jsx +0 -64
- package/packages/rsc/src/components/render-content/components/render-styles.helpers.js +0 -57
- package/packages/rsc/src/components/render-content/components/render-styles.jsx +0 -39
- package/packages/rsc/src/components/render-content/index.js +0 -4
- package/packages/rsc/src/components/render-content/render-content.helpers.js +0 -48
- package/packages/rsc/src/components/render-content/render-content.jsx +0 -253
- package/packages/rsc/src/components/render-content/render-content.types.js +0 -0
- package/packages/rsc/src/components/render-inlined-styles.jsx +0 -33
- package/packages/rsc/src/constants/builder-registered-components.js +0 -54
- package/packages/rsc/src/constants/device-sizes.js +0 -48
- package/packages/rsc/src/constants/target.js +0 -4
- package/packages/rsc/src/context/builder.context.js +0 -14
- package/packages/rsc/src/context/types.js +0 -0
- package/packages/rsc/src/functions/camel-to-kebab-case.js +0 -4
- package/packages/rsc/src/functions/evaluate.js +0 -6
- package/packages/rsc/src/functions/event-handler-name.js +0 -7
- package/packages/rsc/src/functions/extract-text-styles.js +0 -22
- package/packages/rsc/src/functions/fast-clone.js +0 -4
- package/packages/rsc/src/functions/get-block-actions-handler.js +0 -11
- package/packages/rsc/src/functions/get-block-actions.js +0 -18
- package/packages/rsc/src/functions/get-block-component-options.js +0 -28
- package/packages/rsc/src/functions/get-block-properties.js +0 -53
- package/packages/rsc/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/packages/rsc/src/functions/get-builder-search-params/index.js +0 -38
- package/packages/rsc/src/functions/get-content/ab-testing.js +0 -99
- package/packages/rsc/src/functions/get-content/generate-content-url.js +0 -60
- package/packages/rsc/src/functions/get-content/generate-content-url.test.js +0 -82
- package/packages/rsc/src/functions/get-content/index.js +0 -83
- package/packages/rsc/src/functions/get-content/types.js +0 -0
- package/packages/rsc/src/functions/get-fetch.js +0 -14
- package/packages/rsc/src/functions/get-global-this.js +0 -18
- package/packages/rsc/src/functions/get-processed-block.js +0 -59
- package/packages/rsc/src/functions/get-processed-block.test.js +0 -32
- package/packages/rsc/src/functions/get-react-native-block-styles.js +0 -33
- package/packages/rsc/src/functions/if-target.js +0 -15
- package/packages/rsc/src/functions/is-browser.js +0 -6
- package/packages/rsc/src/functions/is-editing.js +0 -8
- package/packages/rsc/src/functions/is-iframe.js +0 -7
- package/packages/rsc/src/functions/is-previewing.js +0 -14
- package/packages/rsc/src/functions/on-change.js +0 -27
- package/packages/rsc/src/functions/on-change.test.js +0 -19
- package/packages/rsc/src/functions/register-component.js +0 -68
- package/packages/rsc/src/functions/register.js +0 -29
- package/packages/rsc/src/functions/sanitize-react-native-block-styles.js +0 -66
- package/packages/rsc/src/functions/set-editor-settings.js +0 -15
- package/packages/rsc/src/functions/set.js +0 -11
- package/packages/rsc/src/functions/set.test.js +0 -16
- package/packages/rsc/src/functions/track/helpers.js +0 -50
- package/packages/rsc/src/functions/track/index.js +0 -129
- package/packages/rsc/src/functions/track/interaction.js +0 -53
- package/packages/rsc/src/functions/transform-block-properties.js +0 -6
- package/packages/rsc/src/functions/transform-block.js +0 -6
- package/packages/rsc/src/helpers/ab-tests.js +0 -16
- package/packages/rsc/src/helpers/cookie.js +0 -81
- package/packages/rsc/src/helpers/css.js +0 -34
- package/packages/rsc/src/helpers/flatten.js +0 -34
- package/packages/rsc/src/helpers/localStorage.js +0 -35
- package/packages/rsc/src/helpers/logger.js +0 -9
- package/packages/rsc/src/helpers/nullable.js +0 -4
- package/packages/rsc/src/helpers/sessionId.js +0 -52
- package/packages/rsc/src/helpers/time.js +0 -5
- package/packages/rsc/src/helpers/url.js +0 -13
- package/packages/rsc/src/helpers/url.test.js +0 -21
- package/packages/rsc/src/helpers/uuid.js +0 -13
- package/packages/rsc/src/helpers/visitorId.js +0 -34
- package/packages/rsc/src/index-helpers/blocks-exports.js +0 -22
- package/packages/rsc/src/index-helpers/top-of-file.js +0 -2
- package/packages/rsc/src/index.js +0 -13
- package/packages/rsc/src/scripts/init-editing.js +0 -93
- package/packages/rsc/src/types/api-version.js +0 -4
- package/packages/rsc/src/types/builder-block.js +0 -0
- package/packages/rsc/src/types/builder-content.js +0 -0
- package/packages/rsc/src/types/can-track.js +0 -0
- package/packages/rsc/src/types/components.js +0 -0
- package/packages/rsc/src/types/deep-partial.js +0 -0
- package/packages/rsc/src/types/element.js +0 -0
- package/packages/rsc/src/types/input.js +0 -0
- package/packages/rsc/src/types/targets.js +0 -0
- package/packages/rsc/src/types/typescript.js +0 -0
- package/tsconfig.json +0 -28
- package/tsconfig.sdk.json +0 -10
- package/tsconfig.server.json +0 -10
- package/vite.config.ts +0 -91
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
export type BlockStylesProps = {
|
|
5
|
-
block: BuilderBlock;
|
|
6
|
-
context: BuilderContextInterface;
|
|
7
|
-
};
|
|
8
|
-
import {
|
|
9
|
-
getMaxWidthQueryForSize,
|
|
10
|
-
getSizesForBreakpoints,
|
|
11
|
-
} from "../../constants/device-sizes.js";
|
|
12
|
-
import { TARGET } from "../../constants/target.js";
|
|
13
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
14
|
-
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
15
|
-
import { createCssClass } from "../../helpers/css.js";
|
|
16
|
-
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
17
|
-
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
-
import RenderInlinedStyles from "../render-inlined-styles";
|
|
19
|
-
|
|
20
|
-
function BlockStyles(props: BlockStylesProps) {
|
|
21
|
-
function useBlock() {
|
|
22
|
-
return getProcessedBlock({
|
|
23
|
-
block: props.block,
|
|
24
|
-
state: props.context.state,
|
|
25
|
-
context: props.context.context,
|
|
26
|
-
shouldEvaluateBindings: true,
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function canShowBlock() {
|
|
31
|
-
// only render styles for blocks that are visible
|
|
32
|
-
if (checkIsDefined(useBlock().hide)) {
|
|
33
|
-
return !useBlock().hide;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
if (checkIsDefined(useBlock().show)) {
|
|
37
|
-
return useBlock().show;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function css() {
|
|
44
|
-
const styles = useBlock().responsiveStyles;
|
|
45
|
-
const content = props.context.content;
|
|
46
|
-
const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(
|
|
47
|
-
content?.meta?.breakpoints || {}
|
|
48
|
-
);
|
|
49
|
-
const largeStyles = styles?.large;
|
|
50
|
-
const mediumStyles = styles?.medium;
|
|
51
|
-
const smallStyles = styles?.small;
|
|
52
|
-
const className = useBlock().id;
|
|
53
|
-
|
|
54
|
-
if (!className) {
|
|
55
|
-
return "";
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const largeStylesClass = largeStyles
|
|
59
|
-
? createCssClass({
|
|
60
|
-
className,
|
|
61
|
-
styles: largeStyles,
|
|
62
|
-
})
|
|
63
|
-
: "";
|
|
64
|
-
const mediumStylesClass = mediumStyles
|
|
65
|
-
? createCssClass({
|
|
66
|
-
className,
|
|
67
|
-
styles: mediumStyles,
|
|
68
|
-
mediaQuery: getMaxWidthQueryForSize(
|
|
69
|
-
"medium",
|
|
70
|
-
sizesWithUpdatedBreakpoints
|
|
71
|
-
),
|
|
72
|
-
})
|
|
73
|
-
: "";
|
|
74
|
-
const smallStylesClass = smallStyles
|
|
75
|
-
? createCssClass({
|
|
76
|
-
className,
|
|
77
|
-
styles: smallStyles,
|
|
78
|
-
mediaQuery: getMaxWidthQueryForSize(
|
|
79
|
-
"small",
|
|
80
|
-
sizesWithUpdatedBreakpoints
|
|
81
|
-
),
|
|
82
|
-
})
|
|
83
|
-
: "";
|
|
84
|
-
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return (
|
|
88
|
-
<>
|
|
89
|
-
{TARGET !== "reactNative" && css() && canShowBlock() ? (
|
|
90
|
-
<>
|
|
91
|
-
<RenderInlinedStyles styles={css()} />
|
|
92
|
-
</>
|
|
93
|
-
) : null}
|
|
94
|
-
</>
|
|
95
|
-
);
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
export default BlockStyles;
|
|
@@ -1,138 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BuilderContextInterface,
|
|
3
|
-
BuilderRenderState,
|
|
4
|
-
} from '../../context/types';
|
|
5
|
-
import { evaluate } from '../../functions/evaluate';
|
|
6
|
-
import { getProcessedBlock } from '../../functions/get-processed-block';
|
|
7
|
-
import type { BuilderBlock } from '../../types/builder-block';
|
|
8
|
-
import type { RepeatData } from './types';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
|
|
12
|
-
*/
|
|
13
|
-
const EMPTY_HTML_ELEMENTS = [
|
|
14
|
-
'area',
|
|
15
|
-
'base',
|
|
16
|
-
'br',
|
|
17
|
-
'col',
|
|
18
|
-
'embed',
|
|
19
|
-
'hr',
|
|
20
|
-
'img',
|
|
21
|
-
'input',
|
|
22
|
-
'keygen',
|
|
23
|
-
'link',
|
|
24
|
-
'meta',
|
|
25
|
-
'param',
|
|
26
|
-
'source',
|
|
27
|
-
'track',
|
|
28
|
-
'wbr',
|
|
29
|
-
];
|
|
30
|
-
|
|
31
|
-
export const isEmptyHtmlElement = (tagName: unknown) => {
|
|
32
|
-
return (
|
|
33
|
-
typeof tagName === 'string' &&
|
|
34
|
-
EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase())
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export const getComponent = ({
|
|
39
|
-
block,
|
|
40
|
-
context,
|
|
41
|
-
}: {
|
|
42
|
-
block: BuilderBlock;
|
|
43
|
-
context: BuilderContextInterface;
|
|
44
|
-
}) => {
|
|
45
|
-
const componentName = getProcessedBlock({
|
|
46
|
-
block,
|
|
47
|
-
state: context.state,
|
|
48
|
-
context: context.context,
|
|
49
|
-
shouldEvaluateBindings: false,
|
|
50
|
-
}).component?.name;
|
|
51
|
-
|
|
52
|
-
if (!componentName) {
|
|
53
|
-
return null;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
const ref = context.registeredComponents[componentName];
|
|
57
|
-
|
|
58
|
-
if (!ref) {
|
|
59
|
-
// TODO: Public doc page with more info about this message
|
|
60
|
-
console.warn(`
|
|
61
|
-
Could not find a registered component named "${componentName}".
|
|
62
|
-
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
63
|
-
return undefined;
|
|
64
|
-
} else {
|
|
65
|
-
return ref;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
export const getRepeatItemData = ({
|
|
70
|
-
block,
|
|
71
|
-
context,
|
|
72
|
-
}: {
|
|
73
|
-
block: BuilderBlock;
|
|
74
|
-
context: BuilderContextInterface;
|
|
75
|
-
}): RepeatData[] | undefined => {
|
|
76
|
-
/**
|
|
77
|
-
* we don't use `state.useBlock` here because the processing done within its logic includes evaluating the block's bindings,
|
|
78
|
-
* which will not work if there is a repeat.
|
|
79
|
-
*/
|
|
80
|
-
const { repeat, ...blockWithoutRepeat } = block;
|
|
81
|
-
|
|
82
|
-
if (!repeat?.collection) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
const itemsArray = evaluate({
|
|
87
|
-
code: repeat.collection,
|
|
88
|
-
state: context.state,
|
|
89
|
-
context: context.context,
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
if (!Array.isArray(itemsArray)) {
|
|
93
|
-
return undefined;
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const collectionName = repeat.collection.split('.').pop();
|
|
97
|
-
const itemNameToUse =
|
|
98
|
-
repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
|
|
99
|
-
|
|
100
|
-
const repeatArray = itemsArray.map<RepeatData>((item, index) => ({
|
|
101
|
-
context: {
|
|
102
|
-
...context,
|
|
103
|
-
state: {
|
|
104
|
-
...context.state,
|
|
105
|
-
$index: index,
|
|
106
|
-
$item: item,
|
|
107
|
-
[itemNameToUse]: item,
|
|
108
|
-
[`$${itemNameToUse}Index`]: index,
|
|
109
|
-
},
|
|
110
|
-
},
|
|
111
|
-
block: blockWithoutRepeat,
|
|
112
|
-
}));
|
|
113
|
-
|
|
114
|
-
return repeatArray;
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
export const getProxyState = (
|
|
118
|
-
context: BuilderContextInterface
|
|
119
|
-
): BuilderContextInterface['state'] => {
|
|
120
|
-
if (typeof Proxy === 'undefined') {
|
|
121
|
-
console.error(
|
|
122
|
-
'no Proxy available in this environment, cannot proxy state.'
|
|
123
|
-
);
|
|
124
|
-
return context.state;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const useState = new Proxy(context.state, {
|
|
128
|
-
set: (obj, prop: keyof BuilderRenderState, value) => {
|
|
129
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
130
|
-
obj[prop] = value;
|
|
131
|
-
|
|
132
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
133
|
-
context.setState?.(obj);
|
|
134
|
-
return true;
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
return useState;
|
|
138
|
-
};
|
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useState } from "react";
|
|
4
|
-
|
|
5
|
-
export type RenderBlockProps = {
|
|
6
|
-
block: BuilderBlock;
|
|
7
|
-
context: BuilderContextInterface;
|
|
8
|
-
};
|
|
9
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
10
|
-
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
11
|
-
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
12
|
-
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
13
|
-
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
14
|
-
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
|
-
import BlockStyles from "./block-styles";
|
|
16
|
-
import {
|
|
17
|
-
getComponent,
|
|
18
|
-
getProxyState,
|
|
19
|
-
getRepeatItemData,
|
|
20
|
-
isEmptyHtmlElement,
|
|
21
|
-
} from "./render-block.helpers.js";
|
|
22
|
-
import type { RenderComponentProps } from "./render-component";
|
|
23
|
-
import RenderRepeatedBlock from "./render-repeated-block";
|
|
24
|
-
import { TARGET } from "../../constants/target.js";
|
|
25
|
-
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
26
|
-
import RenderComponent from "./render-component";
|
|
27
|
-
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
28
|
-
|
|
29
|
-
function RenderBlock(props: RenderBlockProps) {
|
|
30
|
-
const [component, setComponent] = useState(() =>
|
|
31
|
-
getComponent({
|
|
32
|
-
block: props.block,
|
|
33
|
-
context: props.context,
|
|
34
|
-
})
|
|
35
|
-
);
|
|
36
|
-
|
|
37
|
-
const [repeatItemData, setRepeatItemData] = useState(() =>
|
|
38
|
-
getRepeatItemData({
|
|
39
|
-
block: props.block,
|
|
40
|
-
context: props.context,
|
|
41
|
-
})
|
|
42
|
-
);
|
|
43
|
-
|
|
44
|
-
function useBlock() {
|
|
45
|
-
return repeatItemData
|
|
46
|
-
? props.block
|
|
47
|
-
: getProcessedBlock({
|
|
48
|
-
block: props.block,
|
|
49
|
-
state: props.context.state,
|
|
50
|
-
context: props.context.context,
|
|
51
|
-
shouldEvaluateBindings: true,
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
const [tag, setTag] = useState(() => props.block.tagName || "div");
|
|
56
|
-
|
|
57
|
-
function canShowBlock() {
|
|
58
|
-
if ("hide" in useBlock()) {
|
|
59
|
-
return !useBlock().hide;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
if ("show" in useBlock()) {
|
|
63
|
-
return useBlock().show;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
return true;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const [proxyState, setProxyState] = useState(() =>
|
|
70
|
-
getProxyState(props.context)
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
function actions() {
|
|
74
|
-
return getBlockActions({
|
|
75
|
-
block: useBlock(),
|
|
76
|
-
state: TARGET === "qwik" ? props.context.state : proxyState,
|
|
77
|
-
context: props.context.context,
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function attributes() {
|
|
82
|
-
const blockProperties = getBlockProperties(useBlock());
|
|
83
|
-
return {
|
|
84
|
-
...blockProperties,
|
|
85
|
-
...(TARGET === "reactNative"
|
|
86
|
-
? {
|
|
87
|
-
style: getReactNativeBlockStyles({
|
|
88
|
-
block: useBlock(),
|
|
89
|
-
context: props.context,
|
|
90
|
-
blockStyles: blockProperties.style,
|
|
91
|
-
}),
|
|
92
|
-
}
|
|
93
|
-
: {}),
|
|
94
|
-
};
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
function childrenWithoutParentComponent() {
|
|
98
|
-
/**
|
|
99
|
-
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
100
|
-
* we render them outside of `componentRef`.
|
|
101
|
-
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
102
|
-
* blocks, and the children will be repeated within those blocks.
|
|
103
|
-
*/
|
|
104
|
-
const shouldRenderChildrenOutsideRef =
|
|
105
|
-
!component?.component && !repeatItemData;
|
|
106
|
-
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function childrenContext() {
|
|
110
|
-
const getInheritedTextStyles = () => {
|
|
111
|
-
if (TARGET !== "reactNative") {
|
|
112
|
-
return {};
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
return extractTextStyles(
|
|
116
|
-
getReactNativeBlockStyles({
|
|
117
|
-
block: useBlock(),
|
|
118
|
-
context: props.context,
|
|
119
|
-
blockStyles: attributes().style,
|
|
120
|
-
})
|
|
121
|
-
);
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
return {
|
|
125
|
-
apiKey: props.context.apiKey,
|
|
126
|
-
apiVersion: props.context.apiVersion,
|
|
127
|
-
state: props.context.state,
|
|
128
|
-
content: props.context.content,
|
|
129
|
-
context: props.context.context,
|
|
130
|
-
setState: props.context.setState,
|
|
131
|
-
registeredComponents: props.context.registeredComponents,
|
|
132
|
-
inheritedStyles: getInheritedTextStyles(),
|
|
133
|
-
};
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
function renderComponentProps() {
|
|
137
|
-
return {
|
|
138
|
-
blockChildren: useBlock().children ?? [],
|
|
139
|
-
componentRef: component?.component,
|
|
140
|
-
componentOptions: {
|
|
141
|
-
...getBlockComponentOptions(useBlock()),
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
145
|
-
* they are provided to the component itself directly.
|
|
146
|
-
*/
|
|
147
|
-
...(!component?.noWrap
|
|
148
|
-
? {}
|
|
149
|
-
: {
|
|
150
|
-
attributes: { ...attributes(), ...actions() },
|
|
151
|
-
}),
|
|
152
|
-
},
|
|
153
|
-
context: childrenContext(),
|
|
154
|
-
};
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
const TagRef = tag;
|
|
158
|
-
|
|
159
|
-
return (
|
|
160
|
-
<>
|
|
161
|
-
{canShowBlock() ? (
|
|
162
|
-
<>
|
|
163
|
-
{!component?.noWrap ? (
|
|
164
|
-
<>
|
|
165
|
-
{isEmptyHtmlElement(tag) ? (
|
|
166
|
-
<>
|
|
167
|
-
<TagRef {...attributes()} {...actions()} />
|
|
168
|
-
</>
|
|
169
|
-
) : null}
|
|
170
|
-
{!isEmptyHtmlElement(tag) && repeatItemData ? (
|
|
171
|
-
<>
|
|
172
|
-
{repeatItemData?.map((data, index) => (
|
|
173
|
-
<RenderRepeatedBlock
|
|
174
|
-
key={index}
|
|
175
|
-
repeatContext={data.context}
|
|
176
|
-
block={data.block}
|
|
177
|
-
/>
|
|
178
|
-
))}
|
|
179
|
-
</>
|
|
180
|
-
) : null}
|
|
181
|
-
{!isEmptyHtmlElement(tag) && !repeatItemData ? (
|
|
182
|
-
<>
|
|
183
|
-
<TagRef {...attributes()} {...actions()}>
|
|
184
|
-
<RenderComponent {...renderComponentProps()} />
|
|
185
|
-
|
|
186
|
-
{childrenWithoutParentComponent()?.map((child) => (
|
|
187
|
-
<RenderBlock
|
|
188
|
-
key={"render-block-" + child.id}
|
|
189
|
-
block={child}
|
|
190
|
-
context={childrenContext()}
|
|
191
|
-
/>
|
|
192
|
-
))}
|
|
193
|
-
|
|
194
|
-
{childrenWithoutParentComponent()?.map((child) => (
|
|
195
|
-
<BlockStyles
|
|
196
|
-
key={"block-style-" + child.id}
|
|
197
|
-
block={child}
|
|
198
|
-
context={childrenContext()}
|
|
199
|
-
/>
|
|
200
|
-
))}
|
|
201
|
-
</TagRef>
|
|
202
|
-
</>
|
|
203
|
-
) : null}
|
|
204
|
-
</>
|
|
205
|
-
) : (
|
|
206
|
-
<>
|
|
207
|
-
<RenderComponent {...renderComponentProps()} />
|
|
208
|
-
</>
|
|
209
|
-
)}
|
|
210
|
-
</>
|
|
211
|
-
) : null}
|
|
212
|
-
</>
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
export default RenderBlock;
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
|
|
4
|
-
type ComponentOptions = {
|
|
5
|
-
[index: string]: any;
|
|
6
|
-
attributes?: {
|
|
7
|
-
[index: string]: any;
|
|
8
|
-
};
|
|
9
|
-
};
|
|
10
|
-
export interface RenderComponentProps {
|
|
11
|
-
componentRef: any;
|
|
12
|
-
componentOptions: ComponentOptions;
|
|
13
|
-
blockChildren: BuilderBlock[];
|
|
14
|
-
context: BuilderContextInterface;
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
-
import BlockStyles from "./block-styles";
|
|
19
|
-
import RenderBlock from "./render-block";
|
|
20
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
21
|
-
|
|
22
|
-
function RenderComponent(props: RenderComponentProps) {
|
|
23
|
-
const ComponentRefRef = props.componentRef;
|
|
24
|
-
|
|
25
|
-
return (
|
|
26
|
-
<>
|
|
27
|
-
{props.componentRef ? (
|
|
28
|
-
<>
|
|
29
|
-
<ComponentRefRef {...props.componentOptions}>
|
|
30
|
-
{props.blockChildren?.map((child) => (
|
|
31
|
-
<RenderBlock
|
|
32
|
-
key={"render-block-" + child.id}
|
|
33
|
-
block={child}
|
|
34
|
-
context={props.context}
|
|
35
|
-
/>
|
|
36
|
-
))}
|
|
37
|
-
|
|
38
|
-
{props.blockChildren?.map((child) => (
|
|
39
|
-
<BlockStyles
|
|
40
|
-
key={"block-style-" + child.id}
|
|
41
|
-
block={child}
|
|
42
|
-
context={props.context}
|
|
43
|
-
/>
|
|
44
|
-
))}
|
|
45
|
-
</ComponentRefRef>
|
|
46
|
-
</>
|
|
47
|
-
) : null}
|
|
48
|
-
</>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export default RenderComponent;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useContext } from "react";
|
|
4
|
-
|
|
5
|
-
type Props = {
|
|
6
|
-
block: BuilderBlock;
|
|
7
|
-
repeatContext: BuilderContextInterface;
|
|
8
|
-
};
|
|
9
|
-
/**
|
|
10
|
-
* We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
|
|
11
|
-
*
|
|
12
|
-
* ```vue
|
|
13
|
-
* <template>
|
|
14
|
-
* <slot></slot>
|
|
15
|
-
* </template>
|
|
16
|
-
* ```
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
20
|
-
import type { BuilderContextInterface } from "../../context/types.js";
|
|
21
|
-
import type { BuilderBlock } from "../../types/builder-block";
|
|
22
|
-
import RenderBlock from "./render-block";
|
|
23
|
-
|
|
24
|
-
function RenderRepeatedBlock(props: Props) {
|
|
25
|
-
return (
|
|
26
|
-
<BuilderContext.Provider
|
|
27
|
-
value={{
|
|
28
|
-
content: props.repeatContext.content,
|
|
29
|
-
state: props.repeatContext.state,
|
|
30
|
-
setState: props.repeatContext.setState,
|
|
31
|
-
context: props.repeatContext.context,
|
|
32
|
-
apiKey: props.repeatContext.apiKey,
|
|
33
|
-
registeredComponents: props.repeatContext.registeredComponents,
|
|
34
|
-
inheritedStyles: props.repeatContext.inheritedStyles,
|
|
35
|
-
apiVersion: props.repeatContext.apiVersion,
|
|
36
|
-
}}
|
|
37
|
-
>
|
|
38
|
-
<RenderBlock block={props.block} context={props.repeatContext} />
|
|
39
|
-
</BuilderContext.Provider>
|
|
40
|
-
);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
export default RenderRepeatedBlock;
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import { useContext } from "react";
|
|
4
|
-
|
|
5
|
-
export type RenderBlockProps = {
|
|
6
|
-
blocks?: BuilderBlock[];
|
|
7
|
-
parent?: string;
|
|
8
|
-
path?: string;
|
|
9
|
-
styleProp?: Record<string, any>;
|
|
10
|
-
};
|
|
11
|
-
import BuilderContext from "../context/builder.context.js";
|
|
12
|
-
import { isEditing } from "../functions/is-editing.js";
|
|
13
|
-
import type { BuilderBlock } from "../types/builder-block.js";
|
|
14
|
-
import BlockStyles from "./render-block/block-styles";
|
|
15
|
-
import RenderBlock from "./render-block/render-block";
|
|
16
|
-
|
|
17
|
-
function RenderBlocks(props: RenderBlockProps) {
|
|
18
|
-
function className() {
|
|
19
|
-
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function onClick() {
|
|
23
|
-
if (isEditing() && !props.blocks?.length) {
|
|
24
|
-
window.parent?.postMessage(
|
|
25
|
-
{
|
|
26
|
-
type: "builder.clickEmptyBlocks",
|
|
27
|
-
data: {
|
|
28
|
-
parentElementId: props.parent,
|
|
29
|
-
dataPath: props.path,
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
"*"
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function onMouseEnter() {
|
|
38
|
-
if (isEditing() && !props.blocks?.length) {
|
|
39
|
-
window.parent?.postMessage(
|
|
40
|
-
{
|
|
41
|
-
type: "builder.hoverEmptyBlocks",
|
|
42
|
-
data: {
|
|
43
|
-
parentElementId: props.parent,
|
|
44
|
-
dataPath: props.path,
|
|
45
|
-
},
|
|
46
|
-
},
|
|
47
|
-
"*"
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const builderContext = useContext(BuilderContext);
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
<>
|
|
56
|
-
<div
|
|
57
|
-
className={className() + " div-251582f2"}
|
|
58
|
-
builder-path={props.path}
|
|
59
|
-
builder-parent-id={props.parent}
|
|
60
|
-
style={props.styleProp}
|
|
61
|
-
onClick={(event) => onClick()}
|
|
62
|
-
onMouseEnter={(event) => onMouseEnter()}
|
|
63
|
-
>
|
|
64
|
-
{props.blocks ? (
|
|
65
|
-
<>
|
|
66
|
-
{props.blocks?.map((block) => (
|
|
67
|
-
<RenderBlock
|
|
68
|
-
key={"render-block-" + block.id}
|
|
69
|
-
block={block}
|
|
70
|
-
context={builderContext}
|
|
71
|
-
/>
|
|
72
|
-
))}
|
|
73
|
-
</>
|
|
74
|
-
) : null}
|
|
75
|
-
|
|
76
|
-
{props.blocks ? (
|
|
77
|
-
<>
|
|
78
|
-
{props.blocks?.map((block) => (
|
|
79
|
-
<BlockStyles
|
|
80
|
-
key={"block-style-" + block.id}
|
|
81
|
-
block={block}
|
|
82
|
-
context={builderContext}
|
|
83
|
-
/>
|
|
84
|
-
))}
|
|
85
|
-
</>
|
|
86
|
-
) : null}
|
|
87
|
-
</div>
|
|
88
|
-
<style>{`.div-251582f2 {
|
|
89
|
-
display: flex;
|
|
90
|
-
flex-direction: column;
|
|
91
|
-
align-items: stretch;
|
|
92
|
-
}`}</style>
|
|
93
|
-
</>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
export default RenderBlocks;
|