@builder.io/sdk-solid 0.0.22 → 0.0.24-0

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/README.md CHANGED
@@ -5,3 +5,7 @@ More info coming soon.
5
5
  ## Mitosis
6
6
 
7
7
  This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
8
+
9
+ ## Fetch
10
+
11
+ This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
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.24-0",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -14,7 +14,6 @@
14
14
  "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
15
15
  },
16
16
  "dependencies": {
17
- "node-fetch": "^2.6.7",
18
17
  "solid-styled-components": "^0.27.6"
19
18
  },
20
19
  "peerDependencies": {
@@ -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
  }
@@ -5,7 +5,7 @@ import { getDefaultRegisteredComponents } from "../../constants/builder-register
5
5
  import { TARGET } from "../../constants/target.js";
6
6
  import { evaluate } from "../../functions/evaluate.js";
7
7
  import { getContent } from "../../functions/get-content/index.js";
8
- import { getFetch } from "../../functions/get-fetch.js";
8
+ import { fetch } from "../../functions/get-fetch.js";
9
9
  import { isBrowser } from "../../functions/is-browser.js";
10
10
  import { isEditing } from "../../functions/is-editing.js";
11
11
  import { isPreviewing } from "../../functions/is-previewing.js";
@@ -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;
@@ -114,7 +129,7 @@ function RenderContent(props) {
114
129
  url,
115
130
  key
116
131
  }) {
117
- getFetch().then(fetch => fetch(url)).then(response => response.json()).then(json => {
132
+ fetch(url).then(response => response.json()).then(json => {
118
133
  const newOverrideState = {
119
134
  ...overrideState(),
120
135
  [key]: json
@@ -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
@@ -0,0 +1,55 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { flatten } from "../../helpers/flatten.js";
18
+ import {
19
+ getBuilderSearchParamsFromWindow,
20
+ normalizeSearchParams
21
+ } from "../get-builder-search-params/index.js";
22
+ const generateContentUrl = (options) => {
23
+ const {
24
+ limit = 30,
25
+ userAttributes,
26
+ query,
27
+ noTraverse = false,
28
+ model,
29
+ apiKey,
30
+ includeRefs = true,
31
+ locale
32
+ } = options;
33
+ if (!apiKey) {
34
+ throw new Error("Missing API key");
35
+ }
36
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
37
+ const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
38
+ const flattened = flatten(queryOptions);
39
+ for (const key in flattened) {
40
+ url.searchParams.set(key, String(flattened[key]));
41
+ }
42
+ if (userAttributes) {
43
+ url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
44
+ }
45
+ if (query) {
46
+ const flattened2 = flatten({ query });
47
+ for (const key in flattened2) {
48
+ url.searchParams.set(key, JSON.stringify(flattened2[key]));
49
+ }
50
+ }
51
+ return url;
52
+ };
53
+ export {
54
+ generateContentUrl
55
+ };
@@ -1,4 +1,4 @@
1
- import { generateContentUrl } from ".";
1
+ import { generateContentUrl } from "./generate-content-url";
2
2
  const testKey = "YJIGb4i01jvw0SRdL5Bt";
3
3
  const testModel = "page";
4
4
  const testId = "c1b81bab59704599b997574eb0736def";
@@ -37,54 +37,19 @@ var __async = (__this, __arguments, generator) => {
37
37
  step((generator = generator.apply(__this, __arguments)).next());
38
38
  });
39
39
  };
40
- import { flatten } from "../../helpers/flatten.js";
41
- import {
42
- getBuilderSearchParamsFromWindow,
43
- normalizeSearchParams
44
- } from "../get-builder-search-params/index.js";
45
- import { getFetch } from "../get-fetch.js";
40
+ import { fetch } from "../get-fetch.js";
46
41
  import { handleABTesting } from "./ab-testing.js";
42
+ import { generateContentUrl } from "./generate-content-url.js";
47
43
  function getContent(options) {
48
44
  return __async(this, null, function* () {
49
45
  return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
50
46
  });
51
47
  }
52
- const generateContentUrl = (options) => {
53
- const {
54
- limit = 30,
55
- userAttributes,
56
- query,
57
- noTraverse = false,
58
- model,
59
- apiKey,
60
- includeRefs = true,
61
- locale
62
- } = options;
63
- if (!apiKey) {
64
- throw new Error("Missing API key");
65
- }
66
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
67
- const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
68
- const flattened = flatten(queryOptions);
69
- for (const key in flattened) {
70
- url.searchParams.set(key, String(flattened[key]));
71
- }
72
- if (userAttributes) {
73
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
74
- }
75
- if (query) {
76
- const flattened2 = flatten({ query });
77
- for (const key in flattened2) {
78
- url.searchParams.set(key, JSON.stringify(flattened2[key]));
79
- }
80
- }
81
- return url;
82
- };
83
48
  function getAllContent(options) {
84
49
  return __async(this, null, function* () {
85
50
  const url = generateContentUrl(options);
86
- const fetch = yield getFetch();
87
- const content = yield fetch(url.href).then((res) => res.json());
51
+ const res = yield fetch(url.href);
52
+ const content = yield res.json();
88
53
  const canTrack = options.canTrack !== false;
89
54
  if (canTrack && Array.isArray(content.results)) {
90
55
  for (const item of content.results) {
@@ -95,7 +60,6 @@ function getAllContent(options) {
95
60
  });
96
61
  }
97
62
  export {
98
- generateContentUrl,
99
63
  getAllContent,
100
64
  getContent
101
65
  };
@@ -1,34 +1,14 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
1
  import { getGlobalThis } from "./get-global-this.js";
22
2
  function getFetch() {
23
- return __async(this, null, function* () {
24
- const globalFetch = getGlobalThis().fetch;
25
- if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
26
- const nodeFetch = import("node-fetch").then((d) => d.default);
27
- return nodeFetch.default || nodeFetch;
28
- }
29
- return globalFetch.default || globalFetch;
30
- });
3
+ const globalFetch = getGlobalThis().fetch;
4
+ if (typeof globalFetch === "undefined") {
5
+ console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
6
+ For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
7
+ throw new Error("Builder SDK could not find a global `fetch` function");
8
+ }
9
+ return globalFetch;
31
10
  }
11
+ const fetch = getFetch();
32
12
  export {
33
- getFetch
13
+ fetch
34
14
  };
@@ -11,7 +11,7 @@ function getGlobalThis() {
11
11
  if (typeof self !== "undefined") {
12
12
  return self;
13
13
  }
14
- return null;
14
+ return globalThis;
15
15
  }
16
16
  export {
17
17
  getGlobalThis
@@ -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
  };