@builder.io/sdk-solid 0.0.8-20 → 0.0.8-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.8-20",
3
+ "version": "0.0.8-23",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/solid-index.jsx",
@@ -1,8 +1,13 @@
1
1
  import { Show } from "solid-js";
2
+ import { css } from "solid-styled-components";
2
3
 
3
4
  function Button(props) {
4
5
  return <>
5
- <Show fallback={<span {...props.attributes}>{props.text}</span>} when={props.link}>
6
+ <Show fallback={<button class={css({
7
+ all: "unset"
8
+ })} {...props.attributes}>
9
+ {props.text}
10
+ </button>} when={props.link}>
6
11
  <a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
7
12
  {props.text}
8
13
  </a>
@@ -55,7 +55,7 @@ function Columns(props) {
55
55
  display: "flex",
56
56
  alignItems: "stretch",
57
57
  lineHeight: "normal",
58
- "@media (max-width: 999px)": {
58
+ "@media (max-width: 991px)": {
59
59
  flexDirection: "var(--flex-dir-tablet)"
60
60
  },
61
61
  "@media (max-width: 639px)": {
@@ -68,7 +68,7 @@ function Columns(props) {
68
68
 
69
69
  return <div class={"builder-column " + css({
70
70
  flexGrow: "1",
71
- "@media (max-width: 999px)": {
71
+ "@media (max-width: 991px)": {
72
72
  width: "var(--column-width-tablet) !important",
73
73
  marginLeft: "var(--column-margin-left-tablet) !important"
74
74
  },
@@ -81,7 +81,7 @@ function Columns(props) {
81
81
  "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
82
82
  ...state.columnCssVars
83
83
  }} key={index}>
84
- <RenderBlocks blocks={column.blocks}></RenderBlocks>
84
+ <RenderBlocks blocks={column.blocks} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id}></RenderBlocks>
85
85
  </div>;
86
86
  }}
87
87
  </For>
@@ -30,6 +30,11 @@ function RenderContent(props) {
30
30
 
31
31
  overrideContent: null,
32
32
  update: 0,
33
+
34
+ get canTrackToUse() {
35
+ return props.canTrack || true;
36
+ },
37
+
33
38
  overrideState: {},
34
39
 
35
40
  get contentState() {
@@ -102,6 +107,17 @@ function RenderContent(props) {
102
107
  return {};
103
108
  },
104
109
 
110
+ onClick(_event) {
111
+ if (state.useContent) {
112
+ track({
113
+ type: "click",
114
+ canTrack: state.canTrackToUse,
115
+ contentId: state.useContent.id,
116
+ orgId: props.apiKey
117
+ });
118
+ }
119
+ },
120
+
105
121
  evalExpression(expression) {
106
122
  return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
107
123
  code: group,
@@ -170,8 +186,11 @@ function RenderContent(props) {
170
186
  }
171
187
 
172
188
  if (state.useContent) {
173
- track("impression", {
174
- contentId: state.useContent.id
189
+ track({
190
+ type: "impression",
191
+ canTrack: state.canTrackToUse,
192
+ contentId: state.useContent.id,
193
+ orgId: props.apiKey
175
194
  });
176
195
  } // override normal content in preview mode
177
196
 
@@ -241,9 +260,7 @@ function RenderContent(props) {
241
260
 
242
261
  }} component={BuilderContext.Provider}>
243
262
  <Show when={state.useContent}>
244
- <div onClick={event => track("click", {
245
- contentId: state.useContent.id
246
- })} builder-content-id={state.useContent?.id}>
263
+ <div onClick={event => state.onClick(event)} builder-content-id={state.useContent?.id}>
247
264
  <Show when={state.shouldRenderContentStyles}>
248
265
  <RenderContentStyles cssCode={state.useContent?.data?.cssCode} customFonts={state.useContent?.data?.customFonts}></RenderContentStyles>
249
266
  </Show>
@@ -1,7 +1,74 @@
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
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
1
32
  import { TARGET } from "../constants/target.js";
33
+ import { getSessionId } from "../helpers/sessionId.js";
34
+ import { getVisitorId } from "../helpers/visitorId.js";
2
35
  import { isBrowser } from "./is-browser.js";
3
36
  import { isEditing } from "./is-editing.js";
4
- function track(event, properties) {
37
+ const getTrackingEventData = ({ canTrack }) => {
38
+ if (!canTrack) {
39
+ return { visitorId: void 0, sessionId: void 0 };
40
+ }
41
+ const sessionId = getSessionId({ canTrack });
42
+ const visitorId = getVisitorId({ canTrack });
43
+ return {
44
+ sessionId,
45
+ visitorId
46
+ };
47
+ };
48
+ const createEvent = (_a) => {
49
+ var _b = _a, {
50
+ type: eventType,
51
+ canTrack,
52
+ orgId,
53
+ contentId
54
+ } = _b, properties = __objRest(_b, [
55
+ "type",
56
+ "canTrack",
57
+ "orgId",
58
+ "contentId"
59
+ ]);
60
+ return {
61
+ type: eventType,
62
+ data: __spreadProps(__spreadValues(__spreadValues({}, properties), getTrackingEventData({ canTrack })), {
63
+ ownerId: orgId,
64
+ contentId
65
+ })
66
+ };
67
+ };
68
+ function track(eventProps) {
69
+ if (!eventProps.canTrack) {
70
+ return;
71
+ }
5
72
  if (isEditing()) {
6
73
  return;
7
74
  }
@@ -10,7 +77,9 @@ function track(event, properties) {
10
77
  }
11
78
  return fetch(`https://builder.io/api/v1/track`, {
12
79
  method: "POST",
13
- body: JSON.stringify({ events: [{ type: event, data: properties }] }),
80
+ body: JSON.stringify({
81
+ events: [createEvent(eventProps)]
82
+ }),
14
83
  headers: {
15
84
  "content-type": "application/json"
16
85
  },
@@ -0,0 +1,59 @@
1
+ import { isBrowser } from "../functions/is-browser";
2
+ import { getTopLevelDomain } from "./url";
3
+ const getCookie = ({
4
+ name,
5
+ canTrack
6
+ }) => {
7
+ var _a;
8
+ try {
9
+ if (!canTrack) {
10
+ return void 0;
11
+ }
12
+ return (_a = document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))) == null ? void 0 : _a.split("=")[1];
13
+ } catch (err) {
14
+ console.debug("[COOKIE] GET error: ", err);
15
+ }
16
+ };
17
+ const stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).join("; ");
18
+ const SECURE_CONFIG = [
19
+ ["secure", ""],
20
+ ["SameSite", "None"]
21
+ ];
22
+ const createCookieString = ({
23
+ name,
24
+ value,
25
+ expires
26
+ }) => {
27
+ const secure = isBrowser() ? location.protocol === "https:" : true;
28
+ const secureObj = secure ? SECURE_CONFIG : [[]];
29
+ const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
30
+ const cookieValue = [
31
+ [name, value],
32
+ ...expiresObj,
33
+ ["path", "/"],
34
+ ["domain", getTopLevelDomain(window.location.hostname)],
35
+ ...secureObj
36
+ ];
37
+ const cookie = stringifyCookie(cookieValue);
38
+ return cookie;
39
+ };
40
+ const setCookie = ({
41
+ name,
42
+ value,
43
+ expires,
44
+ canTrack
45
+ }) => {
46
+ try {
47
+ if (!canTrack) {
48
+ return void 0;
49
+ }
50
+ const cookie = createCookieString({ name, value, expires });
51
+ document.cookie = cookie;
52
+ } catch (err) {
53
+ console.warn("[COOKIE] SET error: ", err);
54
+ }
55
+ };
56
+ export {
57
+ getCookie,
58
+ setCookie
59
+ };
@@ -0,0 +1,34 @@
1
+ import { isBrowser } from "../functions/is-browser";
2
+ const getLocalStorage = () => isBrowser() && typeof localStorage !== "undefined" ? localStorage : void 0;
3
+ const getLocalStorageItem = ({
4
+ key,
5
+ canTrack
6
+ }) => {
7
+ var _a;
8
+ try {
9
+ if (canTrack) {
10
+ return (_a = getLocalStorage()) == null ? void 0 : _a.getItem(key);
11
+ }
12
+ return void 0;
13
+ } catch (err) {
14
+ console.debug("[LocalStorage] GET error: ", err);
15
+ }
16
+ };
17
+ const setLocalStorageItem = ({
18
+ key,
19
+ canTrack,
20
+ value
21
+ }) => {
22
+ var _a;
23
+ try {
24
+ if (canTrack) {
25
+ (_a = getLocalStorage()) == null ? void 0 : _a.setItem(key, value);
26
+ }
27
+ } catch (err) {
28
+ console.debug("[LocalStorage] SET error: ", err);
29
+ }
30
+ };
31
+ export {
32
+ getLocalStorageItem,
33
+ setLocalStorageItem
34
+ };
@@ -0,0 +1,4 @@
1
+ const checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
2
+ export {
3
+ checkIsDefined
4
+ };
@@ -0,0 +1,26 @@
1
+ import { getCookie, setCookie } from "./cookie";
2
+ import { checkIsDefined } from "./nullable";
3
+ import { uuid } from "./uuid";
4
+ const SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
5
+ const getSessionId = ({ canTrack }) => {
6
+ if (!canTrack) {
7
+ return void 0;
8
+ }
9
+ const sessionId = getCookie({ name: SESSION_LOCAL_STORAGE_KEY, canTrack });
10
+ if (checkIsDefined(sessionId)) {
11
+ return sessionId;
12
+ } else {
13
+ const newSessionId = createSessionId();
14
+ setSessionId({ id: newSessionId, canTrack });
15
+ }
16
+ };
17
+ const createSessionId = () => uuid();
18
+ const setSessionId = ({
19
+ id,
20
+ canTrack
21
+ }) => setCookie({ name: SESSION_LOCAL_STORAGE_KEY, value: id, canTrack });
22
+ export {
23
+ createSessionId,
24
+ getSessionId,
25
+ setSessionId
26
+ };
@@ -0,0 +1,5 @@
1
+ const MINUTE_TO_MILLESECONDS_MULTIPLIER = 6e4;
2
+ const getCurrentDatePlusMinutes = (minutes = 30) => new Date(Date.now() + minutes * MINUTE_TO_MILLESECONDS_MULTIPLIER);
3
+ export {
4
+ getCurrentDatePlusMinutes
5
+ };
@@ -0,0 +1,10 @@
1
+ const getTopLevelDomain = (host) => {
2
+ const parts = host.split(".");
3
+ if (parts.length > 2) {
4
+ return parts.slice(1).join(".");
5
+ }
6
+ return host;
7
+ };
8
+ export {
9
+ getTopLevelDomain
10
+ };
@@ -0,0 +1,15 @@
1
+ import { getTopLevelDomain } from "./url.js";
2
+ describe("getTopLevelDomain", () => {
3
+ test("handles root domain", () => {
4
+ const output = getTopLevelDomain("example.com");
5
+ expect(output).toBe("example.com");
6
+ });
7
+ test("handles subdomain", () => {
8
+ const output = getTopLevelDomain("wwww.example.com");
9
+ expect(output).toBe("example.com");
10
+ });
11
+ test("handles subdomain with long suffix", () => {
12
+ const output = getTopLevelDomain("www.example.co.uk");
13
+ expect(output).toBe("example.co.uk");
14
+ });
15
+ });
@@ -0,0 +1,13 @@
1
+ function uuidv4() {
2
+ return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
3
+ const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
4
+ return v.toString(16);
5
+ });
6
+ }
7
+ function uuid() {
8
+ return uuidv4().replace(/-/g, "");
9
+ }
10
+ export {
11
+ uuid,
12
+ uuidv4
13
+ };
@@ -0,0 +1,33 @@
1
+ import { getLocalStorageItem, setLocalStorageItem } from "./localStorage";
2
+ import { checkIsDefined } from "./nullable";
3
+ import { uuid } from "./uuid";
4
+ const VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
5
+ const getVisitorId = ({ canTrack }) => {
6
+ if (!canTrack) {
7
+ return void 0;
8
+ }
9
+ const visitorId = getLocalStorageItem({
10
+ key: VISITOR_LOCAL_STORAGE_KEY,
11
+ canTrack
12
+ });
13
+ if (checkIsDefined(visitorId)) {
14
+ return visitorId;
15
+ } else {
16
+ const newVisitorId = createVisitorId();
17
+ setVisitorId({ id: newVisitorId, canTrack });
18
+ }
19
+ };
20
+ const createVisitorId = () => uuid();
21
+ const setVisitorId = ({
22
+ id,
23
+ canTrack
24
+ }) => setLocalStorageItem({
25
+ key: VISITOR_LOCAL_STORAGE_KEY,
26
+ value: id,
27
+ canTrack
28
+ });
29
+ export {
30
+ createVisitorId,
31
+ getVisitorId,
32
+ setVisitorId
33
+ };
File without changes