@builder.io/sdk-solid 0.0.18 → 0.0.20

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.18",
3
+ "version": "0.0.20",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -81,8 +81,8 @@ function Columns(props) {
81
81
  "margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
82
82
  ...columnCssVars()
83
83
  }} key={index}>
84
- <RenderBlocks blocks={markMutable(column.blocks)} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id} style={{
85
- "flex-grow": "1"
84
+ <RenderBlocks blocks={markMutable(column.blocks)} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id} styleProp={{
85
+ flexGrow: "1"
86
86
  }}></RenderBlocks>
87
87
  </div>;
88
88
  }}
@@ -120,9 +120,9 @@ function FormComponent(props) {
120
120
 
121
121
  setFormState("sending");
122
122
  const formUrl = `${builder.env === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
123
- fetch(props.sendSubmissionsTo === "email" ? formUrl : props.action,
123
+ fetch(props.sendSubmissionsTo === "email" ? formUrl : props.action
124
124
  /* TODO: throw error if no action URL */
125
- {
125
+ , {
126
126
  body,
127
127
  headers,
128
128
  method: props.method || "post"
@@ -58,8 +58,8 @@ function Image(props) {
58
58
  pointerEvents: "none",
59
59
  fontSize: "0"
60
60
  })} style={{
61
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
- "padding-top": props.aspectRatio * 100 + "%"
61
+ "padding-top": // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
62
+ props.aspectRatio * 100 + "%"
63
63
  }}></div>
64
64
  </Show>
65
65
  <Show when={props.builderBlock?.children?.length && props.fitContent}>
@@ -18,7 +18,13 @@ function Video(props) {
18
18
  };
19
19
  }
20
20
 
21
- return <video {...videoProps()} style={{
21
+ function spreadProps() {
22
+ return { ...props.attributes,
23
+ ...videoProps()
24
+ };
25
+ }
26
+
27
+ return <video {...spreadProps()} style={{
22
28
  width: "100%",
23
29
  height: "100%",
24
30
  ...props.attributes?.style,
@@ -3,7 +3,6 @@ import { Dynamic } from "solid-js/web";
3
3
  import { getBlockActions } from "../../functions/get-block-actions.js";
4
4
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
5
5
  import { getBlockProperties } from "../../functions/get-block-properties.js";
6
- import { getBlockStyles } from "../../functions/get-block-styles.js";
7
6
  import { getBlockTag } from "../../functions/get-block-tag.js";
8
7
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
9
8
  import { evaluate } from "../../functions/evaluate.js";
@@ -14,6 +13,7 @@ import { TARGET } from "../../constants/target.js";
14
13
  import { extractTextStyles } from "../../functions/extract-text-styles.js";
15
14
  import RenderComponentWithContext from "./render-component-with-context.jsx";
16
15
  import RenderComponent from "./render-component.jsx";
16
+ import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
17
17
 
18
18
  function RenderBlock(props) {
19
19
  function component() {
@@ -61,10 +61,12 @@ function RenderBlock(props) {
61
61
  state: props.context.state,
62
62
  context: props.context.context
63
63
  }),
64
- style: getBlockStyles({
65
- block: useBlock(),
66
- context: props.context
67
- })
64
+ ...(TARGET === "reactNative" ? {
65
+ style: getReactNativeBlockStyles({
66
+ block: useBlock(),
67
+ context: props.context
68
+ })
69
+ } : {})
68
70
  };
69
71
  }
70
72
 
@@ -154,7 +156,7 @@ function RenderBlock(props) {
154
156
  return {};
155
157
  }
156
158
 
157
- const styles = getBlockStyles({
159
+ const styles = getReactNativeBlockStyles({
158
160
  block: useBlock(),
159
161
  context: props.context
160
162
  });
@@ -187,18 +189,7 @@ function RenderBlock(props) {
187
189
  <Show when={isEmptyHtmlElement(tagName())}>
188
190
  <Dynamic {...attributes()} component={tagName()}></Dynamic>
189
191
  </Show>
190
- <Show when={!isEmptyHtmlElement(tagName()) && TARGET === "vue2" && repeatItemData()}>
191
- <div class="vue2-root-element-workaround">
192
- <For each={repeatItemData()}>
193
- {(data, _index) => {
194
- const index = _index();
195
-
196
- return <RenderRepeatedBlock key={index} repeatContext={data.context} block={data.block}></RenderRepeatedBlock>;
197
- }}
198
- </For>
199
- </div>
200
- </Show>
201
- <Show when={!isEmptyHtmlElement(tagName()) && TARGET !== "vue2" && repeatItemData()}>
192
+ <Show when={!isEmptyHtmlElement(tagName()) && repeatItemData()}>
202
193
  <For each={repeatItemData()}>
203
194
  {(data, _index) => {
204
195
  const index = _index();
@@ -29,7 +29,7 @@ function RenderComponentWithContext(props) {
29
29
  }
30
30
 
31
31
  }} component={BuilderContext.Provider}>
32
- <RenderComponent {...props}></RenderComponent>
32
+ <RenderComponent componentRef={props.componentRef} componentOptions={props.componentOptions} blockChildren={props.blockChildren} context={props.context}></RenderComponent>
33
33
  </Dynamic>;
34
34
  }
35
35
 
@@ -41,7 +41,7 @@ function RenderBlocks(props) {
41
41
  alignItems: "stretch"
42
42
  })} builder-path={props.path} builder-parent-id={props.parent} dataSet={{
43
43
  class: className()
44
- }} style={props.style} onClick={event => onClick()} onMouseEnter={event => onMouseEnter()}>
44
+ }} style={props.styleProp} onClick={event => onClick()} onMouseEnter={event => onMouseEnter()}>
45
45
  <Show when={props.blocks}>
46
46
  <For each={props.blocks}>
47
47
  {(block, _index) => {
@@ -11,7 +11,7 @@ import { isBrowser } from "../../functions/is-browser.js";
11
11
  import { isEditing } from "../../functions/is-editing.js";
12
12
  import { isPreviewing } from "../../functions/is-previewing.js";
13
13
  import { components, createRegisterComponentMessage } from "../../functions/register-component.js";
14
- import { track } from "../../functions/track.js";
14
+ import { _track } from "../../functions/track.js";
15
15
  import RenderBlocks from "../render-blocks.jsx";
16
16
  import RenderContentStyles from "./components/render-styles.jsx";
17
17
  import { registerInsertMenu, setupBrowserForEditing } from "../../scripts/init-editing.js";
@@ -100,11 +100,15 @@ function RenderContent(props) {
100
100
 
101
101
  function onClick(_event) {
102
102
  if (useContent) {
103
- track({
103
+ const variationId = useContent?.testVariationId;
104
+ const contentId = useContent?.id;
105
+
106
+ _track({
104
107
  type: "click",
105
108
  canTrack: canTrackToUse(),
106
- contentId: useContent?.id,
107
- orgId: props.apiKey
109
+ contentId,
110
+ apiKey: props.apiKey,
111
+ variationId: variationId !== contentId ? variationId : undefined
108
112
  });
109
113
  }
110
114
  }
@@ -195,11 +199,15 @@ function RenderContent(props) {
195
199
  }
196
200
 
197
201
  if (useContent) {
198
- track({
202
+ const variationId = useContent?.testVariationId;
203
+ const contentId = useContent?.id;
204
+
205
+ _track({
199
206
  type: "impression",
200
207
  canTrack: canTrackToUse(),
201
- contentId: useContent?.id,
202
- orgId: props.apiKey
208
+ contentId,
209
+ apiKey: props.apiKey,
210
+ variationId: variationId !== contentId ? variationId : undefined
203
211
  });
204
212
  } // override normal content in preview mode
205
213
 
@@ -269,7 +277,7 @@ function RenderContent(props) {
269
277
 
270
278
  }} component={BuilderContext.Provider}>
271
279
  <Show when={useContent}>
272
- <div ref={elementRef} onClick={event => onClick(event)} builder-content-id={useContent?.id}>
280
+ <div ref={elementRef} onClick={event => onClick(event)} builder-content-id={useContent?.id} builder-model={props.model}>
273
281
  <Show when={shouldRenderContentStyles()}>
274
282
  <RenderContentStyles cssCode={useContent?.data?.cssCode} customFonts={useContent?.data?.customFonts}></RenderContentStyles>
275
283
  </Show>
@@ -0,0 +1,32 @@
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 { sanitizeReactNativeBlockStyles } from "./sanitize-react-native-block-styles.js";
18
+ function getReactNativeBlockStyles({
19
+ block,
20
+ context
21
+ }) {
22
+ const responsiveStyles = block.responsiveStyles;
23
+ if (!responsiveStyles) {
24
+ return {};
25
+ }
26
+ const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {});
27
+ const newStyles = sanitizeReactNativeBlockStyles(styles);
28
+ return newStyles;
29
+ }
30
+ export {
31
+ getReactNativeBlockStyles
32
+ };
@@ -0,0 +1,66 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
+ var __spreadValues = (a, b) => {
9
+ for (var prop in b || (b = {}))
10
+ if (__hasOwnProp.call(b, prop))
11
+ __defNormalProp(a, prop, b[prop]);
12
+ if (__getOwnPropSymbols)
13
+ for (var prop of __getOwnPropSymbols(b)) {
14
+ if (__propIsEnum.call(b, prop))
15
+ __defNormalProp(a, prop, b[prop]);
16
+ }
17
+ return a;
18
+ };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
+ const propertiesThatMustBeNumber = new Set(["lineHeight"]);
21
+ const displayValues = new Set(["flex", "none"]);
22
+ const SHOW_WARNINGS = false;
23
+ const normalizeNumber = (value) => {
24
+ if (Number.isNaN(value)) {
25
+ return void 0;
26
+ } else if (value < 0) {
27
+ return 0;
28
+ } else {
29
+ return value;
30
+ }
31
+ };
32
+ const sanitizeReactNativeBlockStyles = (styles) => {
33
+ return Object.keys(styles).reduce((acc, key) => {
34
+ const propertyValue = styles[key];
35
+ if (key === "display" && !displayValues.has(propertyValue)) {
36
+ if (SHOW_WARNINGS) {
37
+ console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
38
+ }
39
+ return acc;
40
+ }
41
+ if (propertiesThatMustBeNumber.has(key) && typeof propertyValue !== "number") {
42
+ if (SHOW_WARNINGS) {
43
+ console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
44
+ }
45
+ return acc;
46
+ }
47
+ if (typeof propertyValue === "string") {
48
+ const isPixelUnit = propertyValue.match(/^-?(\d*)(\.?)(\d*)*px$/);
49
+ if (isPixelUnit) {
50
+ const newValue = parseFloat(propertyValue);
51
+ const normalizedValue = normalizeNumber(newValue);
52
+ if (normalizedValue) {
53
+ return __spreadProps(__spreadValues({}, acc), { [key]: normalizedValue });
54
+ } else {
55
+ return acc;
56
+ }
57
+ } else if (propertyValue === "0") {
58
+ return __spreadProps(__spreadValues({}, acc), { [key]: 0 });
59
+ }
60
+ }
61
+ return __spreadProps(__spreadValues({}, acc), { [key]: propertyValue });
62
+ }, {});
63
+ };
64
+ export {
65
+ sanitizeReactNativeBlockStyles
66
+ };
@@ -71,23 +71,24 @@ const createEvent = (_a) => __async(void 0, null, function* () {
71
71
  var _b = _a, {
72
72
  type: eventType,
73
73
  canTrack,
74
- orgId,
75
- contentId
74
+ apiKey,
75
+ metadata
76
76
  } = _b, properties = __objRest(_b, [
77
77
  "type",
78
78
  "canTrack",
79
- "orgId",
80
- "contentId"
79
+ "apiKey",
80
+ "metadata"
81
81
  ]);
82
82
  return {
83
83
  type: eventType,
84
- data: __spreadProps(__spreadValues(__spreadValues({}, properties), yield getTrackingEventData({ canTrack })), {
85
- ownerId: orgId,
86
- contentId
84
+ data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, properties), {
85
+ metadata: JSON.stringify(metadata)
86
+ }), yield getTrackingEventData({ canTrack })), {
87
+ ownerId: apiKey
87
88
  })
88
89
  };
89
90
  });
90
- function track(eventProps) {
91
+ function _track(eventProps) {
91
92
  return __async(this, null, function* () {
92
93
  if (!eventProps.canTrack) {
93
94
  return;
@@ -112,6 +113,8 @@ function track(eventProps) {
112
113
  });
113
114
  });
114
115
  }
116
+ const track = (args) => _track(__spreadProps(__spreadValues({}, args), { canTrack: true }));
115
117
  export {
118
+ _track,
116
119
  track
117
120
  };
package/src/index.js CHANGED
@@ -8,3 +8,7 @@ export * from "./functions/register.js";
8
8
  export * from "./functions/set-editor-settings.js";
9
9
  export * from "./functions/get-content/index.js";
10
10
  export * from "./functions/get-builder-search-params/index.js";
11
+ import { track } from "./functions/track";
12
+ export {
13
+ track
14
+ };
@@ -26,7 +26,8 @@ const setupBrowserForEditing = () => {
26
26
  type: "builder.sdkInfo",
27
27
  data: {
28
28
  target: TARGET,
29
- supportsPatchUpdates: false
29
+ supportsPatchUpdates: false,
30
+ supportsAddBlockScoping: true
30
31
  }
31
32
  }, "*");
32
33
  window.addEventListener("message", ({ data }) => {
@@ -1,14 +0,0 @@
1
- const camelCaseToDashCase = (str = "") => str.replace(/[A-Z]/g, (match) => "-" + match.toLowerCase());
2
- const convertStyleObject = (obj) => {
3
- if (!obj) {
4
- return obj;
5
- }
6
- const newObj = {};
7
- for (const key in obj) {
8
- newObj[camelCaseToDashCase(key)] = obj[key];
9
- }
10
- return newObj;
11
- };
12
- export {
13
- convertStyleObject
14
- };
@@ -1,50 +0,0 @@
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 { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
18
- import { TARGET } from "../constants/target.js";
19
- import { convertStyleObject } from "./convert-style-object.js";
20
- import { sanitizeBlockStyles } from "./sanitize-styles.js";
21
- const getStyleForTarget = ({
22
- styles,
23
- context
24
- }) => {
25
- switch (TARGET) {
26
- case "reactNative": {
27
- return __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), styles.large ? convertStyleObject(styles.large) : {}), styles.medium ? convertStyleObject(styles.medium) : {}), styles.small ? convertStyleObject(styles.small) : {});
28
- }
29
- default:
30
- return __spreadValues(__spreadValues(__spreadValues({}, styles.large ? convertStyleObject(styles.large) : {}), styles.medium ? {
31
- [getMaxWidthQueryForSize("medium")]: convertStyleObject(styles.medium)
32
- } : {}), styles.small ? {
33
- [getMaxWidthQueryForSize("small")]: convertStyleObject(styles.small)
34
- } : {});
35
- }
36
- };
37
- function getBlockStyles({
38
- block,
39
- context
40
- }) {
41
- if (!block.responsiveStyles) {
42
- return {};
43
- }
44
- const styles = getStyleForTarget({ styles: block.responsiveStyles, context });
45
- const newStyles = sanitizeBlockStyles(styles);
46
- return newStyles;
47
- }
48
- export {
49
- getBlockStyles
50
- };
@@ -1,4 +0,0 @@
1
- const sanitizeBlockStyles = (styles) => styles;
2
- export {
3
- sanitizeBlockStyles
4
- };