@builder.io/sdk-solid 0.0.22 → 0.0.23

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.22",
3
+ "version": "0.0.23",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -1,6 +1,10 @@
1
- import { For } from "solid-js";
1
+ import { Show, For } from "solid-js";
2
2
  import { css } from "solid-styled-components";
3
3
  import RenderBlocks from "../../components/render-blocks.jsx";
4
+ import { getSizesForBreakpoints } from "../../constants/device-sizes";
5
+ import RenderInlinedStyles from "../../components/render-inlined-styles.jsx";
6
+ import { TARGET } from "../../constants/target.js";
7
+ import { convertStyleMapToCSS } from "../../helpers/css";
4
8
  function Columns(props) {
5
9
  function getGutterSize() {
6
10
  return typeof props.space === "number" ? props.space || 0 : 20;
@@ -39,35 +43,84 @@ function Columns(props) {
39
43
  "--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
40
44
  };
41
45
  }
42
- return <div class={"builder-columns " + css({
46
+ function getWidthForBreakpointSize(size) {
47
+ const breakpointSizes = getSizesForBreakpoints(props.customBreakpoints || {});
48
+ return breakpointSizes[size].max;
49
+ }
50
+ function columnStyleObjects() {
51
+ return {
52
+ columns: {
53
+ small: {
54
+ flexDirection: "var(--flex-dir)",
55
+ alignItems: "stretch"
56
+ },
57
+ medium: {
58
+ flexDirection: "var(--flex-dir-tablet)",
59
+ alignItems: "stretch"
60
+ }
61
+ },
62
+ column: {
63
+ small: {
64
+ width: "var(--column-width) !important",
65
+ marginLeft: "var(--column-margin-left) !important"
66
+ },
67
+ medium: {
68
+ width: "var(--column-width-tablet) !important",
69
+ marginLeft: "var(--column-margin-left-tablet) !important"
70
+ }
71
+ }
72
+ };
73
+ }
74
+ function columnsStyles() {
75
+ return `
76
+ @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
77
+ .${props.builderBlock.id}-breakpoints {
78
+ ${convertStyleMapToCSS(columnStyleObjects().columns.medium)}
79
+ }
80
+
81
+ .${props.builderBlock.id}-breakpoints > .builder-column {
82
+ ${convertStyleMapToCSS(columnStyleObjects().column.medium)}
83
+ }
84
+ }
85
+
86
+ @media (max-width: ${getWidthForBreakpointSize("small")}px) {
87
+ .${props.builderBlock.id}-breakpoints {
88
+ ${convertStyleMapToCSS(columnStyleObjects().columns.small)}
89
+ }
90
+
91
+ .${props.builderBlock.id}-breakpoints > .builder-column {
92
+ ${convertStyleMapToCSS(columnStyleObjects().column.small)}
93
+ }
94
+ },
95
+ `;
96
+ }
97
+ function reactNativeColumnsStyles() {
98
+ return this.columnStyleObjects.columns.small;
99
+ }
100
+ function reactNativeColumnStyles() {
101
+ return this.columnStyleObjects.column.small;
102
+ }
103
+ return <div class={`builder-columns ${props.builderBlock.id}-breakpoints` + " " + css({
43
104
  display: "flex",
44
- alignItems: "stretch",
45
- lineHeight: "normal",
46
- "@media (max-width: 991px)": {
47
- flexDirection: "var(--flex-dir-tablet)"
48
- },
49
- "@media (max-width: 639px)": {
50
- flexDirection: "var(--flex-dir)"
51
- }
52
- })} style={columnsCssVars()}>
105
+ lineHeight: "normal"
106
+ })} style={{
107
+ ...(TARGET === "reactNative" ? reactNativeColumnsStyles() : {}),
108
+ ...columnsCssVars()
109
+ }}>
110
+ <Show when={TARGET !== "reactNative"}>
111
+ <RenderInlinedStyles styles={columnsStyles()}></RenderInlinedStyles>
112
+ </Show>
53
113
  <For each={props.columns}>
54
114
  {(column, _index) => {
55
115
  const index = _index();
56
116
  return <div class={"builder-column " + css({
57
117
  display: "flex",
58
118
  flexDirection: "column",
59
- alignItems: "stretch",
60
- "@media (max-width: 991px)": {
61
- width: "var(--column-width-tablet) !important",
62
- marginLeft: "var(--column-margin-left-tablet) !important"
63
- },
64
- "@media (max-width: 639px)": {
65
- width: "var(--column-width) !important",
66
- marginLeft: "var(--column-margin-left) !important"
67
- }
119
+ alignItems: "stretch"
68
120
  })} style={{
69
121
  width: getColumnCssWidth(index),
70
122
  "margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
123
+ ...(TARGET === "reactNative" ? reactNativeColumnStyles() : {}),
71
124
  ...columnCssVars()
72
125
  }} key={index}>
73
126
  <RenderBlocks blocks={column.blocks} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id} styleProp={{
@@ -1,7 +1,16 @@
1
1
  function SectionComponent(props) {
2
- return <section {...props.attributes} style={props.maxWidth && typeof props.maxWidth === "number" ? {
3
- "max-width": props.maxWidth
4
- } : undefined}>
2
+ return <section {...props.attributes} style={{
3
+ width: "100%",
4
+ "align-self": "stretch",
5
+ "flex-grow": "1",
6
+ "box-sizing": "border-box",
7
+ "max-width": `${props.maxWidth && typeof props.maxWidth === "number" ? props.maxWidth : 1200}px`,
8
+ display: "flex",
9
+ "flex-direction": "column",
10
+ "align-items": "stretch",
11
+ "margin-left": "auto",
12
+ "margin-right": "auto"
13
+ }}>
5
14
  {props.children}
6
15
  </section>;
7
16
  }
@@ -2,9 +2,12 @@ import { useContext, on, createEffect, createSignal } from "solid-js";
2
2
  import RenderContent from "../../components/render-content/render-content.jsx";
3
3
  import BuilderContext from "../../context/builder.context.js";
4
4
  import { getContent } from "../../functions/get-content/index.js";
5
+ import { TARGET } from "../../constants/target";
5
6
  function Symbol(props) {
6
- const [className, setClassName] = createSignal("builder-symbol");
7
7
  const [fetchedContent, setFetchedContent] = createSignal(null);
8
+ function className() {
9
+ return [...(TARGET === "vue2" || TARGET === "vue3" ? Object.keys(props.attributes.class) : [props.attributes.class]), "builder-symbol", props.symbol?.inline ? "builder-inline-symbol" : undefined, props.symbol?.dynamic || props.dynamic ? "builder-dynamic-symbol" : undefined].filter(Boolean).join(" ");
10
+ }
8
11
  function contentToUse() {
9
12
  return props.symbol?.content || fetchedContent();
10
13
  }
@@ -55,12 +55,14 @@ function RenderBlock(props) {
55
55
  });
56
56
  }
57
57
  function attributes() {
58
+ const blockProperties = getBlockProperties(useBlock());
58
59
  return {
59
- ...getBlockProperties(useBlock()),
60
+ ...blockProperties,
60
61
  ...(TARGET === "reactNative" ? {
61
62
  style: getReactNativeBlockStyles({
62
63
  block: useBlock(),
63
- context: props.context
64
+ context: props.context,
65
+ blockStyles: blockProperties.style
64
66
  })
65
67
  } : {})
66
68
  };
@@ -83,7 +85,8 @@ function RenderBlock(props) {
83
85
  ...attributes(),
84
86
  ...actions()
85
87
  }
86
- })
88
+ }),
89
+ customBreakpoints: childrenContext()?.content?.meta?.breakpoints
87
90
  },
88
91
  context: childrenContext()
89
92
  };
@@ -148,7 +151,8 @@ function RenderBlock(props) {
148
151
  }
149
152
  const styles = getReactNativeBlockStyles({
150
153
  block: useBlock(),
151
- context: props.context
154
+ context: props.context,
155
+ blockStyles: attributes().style
152
156
  });
153
157
  return extractTextStyles(styles);
154
158
  }
@@ -19,6 +19,7 @@ function RenderContent(props) {
19
19
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
20
20
  const [overrideContent, setOverrideContent] = createSignal(null);
21
21
  const [update, setUpdate] = createSignal(0);
22
+ const [useBreakpoints, setUseBreakpoints] = createSignal(null);
22
23
  const [overrideState, setOverrideState] = createSignal({});
23
24
  function canTrackToUse() {
24
25
  return props.canTrack || true;
@@ -56,6 +57,20 @@ function RenderContent(props) {
56
57
  } = event;
57
58
  if (data) {
58
59
  switch (data.type) {
60
+ case "builder.configureSdk":
61
+ {
62
+ const messageContent = data.data;
63
+ const {
64
+ breakpoints,
65
+ contentId
66
+ } = messageContent;
67
+ if (!contentId || contentId !== useContent?.id) {
68
+ return;
69
+ }
70
+ setUseBreakpoints(breakpoints);
71
+ setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
72
+ break;
73
+ }
59
74
  case "builder.contentUpdate":
60
75
  {
61
76
  const messageContent = data.data;
@@ -162,12 +177,17 @@ function RenderContent(props) {
162
177
  ...props.content?.data,
163
178
  ...props.data,
164
179
  ...overrideContent()?.data
180
+ },
181
+ meta: {
182
+ ...props.content?.meta,
183
+ ...overrideContent()?.meta,
184
+ breakpoints: useBreakpoints() || overrideContent()?.meta?.breakpoints || props.content?.meta?.breakpoints
165
185
  }
166
186
  };
167
187
  return mergedContent;
168
188
  };
169
189
  const [useContent, setUseContent] = createStore(updateUseContent());
170
- createEffect(on(() => [overrideContent(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
190
+ createEffect(on(() => [overrideContent(), useBreakpoints(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
171
191
  let elementRef;
172
192
  onMount(() => {
173
193
  if (!props.apiKey) {
@@ -17,12 +17,33 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ import { TARGET } from "../constants/target.js";
21
+ import { convertStyleMapToCSSArray } from "../helpers/css.js";
22
+ import { transformBlockProperties } from "./transform-block-properties.js";
20
23
  function getBlockProperties(block) {
21
24
  var _a;
22
- return __spreadProps(__spreadValues({}, block.properties), {
25
+ const properties = __spreadProps(__spreadValues({}, block.properties), {
23
26
  "builder-id": block.id,
27
+ style: getStyleAttribute(block.style),
24
28
  class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
25
29
  });
30
+ return transformBlockProperties(properties);
31
+ }
32
+ function getStyleAttribute(style) {
33
+ if (!style) {
34
+ return void 0;
35
+ }
36
+ switch (TARGET) {
37
+ case "svelte":
38
+ case "vue2":
39
+ case "vue3":
40
+ case "solid":
41
+ return convertStyleMapToCSSArray(style).join(" ");
42
+ case "qwik":
43
+ case "reactNative":
44
+ case "react":
45
+ return style;
46
+ }
26
47
  }
27
48
  export {
28
49
  getBlockProperties
@@ -17,13 +17,14 @@ var __spreadValues = (a, b) => {
17
17
  import { sanitizeReactNativeBlockStyles } from "./sanitize-react-native-block-styles.js";
18
18
  function getReactNativeBlockStyles({
19
19
  block,
20
- context
20
+ context,
21
+ blockStyles
21
22
  }) {
22
23
  const responsiveStyles = block.responsiveStyles;
23
24
  if (!responsiveStyles) {
24
25
  return {};
25
26
  }
26
- const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {});
27
+ const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {}), blockStyles);
27
28
  const newStyles = sanitizeReactNativeBlockStyles(styles);
28
29
  return newStyles;
29
30
  }
@@ -0,0 +1,6 @@
1
+ function transformBlockProperties(properties) {
2
+ return properties;
3
+ }
4
+ export {
5
+ transformBlockProperties
6
+ };
@@ -1,19 +1,23 @@
1
1
  import { camelToKebabCase } from "../functions/camel-to-kebab-case.js";
2
- const convertStyleMaptoCSS = (style) => {
2
+ import { checkIsDefined } from "./nullable.js";
3
+ const convertStyleMapToCSSArray = (style) => {
3
4
  const cssProps = Object.entries(style).map(([key, value]) => {
4
5
  if (typeof value === "string") {
5
6
  return `${camelToKebabCase(key)}: ${value};`;
7
+ } else {
8
+ return void 0;
6
9
  }
7
10
  });
8
- return cssProps.join("\n");
11
+ return cssProps.filter(checkIsDefined);
9
12
  };
13
+ const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
10
14
  const createCssClass = ({
11
15
  mediaQuery,
12
16
  className,
13
17
  styles
14
18
  }) => {
15
19
  const cssClass = `.${className} {
16
- ${convertStyleMaptoCSS(styles)}
20
+ ${convertStyleMapToCSS(styles)}
17
21
  }`;
18
22
  if (mediaQuery) {
19
23
  return `${mediaQuery} {
@@ -24,5 +28,7 @@ const createCssClass = ({
24
28
  }
25
29
  };
26
30
  export {
31
+ convertStyleMapToCSS,
32
+ convertStyleMapToCSSArray,
27
33
  createCssClass
28
34
  };