@builder.io/sdk-react 0.4.4 → 0.4.5

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.
Files changed (63) hide show
  1. package/dist/sdk/blocks/columns/columns.js +6 -6
  2. package/dist/sdk/blocks/symbol/symbol.js +7 -5
  3. package/dist/sdk/blocks/text/text.d.ts +1 -1
  4. package/dist/sdk/blocks/text/text.js +1 -1
  5. package/dist/sdk/components/block/block.d.ts +11 -0
  6. package/dist/sdk/components/block/block.helpers.d.ts +12 -0
  7. package/dist/sdk/components/block/block.helpers.js +86 -0
  8. package/dist/sdk/components/block/block.js +124 -0
  9. package/dist/sdk/components/block/components/block-styles.d.ts +9 -0
  10. package/dist/sdk/components/block/components/block-styles.js +65 -0
  11. package/dist/sdk/components/block/components/component.d.ts +20 -0
  12. package/dist/sdk/components/block/components/component.js +11 -0
  13. package/dist/sdk/components/block/components/repeated-block.d.ts +11 -0
  14. package/dist/sdk/components/block/components/repeated-block.js +11 -0
  15. package/dist/sdk/components/block/types.d.ts +6 -0
  16. package/dist/sdk/components/block/types.js +1 -0
  17. package/dist/sdk/components/blocks/blocks-wrapper.d.ts +13 -0
  18. package/dist/sdk/components/blocks/blocks-wrapper.js +38 -0
  19. package/dist/sdk/components/blocks/blocks.d.ts +10 -0
  20. package/dist/sdk/components/blocks/blocks.js +11 -0
  21. package/dist/sdk/components/content/components/content-styles.d.ts +9 -0
  22. package/dist/sdk/components/content/components/content-styles.helpers.d.ts +15 -0
  23. package/dist/sdk/components/content/components/content-styles.helpers.js +59 -0
  24. package/dist/sdk/components/content/components/content-styles.js +32 -0
  25. package/dist/sdk/components/content/components/enable-editor.d.ts +13 -0
  26. package/dist/sdk/components/content/components/enable-editor.js +278 -0
  27. package/dist/sdk/components/content/content.d.ts +4 -0
  28. package/dist/sdk/components/content/content.helpers.d.ts +7 -0
  29. package/dist/sdk/components/content/content.helpers.js +30 -0
  30. package/dist/sdk/components/content/content.js +97 -0
  31. package/dist/sdk/components/content/content.types.d.ts +38 -0
  32. package/dist/sdk/components/content/content.types.js +1 -0
  33. package/dist/sdk/components/content/index.d.ts +1 -0
  34. package/dist/sdk/components/content/index.js +1 -0
  35. package/dist/sdk/components/content/wrap-component-ref.d.ts +6 -0
  36. package/dist/sdk/components/content/wrap-component-ref.js +6 -0
  37. package/dist/sdk/components/content-variants/content-variants.d.ts +5 -0
  38. package/dist/sdk/components/content-variants/content-variants.js +37 -0
  39. package/dist/sdk/components/content-variants/helpers.d.ts +17 -0
  40. package/dist/sdk/components/content-variants/helpers.js +184 -0
  41. package/dist/sdk/components/inlined-script.d.ts +7 -0
  42. package/dist/sdk/components/inlined-script.js +6 -0
  43. package/dist/sdk/components/inlined-styles.d.ts +7 -0
  44. package/dist/sdk/components/inlined-styles.js +6 -0
  45. package/dist/sdk/components/render-block/block-styles.js +2 -2
  46. package/dist/sdk/components/render-content/components/render-styles.js +2 -2
  47. package/dist/sdk/components/render-content/render-content.js +8 -6
  48. package/dist/sdk/components/render-content/render-content.types.d.ts +9 -23
  49. package/dist/sdk/components/render-content-variants/helpers.d.ts +27 -3
  50. package/dist/sdk/components/render-content-variants/helpers.js +38 -24
  51. package/dist/sdk/components/render-content-variants/render-content-variants.d.ts +7 -2
  52. package/dist/sdk/components/render-content-variants/render-content-variants.js +29 -21
  53. package/dist/sdk/components/render-content-variants/render-content-variants.types.d.ts +20 -0
  54. package/dist/sdk/components/render-content-variants/render-content-variants.types.js +1 -0
  55. package/dist/sdk/constants/sdk-version.d.ts +1 -1
  56. package/dist/sdk/constants/sdk-version.js +1 -1
  57. package/dist/sdk/helpers/ab-tests.js +6 -0
  58. package/dist/sdk/types/builder-props.d.ts +10 -0
  59. package/dist/sdk/types/builder-props.js +1 -0
  60. package/dist/sdk/types/enforced-partials.d.ts +21 -0
  61. package/dist/sdk/types/enforced-partials.js +1 -0
  62. package/dist/sdk/types/typescript.d.ts +3 -0
  63. package/package.json +1 -1
@@ -3,7 +3,7 @@ import * as React from "react";
3
3
  import { useState, useContext } from "react";
4
4
  import RenderBlocks from "../../components/render-blocks";
5
5
  import { getSizesForBreakpoints } from "../../constants/device-sizes";
6
- import RenderInlinedStyles from "../../components/render-inlined-styles";
6
+ import InlinedStyles from "../../components/inlined-styles";
7
7
  import { TARGET } from "../../constants/target.js";
8
8
  import BuilderContext from "../../context/builder.context.js";
9
9
  function Columns(props) {
@@ -108,17 +108,17 @@ function Columns(props) {
108
108
  const builderContext = useContext(BuilderContext);
109
109
  return (React.createElement(React.Fragment, null,
110
110
  React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
111
- " div-fa2ab8fc", style: columnsCssVars() },
111
+ " div-1d72a8ba", style: columnsCssVars() },
112
112
  TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
113
- React.createElement(RenderInlinedStyles, { styles: columnsStyles() }))) : null,
114
- props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-fa2ab8fc-2", style: columnCssVars(index), key: index },
113
+ React.createElement(InlinedStyles, { styles: columnsStyles() }))) : null,
114
+ props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-1d72a8ba-2", style: columnCssVars(index), key: index },
115
115
  React.createElement(RenderBlocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
116
116
  flexGrow: "1",
117
117
  } }))))),
118
- React.createElement("style", null, `.div-fa2ab8fc {
118
+ React.createElement("style", null, `.div-1d72a8ba {
119
119
  display: flex;
120
120
  line-height: normal;
121
- }.div-fa2ab8fc-2 {
121
+ }.div-1d72a8ba-2 {
122
122
  display: flex;
123
123
  flex-direction: column;
124
124
  align-items: stretch;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import * as React from "react";
3
3
  import { useState, useContext, useEffect } from "react";
4
- import RenderContent from "../../components/render-content/render-content";
4
+ import RenderContentVariants from "../../components/render-content-variants/render-content-variants";
5
5
  import BuilderContext from "../../context/builder.context.js";
6
6
  import { getContent } from "../../functions/get-content/index.js";
7
7
  import { TARGET } from "../../constants/target";
@@ -38,9 +38,11 @@ function Symbol(props) {
38
38
  model: props.symbol.model,
39
39
  apiKey: builderContext.apiKey,
40
40
  apiVersion: builderContext.apiVersion,
41
- query: {
42
- id: props.symbol.entry,
43
- },
41
+ ...(props.symbol?.entry && {
42
+ query: {
43
+ id: props.symbol.entry,
44
+ },
45
+ }),
44
46
  })
45
47
  .then((response) => {
46
48
  if (response) {
@@ -60,7 +62,7 @@ function Symbol(props) {
60
62
  fetchContent();
61
63
  }, [props.symbol]);
62
64
  return (React.createElement("div", { ...props.attributes, className: className },
63
- React.createElement(RenderContent, { apiVersion: builderContext.apiVersion, apiKey: builderContext.apiKey, context: builderContext.context, customComponents: Object.values(builderContext.registeredComponents), data: {
65
+ React.createElement(RenderContentVariants, { __isNestedRender: true, apiVersion: builderContext.apiVersion, apiKey: builderContext.apiKey, context: builderContext.context, customComponents: Object.values(builderContext.registeredComponents), data: {
64
66
  ...props.symbol?.data,
65
67
  ...builderContext.localState,
66
68
  ...contentToUse?.data?.state,
@@ -1,6 +1,6 @@
1
1
  /// <reference types="react" />
2
2
  export interface TextProps {
3
- text: string;
3
+ text?: string;
4
4
  }
5
5
  declare function Text(props: TextProps): JSX.Element;
6
6
  export default Text;
@@ -1,7 +1,7 @@
1
1
  'use client';
2
2
  import * as React from "react";
3
3
  function Text(props) {
4
- return (React.createElement("span", { className: "builder-text", dangerouslySetInnerHTML: { __html: props.text }, style: {
4
+ return (React.createElement("span", { className: "builder-text", dangerouslySetInnerHTML: { __html: props.text?.toString() }, style: {
5
5
  outline: "none",
6
6
  } }));
7
7
  }
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ export type BlockProps = {
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ components: Dictionary<RegisteredComponent>;
6
+ };
7
+ import type { BuilderContextInterface, RegisteredComponent } from "../../context/types.js";
8
+ import type { BuilderBlock } from "../../types/builder-block.js";
9
+ import type { Dictionary } from "../../types/typescript.js";
10
+ declare function Block(props: BlockProps): JSX.Element;
11
+ export default Block;
@@ -0,0 +1,12 @@
1
+ import type { BuilderContextInterface } from '../../context/types';
2
+ import type { BuilderBlock } from '../../types/builder-block';
3
+ import type { RepeatData } from './types';
4
+ export declare const isEmptyHtmlElement: (tagName: unknown) => boolean;
5
+ export declare const getComponent: ({ block, context, }: {
6
+ block: BuilderBlock;
7
+ context: BuilderContextInterface;
8
+ }) => import("../../context/types").RegisteredComponent;
9
+ export declare const getRepeatItemData: ({ block, context, }: {
10
+ block: BuilderBlock;
11
+ context: BuilderContextInterface;
12
+ }) => RepeatData[] | undefined;
@@ -0,0 +1,86 @@
1
+ import { evaluate } from '../../functions/evaluate';
2
+ import { getProcessedBlock } from '../../functions/get-processed-block';
3
+ /**
4
+ * https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
5
+ */
6
+ const EMPTY_HTML_ELEMENTS = [
7
+ 'area',
8
+ 'base',
9
+ 'br',
10
+ 'col',
11
+ 'embed',
12
+ 'hr',
13
+ 'img',
14
+ 'input',
15
+ 'keygen',
16
+ 'link',
17
+ 'meta',
18
+ 'param',
19
+ 'source',
20
+ 'track',
21
+ 'wbr',
22
+ ];
23
+ export const isEmptyHtmlElement = (tagName) => {
24
+ return (typeof tagName === 'string' &&
25
+ EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase()));
26
+ };
27
+ export const getComponent = ({ block, context, }) => {
28
+ const componentName = getProcessedBlock({
29
+ block,
30
+ localState: context.localState,
31
+ rootState: context.rootState,
32
+ rootSetState: context.rootSetState,
33
+ context: context.context,
34
+ shouldEvaluateBindings: false,
35
+ }).component?.name;
36
+ if (!componentName) {
37
+ return null;
38
+ }
39
+ const ref = context.registeredComponents[componentName];
40
+ if (!ref) {
41
+ // TODO: Public doc page with more info about this message
42
+ console.warn(`
43
+ Could not find a registered component named "${componentName}".
44
+ If you registered it, is the file that registered it imported by the file that needs to render it?`);
45
+ return undefined;
46
+ }
47
+ else {
48
+ return ref;
49
+ }
50
+ };
51
+ export const getRepeatItemData = ({ block, context, }) => {
52
+ /**
53
+ * we don't use `state.useBlock` here because the processing done within its logic includes evaluating the block's bindings,
54
+ * which will not work if there is a repeat.
55
+ */
56
+ const { repeat, ...blockWithoutRepeat } = block;
57
+ if (!repeat?.collection) {
58
+ return undefined;
59
+ }
60
+ const itemsArray = evaluate({
61
+ code: repeat.collection,
62
+ localState: context.localState,
63
+ rootState: context.rootState,
64
+ rootSetState: context.rootSetState,
65
+ context: context.context,
66
+ });
67
+ if (!Array.isArray(itemsArray)) {
68
+ return undefined;
69
+ }
70
+ const collectionName = repeat.collection.split('.').pop();
71
+ const itemNameToUse = repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
72
+ const repeatArray = itemsArray.map((item, index) => ({
73
+ context: {
74
+ ...context,
75
+ localState: {
76
+ ...context.localState,
77
+ $index: index,
78
+ $item: item,
79
+ [itemNameToUse]: item,
80
+ [`$${itemNameToUse}Index`]: index,
81
+ },
82
+ },
83
+ block: blockWithoutRepeat,
84
+ }));
85
+ return repeatArray;
86
+ };
@@ -0,0 +1,124 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { useState } from "react";
4
+ import { getBlockActions } from "../../functions/get-block-actions.js";
5
+ import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
6
+ import { getBlockProperties } from "../../functions/get-block-properties.js";
7
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
8
+ import BlockStyles from "./components/block-styles";
9
+ import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./block.helpers.js";
10
+ import RepeatedBlock from "./components/repeated-block";
11
+ import { TARGET } from "../../constants/target.js";
12
+ import Component from "./components/component";
13
+ import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
14
+ function Block(props) {
15
+ const [component, setComponent] = useState(() => getComponent({
16
+ block: props.block,
17
+ context: props.context,
18
+ }));
19
+ function repeatItem() {
20
+ return getRepeatItemData({
21
+ block: props.block,
22
+ context: props.context,
23
+ });
24
+ }
25
+ function processedBlock() {
26
+ return repeatItem()
27
+ ? props.block
28
+ : getProcessedBlock({
29
+ block: props.block,
30
+ localState: props.context.localState,
31
+ rootState: props.context.rootState,
32
+ rootSetState: props.context.rootSetState,
33
+ context: props.context.context,
34
+ shouldEvaluateBindings: true,
35
+ });
36
+ }
37
+ const [Tag, setTag] = useState(() => props.block.tagName || "div");
38
+ function canShowBlock() {
39
+ if ("hide" in processedBlock()) {
40
+ return !processedBlock().hide;
41
+ }
42
+ if ("show" in processedBlock()) {
43
+ return processedBlock().show;
44
+ }
45
+ return true;
46
+ }
47
+ function actions() {
48
+ return getBlockActions({
49
+ block: processedBlock(),
50
+ rootState: props.context.rootState,
51
+ rootSetState: props.context.rootSetState,
52
+ localState: props.context.localState,
53
+ context: props.context.context,
54
+ });
55
+ }
56
+ function attributes() {
57
+ const blockProperties = getBlockProperties(processedBlock());
58
+ return {
59
+ ...blockProperties,
60
+ ...(TARGET === "reactNative"
61
+ ? {
62
+ style: getReactNativeBlockStyles({
63
+ block: processedBlock(),
64
+ context: props.context,
65
+ blockStyles: blockProperties.style,
66
+ }),
67
+ }
68
+ : {}),
69
+ };
70
+ }
71
+ function childrenWithoutParentComponent() {
72
+ /**
73
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
74
+ * we render them outside of `componentRef`.
75
+ * NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
76
+ * blocks, and the children will be repeated within those blocks.
77
+ */
78
+ const shouldRenderChildrenOutsideRef = !component?.component && !repeatItem();
79
+ return shouldRenderChildrenOutsideRef
80
+ ? processedBlock().children ?? []
81
+ : [];
82
+ }
83
+ function renderComponentProps() {
84
+ return {
85
+ blockChildren: processedBlock().children ?? [],
86
+ componentRef: component?.component,
87
+ componentOptions: {
88
+ ...getBlockComponentOptions(processedBlock()),
89
+ /**
90
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
91
+ * they are provided to the component itself directly.
92
+ */
93
+ ...(!component?.noWrap
94
+ ? {}
95
+ : {
96
+ attributes: {
97
+ ...attributes(),
98
+ ...actions(),
99
+ },
100
+ }),
101
+ builderContext: props.context,
102
+ ...(component?.name === "Symbol" || component?.name === "Columns"
103
+ ? {
104
+ builderComponents: props.components,
105
+ }
106
+ : {}),
107
+ },
108
+ context: childrenContext,
109
+ components: props.components,
110
+ };
111
+ }
112
+ const [childrenContext, setChildrenContext] = useState(() => props.context);
113
+ return (React.createElement(React.Fragment, null, canShowBlock() ? (React.createElement(React.Fragment, null, !component?.noWrap ? (React.createElement(React.Fragment, null,
114
+ isEmptyHtmlElement(Tag) ? (React.createElement(React.Fragment, null,
115
+ React.createElement(Tag, { ...attributes(), ...actions() }))) : null,
116
+ !isEmptyHtmlElement(Tag) && repeatItem() ? (React.createElement(React.Fragment, null, repeatItem()?.map((data, index) => (React.createElement(RepeatedBlock, { key: index, repeatContext: data.context, block: data.block, components: props.components }))))) : null,
117
+ !isEmptyHtmlElement(Tag) && !repeatItem() ? (React.createElement(React.Fragment, null,
118
+ React.createElement(Tag, { ...attributes(), ...actions() },
119
+ React.createElement(Component, { ...renderComponentProps() }),
120
+ childrenWithoutParentComponent()?.map((child) => (React.createElement(Block, { key: "render-block-" + child.id, block: child, context: childrenContext, components: props.components }))),
121
+ childrenWithoutParentComponent()?.map((child) => (React.createElement(BlockStyles, { key: "block-style-" + child.id, block: child, context: childrenContext })))))) : null)) : (React.createElement(React.Fragment, null,
122
+ React.createElement(Component, { ...renderComponentProps() }))))) : null));
123
+ }
124
+ export default Block;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ export type BlockStylesProps = {
3
+ block: BuilderBlock;
4
+ context: BuilderContextInterface;
5
+ };
6
+ import type { BuilderContextInterface } from "../../../context/types.js";
7
+ import type { BuilderBlock } from "../../../types/builder-block.js";
8
+ declare function BlockStyles(props: BlockStylesProps): JSX.Element;
9
+ export default BlockStyles;
@@ -0,0 +1,65 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { useState } from "react";
4
+ import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../../constants/device-sizes.js";
5
+ import { TARGET } from "../../../constants/target.js";
6
+ import { getProcessedBlock } from "../../../functions/get-processed-block.js";
7
+ import { createCssClass } from "../../../helpers/css.js";
8
+ import { checkIsDefined } from "../../../helpers/nullable.js";
9
+ import InlinedStyles from "../../inlined-styles";
10
+ function BlockStyles(props) {
11
+ const [processedBlock, setProcessedBlock] = useState(() => getProcessedBlock({
12
+ block: props.block,
13
+ localState: props.context.localState,
14
+ rootState: props.context.rootState,
15
+ rootSetState: props.context.rootSetState,
16
+ context: props.context.context,
17
+ shouldEvaluateBindings: true,
18
+ }));
19
+ function canShowBlock() {
20
+ // only render styles for blocks that are visible
21
+ if (checkIsDefined(processedBlock.hide)) {
22
+ return !processedBlock.hide;
23
+ }
24
+ if (checkIsDefined(processedBlock.show)) {
25
+ return processedBlock.show;
26
+ }
27
+ return true;
28
+ }
29
+ function css() {
30
+ const styles = processedBlock.responsiveStyles;
31
+ const content = props.context.content;
32
+ const sizesWithUpdatedBreakpoints = getSizesForBreakpoints(content?.meta?.breakpoints || {});
33
+ const largeStyles = styles?.large;
34
+ const mediumStyles = styles?.medium;
35
+ const smallStyles = styles?.small;
36
+ const className = processedBlock.id;
37
+ if (!className) {
38
+ return "";
39
+ }
40
+ const largeStylesClass = largeStyles
41
+ ? createCssClass({
42
+ className,
43
+ styles: largeStyles,
44
+ })
45
+ : "";
46
+ const mediumStylesClass = mediumStyles
47
+ ? createCssClass({
48
+ className,
49
+ styles: mediumStyles,
50
+ mediaQuery: getMaxWidthQueryForSize("medium", sizesWithUpdatedBreakpoints),
51
+ })
52
+ : "";
53
+ const smallStylesClass = smallStyles
54
+ ? createCssClass({
55
+ className,
56
+ styles: smallStyles,
57
+ mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
58
+ })
59
+ : "";
60
+ return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
61
+ }
62
+ return (React.createElement(React.Fragment, null, TARGET !== "reactNative" && css() && canShowBlock() ? (React.createElement(React.Fragment, null,
63
+ React.createElement(InlinedStyles, { styles: css() }))) : null));
64
+ }
65
+ export default BlockStyles;
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ type ComponentOptions = PropsWithBuilderData<{
3
+ [index: string]: any;
4
+ attributes?: {
5
+ [index: string]: any;
6
+ };
7
+ }>;
8
+ export interface ComponentProps {
9
+ componentRef: any;
10
+ componentOptions: ComponentOptions;
11
+ blockChildren: BuilderBlock[];
12
+ context: BuilderContextInterface;
13
+ components: Dictionary<RegisteredComponent>;
14
+ }
15
+ import type { BuilderBlock } from "../../../types/builder-block.js";
16
+ import type { BuilderContextInterface, RegisteredComponent } from "../../../context/types.js";
17
+ import type { PropsWithBuilderData } from "../../../types/builder-props.js";
18
+ import type { Dictionary } from "../../../types/typescript.js";
19
+ declare function Component(props: ComponentProps): JSX.Element;
20
+ export default Component;
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import BlockStyles from "./block-styles";
4
+ import Block from "../block";
5
+ function Component(props) {
6
+ return (React.createElement(React.Fragment, null, props.componentRef ? (React.createElement(React.Fragment, null,
7
+ React.createElement(props.componentRef, { ...props.componentOptions },
8
+ props.blockChildren?.map((child) => (React.createElement(Block, { key: "render-block-" + child.id, block: child, context: props.context, components: props.components }))),
9
+ props.blockChildren?.map((child) => (React.createElement(BlockStyles, { key: "block-style-" + child.id, block: child, context: props.context })))))) : null));
10
+ }
11
+ export default Component;
@@ -0,0 +1,11 @@
1
+ /// <reference types="react" />
2
+ type Props = {
3
+ block: BuilderBlock;
4
+ repeatContext: BuilderContextInterface;
5
+ components: Dictionary<RegisteredComponent>;
6
+ };
7
+ import type { BuilderContextInterface, RegisteredComponent } from "../../../context/types.js";
8
+ import type { BuilderBlock } from "../../../types/builder-block";
9
+ import type { Dictionary } from "../../../types/typescript";
10
+ declare function RepeatedBlock(props: Props): JSX.Element;
11
+ export default RepeatedBlock;
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { useState } from "react";
4
+ import BuilderContext from "../../../context/builder.context.js";
5
+ import Block from "../block";
6
+ function RepeatedBlock(props) {
7
+ const [store, setStore] = useState(() => props.repeatContext);
8
+ return (React.createElement(BuilderContext.Provider, { value: store },
9
+ React.createElement(Block, { block: props.block, context: store, components: props.components })));
10
+ }
11
+ export default RepeatedBlock;
@@ -0,0 +1,6 @@
1
+ import type { BuilderContextInterface } from '../../context/types.js';
2
+ import type { BuilderBlock } from '../../types/builder-block.js';
3
+ export interface RepeatData {
4
+ block: BuilderBlock;
5
+ context: BuilderContextInterface;
6
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,13 @@
1
+ /// <reference types="react" />
2
+ export type BlocksWrapperProps = {
3
+ blocks: BuilderBlock[] | undefined;
4
+ parent: string | undefined;
5
+ path: string | undefined;
6
+ styleProp: Record<string, any> | undefined;
7
+ };
8
+ type PropsWithChildren = BlocksWrapperProps & {
9
+ children?: any;
10
+ };
11
+ import type { BuilderBlock } from "../../types/builder-block.js";
12
+ declare function BlocksWrapper(props: PropsWithChildren): JSX.Element;
13
+ export default BlocksWrapper;
@@ -0,0 +1,38 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import { isEditing } from "../../functions/is-editing.js";
4
+ function BlocksWrapper(props) {
5
+ function className() {
6
+ return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
7
+ }
8
+ function onClick() {
9
+ if (isEditing() && !props.blocks?.length) {
10
+ window.parent?.postMessage({
11
+ type: "builder.clickEmptyBlocks",
12
+ data: {
13
+ parentElementId: props.parent,
14
+ dataPath: props.path,
15
+ },
16
+ }, "*");
17
+ }
18
+ }
19
+ function onMouseEnter() {
20
+ if (isEditing() && !props.blocks?.length) {
21
+ window.parent?.postMessage({
22
+ type: "builder.hoverEmptyBlocks",
23
+ data: {
24
+ parentElementId: props.parent,
25
+ dataPath: props.path,
26
+ },
27
+ }, "*");
28
+ }
29
+ }
30
+ return (React.createElement(React.Fragment, null,
31
+ React.createElement("div", { className: className() + " div-7cb52693", "builder-path": props.path, "builder-parent-id": props.parent, style: props.styleProp, onClick: (event) => onClick(), onMouseEnter: (event) => onMouseEnter(), onKeyPress: (event) => onClick() }, props.children),
32
+ React.createElement("style", null, `.div-7cb52693 {
33
+ display: flex;
34
+ flex-direction: column;
35
+ align-items: stretch;
36
+ }`)));
37
+ }
38
+ export default BlocksWrapper;
@@ -0,0 +1,10 @@
1
+ /// <reference types="react" />
2
+ export type BlocksProps = Partial<BlocksWrapperProps> & {
3
+ context: BuilderContextInterface;
4
+ components: Dictionary<RegisteredComponent>;
5
+ };
6
+ import type { BlocksWrapperProps } from "./blocks-wrapper";
7
+ import type { BuilderContextInterface, RegisteredComponent } from "../../context/types.js";
8
+ import type { Dictionary } from "../../types/typescript";
9
+ declare function Blocks(props: BlocksProps): JSX.Element;
10
+ export default Blocks;
@@ -0,0 +1,11 @@
1
+ 'use client';
2
+ import * as React from "react";
3
+ import BlockStyles from "../block/components/block-styles";
4
+ import Block from "../block/block";
5
+ import BlocksWrapper from "./blocks-wrapper";
6
+ function Blocks(props) {
7
+ return (React.createElement(BlocksWrapper, { blocks: props.blocks, parent: props.parent, path: props.path, styleProp: props.styleProp },
8
+ props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(Block, { key: "render-block-" + block.id, block: block, context: props.context, components: props.components }))))) : null,
9
+ props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(BlockStyles, { key: "block-style-" + block.id, block: block, context: props.context }))))) : null));
10
+ }
11
+ export default Blocks;
@@ -0,0 +1,9 @@
1
+ /// <reference types="react" />
2
+ interface Props {
3
+ cssCode?: string;
4
+ customFonts?: CustomFont[];
5
+ contentId?: string;
6
+ }
7
+ import type { CustomFont } from "./content-styles.helpers";
8
+ declare function ContentStyles(props: Props): JSX.Element;
9
+ export default ContentStyles;
@@ -0,0 +1,15 @@
1
+ export interface CustomFont {
2
+ family?: string;
3
+ kind?: string;
4
+ fileUrl?: string;
5
+ files?: {
6
+ [key: string]: string;
7
+ };
8
+ }
9
+ export declare const getFontCss: ({ customFonts }: {
10
+ customFonts?: CustomFont[];
11
+ }) => string;
12
+ export declare const getCss: ({ cssCode, contentId, }: {
13
+ cssCode?: string;
14
+ contentId?: string;
15
+ }) => string;
@@ -0,0 +1,59 @@
1
+ const getCssFromFont = (font) => {
2
+ // TODO: compute what font sizes are used and only load those.......
3
+ const family = font.family +
4
+ (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
5
+ const name = family.split(',')[0];
6
+ const url = font.fileUrl ?? font?.files?.regular;
7
+ let str = '';
8
+ if (url && family && name) {
9
+ str += `
10
+ @font-face {
11
+ font-family: "${family}";
12
+ src: local("${name}"), url('${url}') format('woff2');
13
+ font-display: fallback;
14
+ font-weight: 400;
15
+ }
16
+ `.trim();
17
+ }
18
+ if (font.files) {
19
+ for (const weight in font.files) {
20
+ const isNumber = String(Number(weight)) === weight;
21
+ if (!isNumber) {
22
+ continue;
23
+ }
24
+ // TODO: maybe limit number loaded
25
+ const weightUrl = font.files[weight];
26
+ if (weightUrl && weightUrl !== url) {
27
+ str += `
28
+ @font-face {
29
+ font-family: "${family}";
30
+ src: url('${weightUrl}') format('woff2');
31
+ font-display: fallback;
32
+ font-weight: ${weight};
33
+ }
34
+ `.trim();
35
+ }
36
+ }
37
+ }
38
+ return str;
39
+ };
40
+ export const getFontCss = ({ customFonts }) => {
41
+ // TODO: flag for this
42
+ // if (!this.builder.allowCustomFonts) {
43
+ // return '';
44
+ // }
45
+ // TODO: separate internal data from external
46
+ return customFonts?.map((font) => getCssFromFont(font))?.join(' ') || '';
47
+ };
48
+ export const getCss = ({ cssCode, contentId, }) => {
49
+ if (!cssCode) {
50
+ return '';
51
+ }
52
+ if (!contentId) {
53
+ return cssCode;
54
+ }
55
+ // Allow using `&` in custom CSS code like @emotion
56
+ // E.g. `& .foobar { ... }` to scope CSS
57
+ // TODO: handle if '&' is within a string like `content: "&"`
58
+ return cssCode?.replace(/&/g, `div[builder-content-id="${contentId}"]`) || '';
59
+ };