@builder.io/sdk-svelte 0.0.1-3 → 0.0.1-32
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 +19 -0
- package/package.json +8 -1
- package/src/blocks/button/button.svelte +35 -48
- package/src/blocks/columns/columns.svelte +137 -103
- package/src/blocks/columns/component-info.js +26 -1
- package/src/blocks/custom-code/custom-code.svelte +58 -53
- package/src/blocks/embed/component-info.js +21 -1
- package/src/blocks/embed/embed.svelte +45 -57
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/form.svelte +313 -296
- package/src/blocks/fragment/fragment.svelte +9 -25
- package/src/blocks/image/component-info.js +48 -1
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.svelte +146 -117
- package/src/blocks/img/img.svelte +48 -36
- package/src/blocks/input/input.svelte +30 -31
- package/src/blocks/raw-text/raw-text.svelte +12 -26
- package/src/blocks/section/section.svelte +30 -36
- package/src/blocks/select/select.svelte +30 -37
- package/src/blocks/submit-button/submit-button.svelte +12 -30
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.svelte +88 -53
- package/src/blocks/text/text.svelte +8 -25
- package/src/blocks/textarea/textarea.svelte +16 -29
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/video.svelte +88 -41
- package/src/components/render-block/block-styles.svelte +58 -51
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.svelte +204 -160
- package/src/components/render-block/render-component.svelte +30 -0
- package/src/components/render-block/render-repeated-block.svelte +45 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.svelte +88 -80
- package/src/components/render-content/components/render-styles.svelte +59 -63
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.svelte +316 -207
- package/src/components/render-inlined-styles.svelte +26 -48
- package/src/constants/builder-registered-components.js +51 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +7 -1
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +7 -4
- package/src/functions/get-builder-search-params/index.js +12 -1
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/get-content/index.js +16 -58
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +2 -2
- package/src/functions/get-processed-block.js +19 -8
- package/src/functions/get-processed-block.test.js +2 -1
- package/src/functions/register-component.js +45 -26
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/track.js +71 -2
- package/src/helpers/cookie.js +59 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- 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/index-helpers/blocks-exports.js +10 -8
- package/src/scripts/init-editing.js +4 -5
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/video/index.js +0 -7
- package/src/components/error-boundary.svelte +0 -26
- package/src/functions/macro-eval.js +0 -5
- package/src/functions/previewing-model-name.js +0 -11
|
@@ -1,10 +1,4 @@
|
|
|
1
|
-
const
|
|
2
|
-
const sizes = {
|
|
3
|
-
xsmall: {
|
|
4
|
-
min: 0,
|
|
5
|
-
default: 0,
|
|
6
|
-
max: 0
|
|
7
|
-
},
|
|
1
|
+
const SIZES = {
|
|
8
2
|
small: {
|
|
9
3
|
min: 320,
|
|
10
4
|
default: 321,
|
|
@@ -19,21 +13,9 @@ const sizes = {
|
|
|
19
13
|
min: 990,
|
|
20
14
|
default: 991,
|
|
21
15
|
max: 1200
|
|
22
|
-
},
|
|
23
|
-
getWidthForSize(size) {
|
|
24
|
-
return this[size].default;
|
|
25
|
-
},
|
|
26
|
-
getSizeForWidth(width) {
|
|
27
|
-
for (const size of sizeNames) {
|
|
28
|
-
const value = this[size];
|
|
29
|
-
if (width <= value.max) {
|
|
30
|
-
return size;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
return "large";
|
|
34
16
|
}
|
|
35
17
|
};
|
|
18
|
+
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
|
|
36
19
|
export {
|
|
37
|
-
|
|
38
|
-
sizes
|
|
20
|
+
getMaxWidthQueryForSize
|
|
39
21
|
};
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,9 +16,12 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
function getBlockComponentOptions(block) {
|
|
18
21
|
var _a;
|
|
19
|
-
return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options)
|
|
22
|
+
return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
|
|
23
|
+
builderBlock: block
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
export {
|
|
22
27
|
getBlockComponentOptions
|
|
@@ -14,16 +14,19 @@ var __spreadValues = (a, b) => {
|
|
|
14
14
|
}
|
|
15
15
|
return a;
|
|
16
16
|
};
|
|
17
|
-
import {
|
|
17
|
+
import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
|
|
18
|
+
import { convertStyleObject } from "./convert-style-object.js";
|
|
19
|
+
import { sanitizeBlockStyles } from "./sanitize-styles.js";
|
|
18
20
|
function getBlockStyles(block) {
|
|
19
21
|
var _a, _b, _c, _d, _e;
|
|
20
|
-
const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
|
|
22
|
+
const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
|
|
21
23
|
if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
|
|
22
|
-
styles[
|
|
24
|
+
styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
|
|
23
25
|
}
|
|
24
26
|
if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
|
|
25
|
-
styles[
|
|
27
|
+
styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
|
|
26
28
|
}
|
|
29
|
+
sanitizeBlockStyles(styles);
|
|
27
30
|
return styles;
|
|
28
31
|
}
|
|
29
32
|
export {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isBrowser } from "../is-browser";
|
|
1
2
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
2
3
|
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
3
4
|
const options = {};
|
|
@@ -16,7 +17,17 @@ const getBuilderSearchParams = (options) => {
|
|
|
16
17
|
});
|
|
17
18
|
return newOptions;
|
|
18
19
|
};
|
|
20
|
+
const getBuilderSearchParamsFromWindow = () => {
|
|
21
|
+
if (!isBrowser()) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
25
|
+
return getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams));
|
|
26
|
+
};
|
|
27
|
+
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
19
28
|
export {
|
|
20
29
|
convertSearchParamsToQueryObject,
|
|
21
|
-
getBuilderSearchParams
|
|
30
|
+
getBuilderSearchParams,
|
|
31
|
+
getBuilderSearchParamsFromWindow,
|
|
32
|
+
normalizeSearchParams
|
|
22
33
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const handleABTesting = (item, testGroups) => {
|
|
2
|
+
if (item.variations && Object.keys(item.variations).length) {
|
|
3
|
+
const testGroup = item.id ? testGroups[item.id] : void 0;
|
|
4
|
+
const variationValue = testGroup ? item.variations[testGroup] : void 0;
|
|
5
|
+
if (testGroup && variationValue) {
|
|
6
|
+
item.data = variationValue.data;
|
|
7
|
+
item.testVariationId = variationValue.id;
|
|
8
|
+
item.testVariationName = variationValue.name;
|
|
9
|
+
} else {
|
|
10
|
+
let n = 0;
|
|
11
|
+
const random = Math.random();
|
|
12
|
+
let set = false;
|
|
13
|
+
for (const id in item.variations) {
|
|
14
|
+
const variation = item.variations[id];
|
|
15
|
+
const testRatio = variation.testRatio;
|
|
16
|
+
n += testRatio;
|
|
17
|
+
if (random < n) {
|
|
18
|
+
const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
|
|
19
|
+
set = true;
|
|
20
|
+
Object.assign(item, {
|
|
21
|
+
data: variation.data,
|
|
22
|
+
testVariationId: variation.id,
|
|
23
|
+
testVariationName: variationName
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
if (!set) {
|
|
28
|
+
Object.assign(item, {
|
|
29
|
+
testVariationId: item.id,
|
|
30
|
+
testVariationName: "Default"
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
handleABTesting
|
|
38
|
+
};
|
|
@@ -37,20 +37,14 @@ 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";
|
|
40
45
|
import { getFetch } from "../get-fetch.js";
|
|
46
|
+
import { handleABTesting } from "./ab-testing.js";
|
|
41
47
|
const fetch$ = getFetch();
|
|
42
|
-
function flatten(object, path = null, separator = ".") {
|
|
43
|
-
return Object.keys(object).reduce((acc, key) => {
|
|
44
|
-
const value = object[key];
|
|
45
|
-
const newPath = [path, key].filter(Boolean).join(separator);
|
|
46
|
-
const isObject = [
|
|
47
|
-
typeof value === "object",
|
|
48
|
-
value !== null,
|
|
49
|
-
!(Array.isArray(value) && value.length === 0)
|
|
50
|
-
].every(Boolean);
|
|
51
|
-
return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
|
|
52
|
-
}, {});
|
|
53
|
-
}
|
|
54
48
|
function getContent(options) {
|
|
55
49
|
return __async(this, null, function* () {
|
|
56
50
|
return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
|
|
@@ -66,67 +60,31 @@ const generateContentUrl = (options) => {
|
|
|
66
60
|
apiKey
|
|
67
61
|
} = options;
|
|
68
62
|
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
63
|
+
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
64
|
+
const flattened = flatten(queryOptions);
|
|
65
|
+
for (const key in flattened) {
|
|
66
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
74
67
|
}
|
|
75
68
|
if (userAttributes) {
|
|
76
69
|
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
77
70
|
}
|
|
78
71
|
if (query) {
|
|
79
|
-
const
|
|
80
|
-
for (const key in
|
|
81
|
-
url.searchParams.set(key, JSON.stringify(
|
|
72
|
+
const flattened2 = flatten({ query });
|
|
73
|
+
for (const key in flattened2) {
|
|
74
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
82
75
|
}
|
|
83
76
|
}
|
|
84
77
|
return url;
|
|
85
78
|
};
|
|
86
|
-
const handleABTesting = (content, testGroups) => {
|
|
87
|
-
for (const item of content.results) {
|
|
88
|
-
if (item.variations && Object.keys(item.variations).length) {
|
|
89
|
-
const testGroup = testGroups[item.id];
|
|
90
|
-
const variationValue = item.variations[testGroup];
|
|
91
|
-
if (testGroup && variationValue) {
|
|
92
|
-
item.data = variationValue.data;
|
|
93
|
-
item.testVariationId = variationValue.id;
|
|
94
|
-
item.testVariationName = variationValue.name;
|
|
95
|
-
} else {
|
|
96
|
-
let n = 0;
|
|
97
|
-
const random = Math.random();
|
|
98
|
-
let set = false;
|
|
99
|
-
for (const id in item.variations) {
|
|
100
|
-
const variation = item.variations[id];
|
|
101
|
-
const testRatio = variation.testRatio;
|
|
102
|
-
n += testRatio;
|
|
103
|
-
if (random < n) {
|
|
104
|
-
const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
|
|
105
|
-
set = true;
|
|
106
|
-
Object.assign(item, {
|
|
107
|
-
data: variation.data,
|
|
108
|
-
testVariationId: variation.id,
|
|
109
|
-
testVariationName: variationName
|
|
110
|
-
});
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
if (!set) {
|
|
114
|
-
Object.assign(item, {
|
|
115
|
-
testVariationId: item.id,
|
|
116
|
-
testVariationName: "Default"
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
};
|
|
123
79
|
function getAllContent(options) {
|
|
124
80
|
return __async(this, null, function* () {
|
|
125
81
|
const url = generateContentUrl(options);
|
|
126
82
|
const fetch = yield fetch$;
|
|
127
83
|
const content = yield fetch(url.href).then((res) => res.json());
|
|
128
84
|
if (options.testGroups) {
|
|
129
|
-
|
|
85
|
+
for (const item of content.results) {
|
|
86
|
+
handleABTesting(item, options.testGroups);
|
|
87
|
+
}
|
|
130
88
|
}
|
|
131
89
|
return content;
|
|
132
90
|
});
|
|
File without changes
|
|
@@ -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 {
|
|
@@ -20,9 +20,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { evaluate } from "./evaluate.js";
|
|
21
21
|
import { set } from "./set.js";
|
|
22
22
|
import { transformBlock } from "./transform-block.js";
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
const evaluateBindings = ({
|
|
24
|
+
block,
|
|
25
|
+
context,
|
|
26
|
+
state
|
|
27
|
+
}) => {
|
|
26
28
|
if (!block.bindings) {
|
|
27
29
|
return block;
|
|
28
30
|
}
|
|
@@ -32,14 +34,23 @@ function getProcessedBlock(options) {
|
|
|
32
34
|
});
|
|
33
35
|
for (const binding in block.bindings) {
|
|
34
36
|
const expression = block.bindings[binding];
|
|
35
|
-
const value = evaluate({
|
|
36
|
-
code: expression,
|
|
37
|
-
state,
|
|
38
|
-
context
|
|
39
|
-
});
|
|
37
|
+
const value = evaluate({ code: expression, state, context });
|
|
40
38
|
set(copied, binding, value);
|
|
41
39
|
}
|
|
42
40
|
return copied;
|
|
41
|
+
};
|
|
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 });
|
|
51
|
+
} else {
|
|
52
|
+
return transformedBlock;
|
|
53
|
+
}
|
|
43
54
|
}
|
|
44
55
|
export {
|
|
45
56
|
getProcessedBlock
|
|
@@ -20,7 +20,8 @@ test("Can process bindings", () => {
|
|
|
20
20
|
const processed = getProcessedBlock({
|
|
21
21
|
block,
|
|
22
22
|
context: {},
|
|
23
|
-
state: { test: "hello" }
|
|
23
|
+
state: { test: "hello" },
|
|
24
|
+
shouldEvaluateBindings: true
|
|
24
25
|
});
|
|
25
26
|
expect(processed).not.toEqual(block);
|
|
26
27
|
expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
|
|
@@ -17,37 +17,56 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
|
|
21
|
-
|
|
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
|
+
const components = [];
|
|
22
33
|
function registerComponent(component, info) {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (isBrowser()) {
|
|
26
|
-
const sendInfo = prepareComponentInfoToSend(info);
|
|
27
|
-
(_a = window.parent) == null ? void 0 : _a.postMessage({
|
|
28
|
-
type: "builder.registerComponent",
|
|
29
|
-
data: sendInfo
|
|
30
|
-
}, "*");
|
|
31
|
-
}
|
|
34
|
+
components.push(__spreadValues({ component }, info));
|
|
35
|
+
console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
|
|
32
36
|
return component;
|
|
33
37
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
38
|
+
const createRegisterComponentMessage = (_a) => {
|
|
39
|
+
var _b = _a, {
|
|
40
|
+
component: _
|
|
41
|
+
} = _b, info = __objRest(_b, [
|
|
42
|
+
"component"
|
|
43
|
+
]);
|
|
44
|
+
return {
|
|
45
|
+
type: "builder.registerComponent",
|
|
46
|
+
data: prepareComponentInfoToSend(info)
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
50
|
+
const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
|
|
51
|
+
const serializeFn = (fnValue) => {
|
|
52
|
+
const fnStr = fnValue.toString().trim();
|
|
53
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
|
|
54
|
+
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
55
|
+
};
|
|
56
|
+
const prepareComponentInfoToSend = (_c) => {
|
|
57
|
+
var _d = _c, {
|
|
58
|
+
inputs
|
|
59
|
+
} = _d, info = __objRest(_d, [
|
|
60
|
+
"inputs"
|
|
61
|
+
]);
|
|
62
|
+
return __spreadProps(__spreadValues({}, fastClone(info)), {
|
|
63
|
+
inputs: inputs == null ? void 0 : inputs.map((input) => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
|
|
64
|
+
[key]: serializeValue(value)
|
|
65
|
+
}), {}))
|
|
48
66
|
});
|
|
49
|
-
}
|
|
67
|
+
};
|
|
50
68
|
export {
|
|
51
69
|
components,
|
|
70
|
+
createRegisterComponentMessage,
|
|
52
71
|
registerComponent
|
|
53
72
|
};
|
package/src/functions/track.js
CHANGED
|
@@ -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
|
-
|
|
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({
|
|
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,12 @@
|
|
|
1
|
+
import { camelToKebabCase } from "../functions/camel-to-kebab-case";
|
|
2
|
+
const convertStyleMaptoCSS = (style) => {
|
|
3
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
4
|
+
if (typeof value === "string") {
|
|
5
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
6
|
+
}
|
|
7
|
+
});
|
|
8
|
+
return cssProps.join("\n");
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
convertStyleMaptoCSS
|
|
12
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
function flatten(object, path = null, separator = ".") {
|
|
21
|
+
return Object.keys(object).reduce((acc, key) => {
|
|
22
|
+
const value = object[key];
|
|
23
|
+
const newPath = [path, key].filter(Boolean).join(separator);
|
|
24
|
+
const isObject = [
|
|
25
|
+
typeof value === "object",
|
|
26
|
+
value !== null,
|
|
27
|
+
!(Array.isArray(value) && value.length === 0)
|
|
28
|
+
].every(Boolean);
|
|
29
|
+
return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
|
|
30
|
+
}, {});
|
|
31
|
+
}
|
|
32
|
+
export {
|
|
33
|
+
flatten
|
|
34
|
+
};
|
|
@@ -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
|
+
};
|