@builder.io/sdk-svelte 0.0.1-30 → 0.0.1-33
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 +1 -1
- package/src/blocks/button/button.svelte +14 -5
- package/src/blocks/columns/columns.svelte +29 -6
- package/src/blocks/columns/component-info.js +3 -2
- package/src/blocks/custom-code/custom-code.svelte +11 -4
- package/src/blocks/embed/component-info.js +3 -2
- package/src/blocks/embed/embed.svelte +10 -4
- package/src/blocks/form/form.svelte +87 -40
- package/src/blocks/fragment/fragment.svelte +9 -1
- package/src/blocks/image/component-info.js +3 -2
- package/src/blocks/image/image.svelte +36 -15
- package/src/blocks/img/img.svelte +29 -7
- package/src/blocks/input/input.svelte +20 -8
- package/src/blocks/raw-text/raw-text.svelte +10 -3
- package/src/blocks/section/section.svelte +12 -3
- package/src/blocks/select/select.svelte +20 -7
- package/src/blocks/submit-button/submit-button.svelte +10 -3
- package/src/blocks/symbol/symbol.svelte +24 -4
- package/src/blocks/text/text.svelte +8 -2
- package/src/blocks/textarea/textarea.svelte +16 -6
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.svelte +39 -11
- package/src/components/render-block/block-styles.svelte +15 -12
- package/src/components/render-block/render-block.svelte +29 -25
- package/src/components/render-block/render-component.svelte +18 -8
- package/src/components/render-block/render-repeated-block.svelte +23 -5
- package/src/components/render-blocks.svelte +21 -8
- package/src/components/render-content/components/render-styles.svelte +19 -3
- package/src/components/render-content/render-content.svelte +82 -32
- package/src/components/render-inlined-styles.svelte +8 -2
- package/src/constants/builder-registered-components.js +12 -9
- package/src/functions/get-builder-search-params/index.js +1 -1
- package/src/functions/get-content/index.js +1 -1
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +10 -6
- package/src/functions/get-processed-block.test.js +1 -1
- package/src/functions/track.js +106 -13
- package/src/helpers/cookie.js +59 -0
- package/src/helpers/css.js +1 -1
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +26 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
|
@@ -24,9 +24,9 @@ function getFetch() {
|
|
|
24
24
|
const globalFetch = getGlobalThis().fetch;
|
|
25
25
|
if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
|
|
26
26
|
const nodeFetch = import("node-fetch").then((d) => d.default);
|
|
27
|
-
return nodeFetch;
|
|
27
|
+
return nodeFetch.default || nodeFetch;
|
|
28
28
|
}
|
|
29
|
-
return globalFetch;
|
|
29
|
+
return globalFetch.default || globalFetch;
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
export {
|
|
@@ -39,13 +39,17 @@ const evaluateBindings = ({
|
|
|
39
39
|
}
|
|
40
40
|
return copied;
|
|
41
41
|
};
|
|
42
|
-
function getProcessedBlock(
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
function getProcessedBlock({
|
|
43
|
+
block,
|
|
44
|
+
context,
|
|
45
|
+
shouldEvaluateBindings,
|
|
46
|
+
state
|
|
47
|
+
}) {
|
|
48
|
+
const transformedBlock = transformBlock(block);
|
|
49
|
+
if (shouldEvaluateBindings) {
|
|
50
|
+
return evaluateBindings({ block: transformedBlock, state, context });
|
|
47
51
|
} else {
|
|
48
|
-
return
|
|
52
|
+
return transformedBlock;
|
|
49
53
|
}
|
|
50
54
|
}
|
|
51
55
|
export {
|
|
@@ -21,7 +21,7 @@ test("Can process bindings", () => {
|
|
|
21
21
|
block,
|
|
22
22
|
context: {},
|
|
23
23
|
state: { test: "hello" },
|
|
24
|
-
|
|
24
|
+
shouldEvaluateBindings: true
|
|
25
25
|
});
|
|
26
26
|
expect(processed).not.toEqual(block);
|
|
27
27
|
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|
package/src/functions/track.js
CHANGED
|
@@ -1,20 +1,113 @@
|
|
|
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
|
+
};
|
|
32
|
+
var __async = (__this, __arguments, generator) => {
|
|
33
|
+
return new Promise((resolve, reject) => {
|
|
34
|
+
var fulfilled = (value) => {
|
|
35
|
+
try {
|
|
36
|
+
step(generator.next(value));
|
|
37
|
+
} catch (e) {
|
|
38
|
+
reject(e);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var rejected = (value) => {
|
|
42
|
+
try {
|
|
43
|
+
step(generator.throw(value));
|
|
44
|
+
} catch (e) {
|
|
45
|
+
reject(e);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
49
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
50
|
+
});
|
|
51
|
+
};
|
|
1
52
|
import { TARGET } from "../constants/target.js";
|
|
53
|
+
import { getSessionId } from "../helpers/sessionId.js";
|
|
54
|
+
import { getVisitorId } from "../helpers/visitorId.js";
|
|
2
55
|
import { isBrowser } from "./is-browser.js";
|
|
3
56
|
import { isEditing } from "./is-editing.js";
|
|
4
|
-
|
|
5
|
-
if (
|
|
6
|
-
return;
|
|
57
|
+
const getTrackingEventData = ({ canTrack }) => {
|
|
58
|
+
if (!canTrack) {
|
|
59
|
+
return { visitorId: void 0, sessionId: void 0 };
|
|
7
60
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
61
|
+
const sessionId = getSessionId({ canTrack });
|
|
62
|
+
const visitorId = getVisitorId({ canTrack });
|
|
63
|
+
return {
|
|
64
|
+
sessionId,
|
|
65
|
+
visitorId
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
const createEvent = (_a) => {
|
|
69
|
+
var _b = _a, {
|
|
70
|
+
type: eventType,
|
|
71
|
+
canTrack,
|
|
72
|
+
orgId,
|
|
73
|
+
contentId
|
|
74
|
+
} = _b, properties = __objRest(_b, [
|
|
75
|
+
"type",
|
|
76
|
+
"canTrack",
|
|
77
|
+
"orgId",
|
|
78
|
+
"contentId"
|
|
79
|
+
]);
|
|
80
|
+
return {
|
|
81
|
+
type: eventType,
|
|
82
|
+
data: __spreadProps(__spreadValues(__spreadValues({}, properties), getTrackingEventData({ canTrack })), {
|
|
83
|
+
ownerId: orgId,
|
|
84
|
+
contentId
|
|
85
|
+
})
|
|
86
|
+
};
|
|
87
|
+
};
|
|
88
|
+
function track(eventProps) {
|
|
89
|
+
return __async(this, null, function* () {
|
|
90
|
+
if (!eventProps.canTrack) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
if (isEditing()) {
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
if (!(isBrowser() || TARGET === "reactNative")) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
return fetch(`https://builder.io/api/v1/track`, {
|
|
100
|
+
method: "POST",
|
|
101
|
+
body: JSON.stringify({
|
|
102
|
+
events: [createEvent(eventProps)]
|
|
103
|
+
}),
|
|
104
|
+
headers: {
|
|
105
|
+
"content-type": "application/json"
|
|
106
|
+
},
|
|
107
|
+
mode: "cors"
|
|
108
|
+
}).catch((err) => {
|
|
109
|
+
console.error("Failed to track: ", err);
|
|
110
|
+
});
|
|
18
111
|
});
|
|
19
112
|
}
|
|
20
113
|
export {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { isBrowser } from "../functions/is-browser.js";
|
|
2
|
+
import { getTopLevelDomain } from "./url.js";
|
|
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
|
+
};
|
package/src/helpers/css.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { camelToKebabCase } from "../functions/camel-to-kebab-case";
|
|
1
|
+
import { camelToKebabCase } from "../functions/camel-to-kebab-case.js";
|
|
2
2
|
const convertStyleMaptoCSS = (style) => {
|
|
3
3
|
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
4
4
|
if (typeof value === "string") {
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isBrowser } from "../functions/is-browser.js";
|
|
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,26 @@
|
|
|
1
|
+
import { getCookie, setCookie } from "./cookie.js";
|
|
2
|
+
import { checkIsDefined } from "./nullable.js";
|
|
3
|
+
import { uuid } from "./uuid.js";
|
|
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,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.js";
|
|
2
|
+
import { checkIsDefined } from "./nullable.js";
|
|
3
|
+
import { uuid } from "./uuid.js";
|
|
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
|
+
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { TARGET } from "../constants/target.js";
|
|
2
2
|
import { isBrowser } from "../functions/is-browser.js";
|
|
3
|
-
import { isEditing } from "../functions/is-editing.js";
|
|
4
3
|
import { register } from "../functions/register.js";
|
|
5
4
|
const registerInsertMenu = () => {
|
|
6
5
|
register("insertMenu", {
|
|
@@ -74,7 +73,7 @@ const setupBrowserForEditing = () => {
|
|
|
74
73
|
});
|
|
75
74
|
}
|
|
76
75
|
};
|
|
77
|
-
|
|
78
|
-
registerInsertMenu
|
|
79
|
-
setupBrowserForEditing
|
|
80
|
-
}
|
|
76
|
+
export {
|
|
77
|
+
registerInsertMenu,
|
|
78
|
+
setupBrowserForEditing
|
|
79
|
+
};
|
|
File without changes
|