@builder.io/sdk-svelte 5.2.11 → 5.2.13
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/lib/browser/blocks/image/image.svelte +3 -1
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -2
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.js +22 -2
- package/lib/browser/blocks/personalization-container/helpers.js +5 -1
- package/lib/browser/components/block/components/block-styles.svelte +2 -2
- package/lib/browser/components/block/components/live-edit-block-styles.svelte +2 -2
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/helpers/css.d.ts +2 -0
- package/lib/browser/helpers/css.js +14 -0
- package/lib/browser/helpers/studio-user-attributes.d.ts +6 -0
- package/lib/browser/helpers/studio-user-attributes.js +31 -0
- package/lib/browser/helpers/user-attributes.d.ts +6 -2
- package/lib/browser/helpers/user-attributes.js +20 -6
- package/lib/edge/blocks/image/image.svelte +3 -1
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -2
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.js +22 -2
- package/lib/edge/blocks/personalization-container/helpers.js +5 -1
- package/lib/edge/components/block/components/block-styles.svelte +2 -2
- package/lib/edge/components/block/components/live-edit-block-styles.svelte +2 -2
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/helpers/css.d.ts +2 -0
- package/lib/edge/helpers/css.js +14 -0
- package/lib/edge/helpers/studio-user-attributes.d.ts +6 -0
- package/lib/edge/helpers/studio-user-attributes.js +31 -0
- package/lib/edge/helpers/user-attributes.d.ts +6 -2
- package/lib/edge/helpers/user-attributes.js +20 -6
- package/lib/node/blocks/image/image.svelte +3 -1
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -2
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.js +22 -2
- package/lib/node/blocks/personalization-container/helpers.js +5 -1
- package/lib/node/components/block/components/block-styles.svelte +2 -2
- package/lib/node/components/block/components/live-edit-block-styles.svelte +2 -2
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/helpers/css.d.ts +2 -0
- package/lib/node/helpers/css.js +14 -0
- package/lib/node/helpers/studio-user-attributes.d.ts +6 -0
- package/lib/node/helpers/studio-user-attributes.js +31 -0
- package/lib/node/helpers/user-attributes.d.ts +6 -2
- package/lib/node/helpers/user-attributes.js +20 -6
- package/package.json +1 -1
- package/src/blocks/image/image.svelte +3 -1
- package/src/blocks/personalization-container/helpers/inlined-fns.ts +23 -2
- package/src/blocks/personalization-container/helpers.ts +5 -1
- package/src/components/block/components/block-styles.svelte +8 -2
- package/src/components/block/components/live-edit-block-styles.svelte +8 -2
- package/src/constants/sdk-version.ts +1 -1
- package/src/helpers/css.ts +15 -0
- package/src/helpers/studio-user-attributes.ts +31 -0
- package/src/helpers/user-attributes.ts +20 -6
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isBrowser } from '../functions/is-browser';
|
|
2
|
+
import type { UserAttributes } from './user-attributes';
|
|
3
|
+
const STUDIO_PREVIEW_PARAM = 'builder.preview';
|
|
4
|
+
const STUDIO_PREVIEW_VALUE = 'BUILDER_STUDIO';
|
|
5
|
+
const USER_ATTRIBUTE_PARAM_PREFIX = 'builder.userAttributes.';
|
|
6
|
+
const parseStudioValue = (value: string) => {
|
|
7
|
+
if (value === 'true') return true;
|
|
8
|
+
if (value === 'false') return false;
|
|
9
|
+
return value;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Studio passes its targeting overrides as query params because it cannot write the
|
|
14
|
+
* builder.userAttributes cookie on the previewed site's origin.
|
|
15
|
+
*/
|
|
16
|
+
export const getStudioUserAttributes = (): UserAttributes => {
|
|
17
|
+
if (!isBrowser()) {
|
|
18
|
+
return {};
|
|
19
|
+
}
|
|
20
|
+
const params = new URLSearchParams(window.location.search);
|
|
21
|
+
if (params.get(STUDIO_PREVIEW_PARAM) !== STUDIO_PREVIEW_VALUE) {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const attributes: UserAttributes = {};
|
|
25
|
+
params.forEach((value, key) => {
|
|
26
|
+
if (key.startsWith(USER_ATTRIBUTE_PARAM_PREFIX)) {
|
|
27
|
+
attributes[key.slice(USER_ATTRIBUTE_PARAM_PREFIX.length)] = parseStudioValue(value);
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
return attributes;
|
|
31
|
+
}
|
|
@@ -2,6 +2,7 @@ import { TARGET } from '../constants/target';
|
|
|
2
2
|
import { isBrowser } from '../functions/is-browser';
|
|
3
3
|
import { getCookieSync, setCookie } from './cookie';
|
|
4
4
|
import { noSerializeWrapper } from './no-serialize-wrapper';
|
|
5
|
+
import { getStudioUserAttributes } from './studio-user-attributes';
|
|
5
6
|
export interface UserAttributes {
|
|
6
7
|
[key: string]: any;
|
|
7
8
|
}
|
|
@@ -9,13 +10,20 @@ export const USER_ATTRIBUTES_COOKIE_NAME = 'builder.userAttributes';
|
|
|
9
10
|
export function createUserAttributesService() {
|
|
10
11
|
let canTrack = true;
|
|
11
12
|
const subscribers = new Set<(attrs: UserAttributes) => void>();
|
|
13
|
+
const getCookieUserAttributes = (): UserAttributes => {
|
|
14
|
+
const cookie = getCookieSync({
|
|
15
|
+
name: USER_ATTRIBUTES_COOKIE_NAME,
|
|
16
|
+
canTrack
|
|
17
|
+
});
|
|
18
|
+
return cookie ? JSON.parse(cookie) : {};
|
|
19
|
+
};
|
|
12
20
|
return {
|
|
13
21
|
setUserAttributes(newAttrs: UserAttributes) {
|
|
14
22
|
if (!isBrowser()) {
|
|
15
23
|
return;
|
|
16
24
|
}
|
|
17
25
|
const userAttributes: UserAttributes = {
|
|
18
|
-
...
|
|
26
|
+
...getCookieUserAttributes(),
|
|
19
27
|
...newAttrs
|
|
20
28
|
};
|
|
21
29
|
setCookie({
|
|
@@ -23,16 +31,22 @@ export function createUserAttributesService() {
|
|
|
23
31
|
value: JSON.stringify(userAttributes),
|
|
24
32
|
canTrack
|
|
25
33
|
});
|
|
26
|
-
|
|
34
|
+
// Kept out of the cookie above so previewing never persists into a real visitor's
|
|
35
|
+
// session, but re-applied here so the site's own attributes cannot clobber it.
|
|
36
|
+
const studioAttributes = getStudioUserAttributes();
|
|
37
|
+
subscribers.forEach(callback => callback({
|
|
38
|
+
...userAttributes,
|
|
39
|
+
...studioAttributes
|
|
40
|
+
}));
|
|
27
41
|
},
|
|
28
42
|
getUserAttributes() {
|
|
29
43
|
if (!isBrowser()) {
|
|
30
44
|
return {};
|
|
31
45
|
}
|
|
32
|
-
return
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
46
|
+
return {
|
|
47
|
+
...getCookieUserAttributes(),
|
|
48
|
+
...getStudioUserAttributes()
|
|
49
|
+
};
|
|
36
50
|
},
|
|
37
51
|
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void, {
|
|
38
52
|
fireImmediately
|