@builder.io/sdk-svelte 0.1.1 → 0.1.3-0
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/--package.json +3 -3
- package/package/CHANGELOG.md +9 -0
- package/package/blocks/BaseText.svelte +1 -1
- package/package/blocks/button/button.svelte +1 -1
- package/package/blocks/columns/columns.svelte +3 -3
- package/package/blocks/custom-code/custom-code.svelte +1 -1
- package/package/blocks/embed/embed.svelte +2 -3
- package/package/blocks/form/form.svelte +1 -1
- package/package/blocks/fragment/fragment.svelte +1 -1
- package/package/blocks/image/image.svelte +1 -2
- package/package/blocks/img/img.svelte +1 -1
- package/package/blocks/input/input.svelte +1 -1
- package/package/blocks/raw-text/raw-text.svelte +1 -1
- package/package/blocks/section/section.svelte +1 -1
- package/package/blocks/select/select.svelte +1 -1
- package/package/blocks/submit-button/submit-button.svelte +1 -1
- package/package/blocks/symbol/symbol.svelte +4 -2
- package/package/blocks/text/text.svelte +1 -1
- package/package/blocks/textarea/textarea.svelte +1 -1
- package/package/blocks/video/video.svelte +1 -1
- package/package/components/render-block/block-styles.svelte +1 -1
- package/package/components/render-block/render-block.helpers.d.ts +11 -0
- package/package/components/render-block/render-block.helpers.js +58 -0
- package/package/components/render-block/render-block.svelte +33 -109
- package/package/components/render-block/render-component.svelte +1 -1
- package/package/components/render-block/render-repeated-block.svelte +7 -19
- package/package/components/render-blocks.svelte +1 -1
- package/package/components/render-content/builder-editing.svelte +1 -1
- package/package/components/render-content/components/render-styles.svelte +3 -3
- package/package/components/render-content/render-content.svelte +53 -53
- package/package/components/render-inlined-styles.svelte +1 -1
- package/package/functions/track/helpers.d.ts +5 -0
- package/package/functions/track/helpers.js +56 -0
- package/package/functions/{track.d.ts → track/index.d.ts} +5 -10
- package/package/functions/{track.js → track/index.js} +11 -6
- package/package/helpers/ab-tests.d.ts +1 -1
- package/package/helpers/cookie.d.ts +1 -1
- package/package/helpers/cookie.js +7 -2
- package/package/helpers/localStorage.d.ts +2 -1
- package/package/helpers/localStorage.js +1 -0
- package/package/helpers/sessionId.d.ts +2 -2
- package/package/helpers/sessionId.js +2 -1
- package/package/helpers/url.js +3 -0
- package/package/helpers/url.test.js +6 -0
- package/package/helpers/visitorId.js +1 -0
- package/package/index.d.ts +1 -1
- package/package/index.js +1 -1
- package/package.json +1 -1
- package/src/blocks/BaseText.svelte +2 -2
- package/src/blocks/button/button.svelte +1 -6
- package/src/blocks/columns/columns.svelte +3 -3
- package/src/blocks/custom-code/custom-code.svelte +1 -1
- package/src/blocks/embed/component-info.ts +29 -27
- package/src/blocks/embed/embed.svelte +1 -3
- package/src/blocks/form/form.svelte +2 -7
- package/src/blocks/fragment/fragment.svelte +1 -1
- package/src/blocks/image/component-info.ts +57 -55
- package/src/blocks/image/image.svelte +1 -2
- package/src/blocks/img/img.svelte +1 -6
- package/src/blocks/input/input.svelte +1 -6
- package/src/blocks/raw-text/raw-text.svelte +1 -1
- package/src/blocks/section/section.svelte +1 -6
- package/src/blocks/select/select.svelte +1 -6
- package/src/blocks/submit-button/submit-button.svelte +1 -6
- package/src/blocks/symbol/symbol.svelte +5 -8
- package/src/blocks/text/text.svelte +1 -1
- package/src/blocks/textarea/textarea.svelte +1 -6
- package/src/blocks/video/video.svelte +1 -6
- package/src/components/render-block/block-styles.svelte +1 -1
- package/src/components/render-block/render-block.helpers.ts +85 -0
- package/src/components/render-block/render-block.svelte +41 -118
- package/src/components/render-block/render-component.svelte +1 -1
- package/src/components/render-block/render-repeated-block.svelte +8 -20
- package/src/components/render-blocks.svelte +2 -2
- package/src/components/render-content/builder-editing.svelte +1 -1
- package/src/components/render-content/components/render-styles.svelte +5 -3
- package/src/components/render-content/render-content.svelte +59 -64
- package/src/components/render-inlined-styles.svelte +1 -1
- package/src/functions/track/helpers.ts +67 -0
- package/src/functions/{track.ts → track/index.ts} +16 -17
- package/src/helpers/cookie.ts +9 -4
- package/src/helpers/localStorage.ts +3 -1
- package/src/helpers/sessionId.ts +5 -1
- package/src/helpers/url.test.ts +7 -0
- package/src/helpers/url.ts +4 -0
- package/src/helpers/visitorId.ts +3 -1
- package/src/index.ts +1 -1
- package/package/components/render-block/render-component-with-context.svelte +0 -32
- package/package/components/render-block/render-component-with-context.svelte.d.ts +0 -19
- package/src/components/render-block/render-component-with-context.svelte +0 -38
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>import { onDestroy, onMount, setContext
|
|
3
|
+
<script>import { onDestroy, onMount, setContext } from "svelte";
|
|
4
4
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
5
|
import { TARGET } from "../../constants/target.js";
|
|
6
6
|
import { evaluate } from "../../functions/evaluate.js";
|
|
@@ -10,11 +10,12 @@ import { isBrowser } from "../../functions/is-browser.js";
|
|
|
10
10
|
import { isEditing } from "../../functions/is-editing.js";
|
|
11
11
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
12
12
|
import { components, createRegisterComponentMessage, } from "../../functions/register-component.js";
|
|
13
|
-
import { _track } from "../../functions/track.js";
|
|
13
|
+
import { _track } from "../../functions/track/index.js";
|
|
14
14
|
import RenderBlocks from "../render-blocks.svelte";
|
|
15
15
|
import RenderContentStyles from "./components/render-styles.svelte";
|
|
16
|
-
import
|
|
16
|
+
import builderContext from "../../context/builder.context.js";
|
|
17
17
|
import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
|
|
18
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
18
19
|
export let content;
|
|
19
20
|
export let data;
|
|
20
21
|
export let canTrack;
|
|
@@ -24,7 +25,7 @@ export let customComponents;
|
|
|
24
25
|
export let model;
|
|
25
26
|
export let apiKey;
|
|
26
27
|
export let includeRefs;
|
|
27
|
-
setContext(
|
|
28
|
+
setContext(builderContext.key, {
|
|
28
29
|
get content() {
|
|
29
30
|
return useContent();
|
|
30
31
|
},
|
|
@@ -32,13 +33,13 @@ setContext(BuilderContext.key, {
|
|
|
32
33
|
return contentState();
|
|
33
34
|
},
|
|
34
35
|
get context() {
|
|
35
|
-
return contextContext
|
|
36
|
+
return contextContext;
|
|
36
37
|
},
|
|
37
38
|
get apiKey() {
|
|
38
39
|
return apiKey;
|
|
39
40
|
},
|
|
40
41
|
get registeredComponents() {
|
|
41
|
-
return allRegisteredComponents
|
|
42
|
+
return allRegisteredComponents;
|
|
42
43
|
},
|
|
43
44
|
});
|
|
44
45
|
function processMessage(event) {
|
|
@@ -81,7 +82,7 @@ function evaluateJsCode() {
|
|
|
81
82
|
if (jsCode) {
|
|
82
83
|
evaluate({
|
|
83
84
|
code: jsCode,
|
|
84
|
-
context: contextContext
|
|
85
|
+
context: contextContext,
|
|
85
86
|
state: contentState(),
|
|
86
87
|
});
|
|
87
88
|
}
|
|
@@ -92,7 +93,7 @@ function onClick(_event) {
|
|
|
92
93
|
const contentId = useContent?.()?.id;
|
|
93
94
|
_track({
|
|
94
95
|
type: "click",
|
|
95
|
-
canTrack: canTrackToUse
|
|
96
|
+
canTrack: canTrackToUse,
|
|
96
97
|
contentId,
|
|
97
98
|
apiKey: apiKey,
|
|
98
99
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
@@ -102,7 +103,7 @@ function onClick(_event) {
|
|
|
102
103
|
function evalExpression(expression) {
|
|
103
104
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
104
105
|
code: group,
|
|
105
|
-
context: contextContext
|
|
106
|
+
context: contextContext,
|
|
106
107
|
state: contentState(),
|
|
107
108
|
}));
|
|
108
109
|
}
|
|
@@ -123,7 +124,7 @@ function handleRequest({ url, key }) {
|
|
|
123
124
|
function runHttpRequests() {
|
|
124
125
|
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
125
126
|
Object.entries(requests).forEach(([key, url]) => {
|
|
126
|
-
if (url && (!httpReqsData
|
|
127
|
+
if (url && (!httpReqsData[key] || isEditing())) {
|
|
127
128
|
const evaluatedUrl = evalExpression(url);
|
|
128
129
|
handleRequest({
|
|
129
130
|
url: evaluatedUrl,
|
|
@@ -148,7 +149,7 @@ $: useContent = () => {
|
|
|
148
149
|
if (!content && !overrideContent) {
|
|
149
150
|
return undefined;
|
|
150
151
|
}
|
|
151
|
-
|
|
152
|
+
return {
|
|
152
153
|
...content,
|
|
153
154
|
...overrideContent,
|
|
154
155
|
data: {
|
|
@@ -164,10 +165,6 @@ $: useContent = () => {
|
|
|
164
165
|
content?.meta?.breakpoints,
|
|
165
166
|
},
|
|
166
167
|
};
|
|
167
|
-
return mergedContent;
|
|
168
|
-
};
|
|
169
|
-
$: canTrackToUse = () => {
|
|
170
|
-
return canTrack || true;
|
|
171
168
|
};
|
|
172
169
|
$: contentState = () => {
|
|
173
170
|
return {
|
|
@@ -181,29 +178,6 @@ $: contentState = () => {
|
|
|
181
178
|
...overrideState,
|
|
182
179
|
};
|
|
183
180
|
};
|
|
184
|
-
$: contextContext = () => {
|
|
185
|
-
return context || {};
|
|
186
|
-
};
|
|
187
|
-
$: allRegisteredComponents = () => {
|
|
188
|
-
const allComponentsArray = [
|
|
189
|
-
...getDefaultRegisteredComponents(),
|
|
190
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
191
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
192
|
-
// existing usage.
|
|
193
|
-
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
194
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
195
|
-
...components,
|
|
196
|
-
...(customComponents || []),
|
|
197
|
-
];
|
|
198
|
-
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
199
|
-
...acc,
|
|
200
|
-
[curr.name]: curr,
|
|
201
|
-
}), {});
|
|
202
|
-
return allComponents;
|
|
203
|
-
};
|
|
204
|
-
$: httpReqsData = () => {
|
|
205
|
-
return {};
|
|
206
|
-
};
|
|
207
181
|
$: shouldRenderContentStyles = () => {
|
|
208
182
|
return Boolean((useContent?.()?.data?.cssCode ||
|
|
209
183
|
useContent?.()?.data?.customFonts?.length) &&
|
|
@@ -214,7 +188,23 @@ let forceReRenderCount = 0;
|
|
|
214
188
|
let overrideContent = null;
|
|
215
189
|
let update = 0;
|
|
216
190
|
let useBreakpoints = null;
|
|
191
|
+
let canTrackToUse = checkIsDefined(canTrack) ? canTrack : true;
|
|
217
192
|
let overrideState = {};
|
|
193
|
+
let contextContext = context || {};
|
|
194
|
+
let allRegisteredComponents = [
|
|
195
|
+
...getDefaultRegisteredComponents(),
|
|
196
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
197
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
198
|
+
// existing usage.
|
|
199
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
200
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
201
|
+
...components,
|
|
202
|
+
...(customComponents || []),
|
|
203
|
+
].reduce((acc, curr) => ({
|
|
204
|
+
...acc,
|
|
205
|
+
[curr.name]: curr,
|
|
206
|
+
}), {});
|
|
207
|
+
let httpReqsData = {};
|
|
218
208
|
onMount(() => {
|
|
219
209
|
if (!apiKey) {
|
|
220
210
|
console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
@@ -235,7 +225,7 @@ onMount(() => {
|
|
|
235
225
|
}
|
|
236
226
|
: {}),
|
|
237
227
|
});
|
|
238
|
-
Object.values(allRegisteredComponents
|
|
228
|
+
Object.values(allRegisteredComponents).forEach((registeredComponent) => {
|
|
239
229
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
240
230
|
window.parent?.postMessage(message, "*");
|
|
241
231
|
});
|
|
@@ -247,7 +237,7 @@ onMount(() => {
|
|
|
247
237
|
const contentId = useContent?.()?.id;
|
|
248
238
|
_track({
|
|
249
239
|
type: "impression",
|
|
250
|
-
canTrack: canTrackToUse
|
|
240
|
+
canTrack: canTrackToUse,
|
|
251
241
|
contentId,
|
|
252
242
|
apiKey: apiKey,
|
|
253
243
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
@@ -256,18 +246,28 @@ onMount(() => {
|
|
|
256
246
|
// override normal content in preview mode
|
|
257
247
|
if (isPreviewing()) {
|
|
258
248
|
const searchParams = new URL(location.href).searchParams;
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
249
|
+
const searchParamPreview = searchParams.get("builder.preview");
|
|
250
|
+
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
251
|
+
/**
|
|
252
|
+
* Make sure that:
|
|
253
|
+
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
|
|
254
|
+
* at the same time, e.g. header/page/footer.
|
|
255
|
+
* - the API key is the same, since we don't want to preview content from other organizations.
|
|
256
|
+
*
|
|
257
|
+
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
258
|
+
* this break scenarios where the item is not published yet?
|
|
259
|
+
*
|
|
260
|
+
* TO-DO: should we only update the state when there is a change?
|
|
261
|
+
**/
|
|
262
|
+
if (searchParamPreview === model && previewApiKey === apiKey) {
|
|
263
|
+
getContent({
|
|
264
|
+
model: model,
|
|
265
|
+
apiKey: apiKey,
|
|
266
|
+
}).then((content) => {
|
|
267
|
+
if (content) {
|
|
268
|
+
overrideContent = content;
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
271
|
}
|
|
272
272
|
}
|
|
273
273
|
evaluateJsCode();
|
|
@@ -315,4 +315,4 @@ onDestroy(() => {
|
|
|
315
315
|
key={forceReRenderCount}
|
|
316
316
|
/>
|
|
317
317
|
</div>
|
|
318
|
-
{/if}
|
|
318
|
+
{/if}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { TARGET } from '../../constants/target';
|
|
2
|
+
import { isBrowser } from '../is-browser';
|
|
3
|
+
const getLocation = () => {
|
|
4
|
+
if (TARGET === 'reactNative') {
|
|
5
|
+
return null;
|
|
6
|
+
}
|
|
7
|
+
else if (isBrowser()) {
|
|
8
|
+
const parsedLocation = new URL(location.href);
|
|
9
|
+
// IE11 bug with parsed path being empty string
|
|
10
|
+
// causes issues with our user targeting
|
|
11
|
+
if (parsedLocation.pathname === '') {
|
|
12
|
+
parsedLocation.pathname = '/';
|
|
13
|
+
}
|
|
14
|
+
return parsedLocation;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
console.warn('Cannot get location for tracking in non-browser environment');
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
};
|
|
21
|
+
const getUserAgent = () => (typeof navigator === 'object' && navigator.userAgent) || '';
|
|
22
|
+
export const getUserAttributes = () => {
|
|
23
|
+
const userAgent = getUserAgent();
|
|
24
|
+
const isMobile = {
|
|
25
|
+
Android() {
|
|
26
|
+
return userAgent.match(/Android/i);
|
|
27
|
+
},
|
|
28
|
+
BlackBerry() {
|
|
29
|
+
return userAgent.match(/BlackBerry/i);
|
|
30
|
+
},
|
|
31
|
+
iOS() {
|
|
32
|
+
return userAgent.match(/iPhone|iPod/i);
|
|
33
|
+
},
|
|
34
|
+
Opera() {
|
|
35
|
+
return userAgent.match(/Opera Mini/i);
|
|
36
|
+
},
|
|
37
|
+
Windows() {
|
|
38
|
+
return userAgent.match(/IEMobile/i) || userAgent.match(/WPDesktop/i);
|
|
39
|
+
},
|
|
40
|
+
any() {
|
|
41
|
+
return (isMobile.Android() ||
|
|
42
|
+
isMobile.BlackBerry() ||
|
|
43
|
+
isMobile.iOS() ||
|
|
44
|
+
isMobile.Opera() ||
|
|
45
|
+
isMobile.Windows() ||
|
|
46
|
+
TARGET === 'reactNative');
|
|
47
|
+
},
|
|
48
|
+
};
|
|
49
|
+
const isTablet = userAgent.match(/Tablet|iPad/i);
|
|
50
|
+
const url = getLocation();
|
|
51
|
+
return {
|
|
52
|
+
urlPath: url?.pathname,
|
|
53
|
+
host: url?.host || url?.hostname,
|
|
54
|
+
device: isTablet ? 'tablet' : isMobile.any() ? 'mobile' : 'desktop',
|
|
55
|
+
};
|
|
56
|
+
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type { CanTrack } from '
|
|
1
|
+
import type { CanTrack } from '../../types/can-track.js';
|
|
2
|
+
import type { Dictionary } from '../../types/typescript.js';
|
|
2
3
|
interface Event {
|
|
3
4
|
/**
|
|
4
5
|
* The type of your event.
|
|
@@ -16,9 +17,9 @@ interface Event {
|
|
|
16
17
|
*/
|
|
17
18
|
ownerId: string;
|
|
18
19
|
/**
|
|
19
|
-
*
|
|
20
|
+
* (Optional) metadata that you want to provide with your event.
|
|
20
21
|
*/
|
|
21
|
-
metadata?:
|
|
22
|
+
metadata?: Dictionary<any>;
|
|
22
23
|
/**
|
|
23
24
|
* Session ID of the user. This is provided by the SDK by checking session storage.
|
|
24
25
|
*/
|
|
@@ -34,17 +35,11 @@ interface Event {
|
|
|
34
35
|
[index: string]: any;
|
|
35
36
|
};
|
|
36
37
|
}
|
|
37
|
-
declare type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | 'variationId'> & {
|
|
38
|
+
declare type EventProperties = Pick<Event, 'type'> & Pick<Event['data'], 'contentId' | 'variationId' | 'metadata'> & {
|
|
38
39
|
/**
|
|
39
40
|
* Your organization's API key.
|
|
40
41
|
*/
|
|
41
42
|
apiKey: Event['data']['ownerId'];
|
|
42
|
-
/**
|
|
43
|
-
* (Optional) metadata that you want to provide with your event.
|
|
44
|
-
*/
|
|
45
|
-
metadata?: {
|
|
46
|
-
[index: string]: any;
|
|
47
|
-
};
|
|
48
43
|
/**
|
|
49
44
|
* (Optional) Any additional (non-metadata) properties to add to the event.
|
|
50
45
|
*/
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { TARGET } from '
|
|
2
|
-
import { getSessionId } from '
|
|
3
|
-
import { getVisitorId } from '
|
|
4
|
-
import { isBrowser } from '
|
|
5
|
-
import { isEditing } from '
|
|
1
|
+
import { TARGET } from '../../constants/target.js';
|
|
2
|
+
import { getSessionId } from '../../helpers/sessionId.js';
|
|
3
|
+
import { getVisitorId } from '../../helpers/visitorId.js';
|
|
4
|
+
import { isBrowser } from '../is-browser.js';
|
|
5
|
+
import { isEditing } from '../is-editing.js';
|
|
6
|
+
import { getUserAttributes } from './helpers.js';
|
|
6
7
|
const getTrackingEventData = async ({ canTrack, }) => {
|
|
7
8
|
if (!canTrack) {
|
|
8
9
|
return { visitorId: undefined, sessionId: undefined };
|
|
@@ -18,8 +19,12 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
|
|
|
18
19
|
type: eventType,
|
|
19
20
|
data: {
|
|
20
21
|
...properties,
|
|
21
|
-
metadata:
|
|
22
|
+
metadata: {
|
|
23
|
+
url: location.href,
|
|
24
|
+
...metadata,
|
|
25
|
+
},
|
|
22
26
|
...(await getTrackingEventData({ canTrack })),
|
|
27
|
+
userAttributes: getUserAttributes(),
|
|
23
28
|
ownerId: apiKey,
|
|
24
29
|
},
|
|
25
30
|
});
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isBrowser } from '../functions/is-browser.js';
|
|
2
|
+
import { checkIsDefined } from './nullable.js';
|
|
2
3
|
import { getTopLevelDomain } from './url.js';
|
|
3
4
|
/**
|
|
4
5
|
* NOTE: This function is `async` because its react-native override is async. Do not remove the `async` keyword!
|
|
@@ -19,9 +20,13 @@ export const getCookie = async ({ name, canTrack, }) => {
|
|
|
19
20
|
}
|
|
20
21
|
catch (err) {
|
|
21
22
|
console.debug('[COOKIE] GET error: ', err);
|
|
23
|
+
return undefined;
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
|
-
const stringifyCookie = (cookie) => cookie
|
|
26
|
+
const stringifyCookie = (cookie) => cookie
|
|
27
|
+
.map(([key, value]) => (value ? `${key}=${value}` : key))
|
|
28
|
+
.filter(checkIsDefined)
|
|
29
|
+
.join('; ');
|
|
25
30
|
const SECURE_CONFIG = [
|
|
26
31
|
['secure', ''],
|
|
27
32
|
['SameSite', 'None'],
|
|
@@ -49,7 +54,7 @@ const createCookieString = ({ name, value, expires, }) => {
|
|
|
49
54
|
export const setCookie = async ({ name, value, expires, canTrack, }) => {
|
|
50
55
|
try {
|
|
51
56
|
if (!canTrack) {
|
|
52
|
-
return
|
|
57
|
+
return;
|
|
53
58
|
}
|
|
54
59
|
const cookie = createCookieString({ name, value, expires });
|
|
55
60
|
document.cookie = cookie;
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
+
import type { Nullable } from './nullable.js';
|
|
2
3
|
export declare const getLocalStorageItem: ({ key, canTrack, }: {
|
|
3
4
|
key: string;
|
|
4
|
-
} & CanTrack) => string
|
|
5
|
+
} & CanTrack) => Nullable<string>;
|
|
5
6
|
export declare const setLocalStorageItem: ({ key, canTrack, value, }: {
|
|
6
7
|
key: string;
|
|
7
8
|
value: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { CanTrack } from '../types/can-track.js';
|
|
2
|
-
export declare const getSessionId: ({ canTrack }: CanTrack) => Promise<string | undefined>;
|
|
2
|
+
export declare const getSessionId: ({ canTrack, }: CanTrack) => Promise<string | undefined>;
|
|
3
3
|
export declare const createSessionId: () => string;
|
|
4
4
|
export declare const setSessionId: ({ id, canTrack, }: {
|
|
5
5
|
id: string;
|
|
6
|
-
} & CanTrack) => Promise<
|
|
6
|
+
} & CanTrack) => Promise<void>;
|
|
@@ -2,7 +2,7 @@ import { getCookie, setCookie } from './cookie.js';
|
|
|
2
2
|
import { checkIsDefined } from './nullable.js';
|
|
3
3
|
import { uuid } from './uuid.js';
|
|
4
4
|
const SESSION_LOCAL_STORAGE_KEY = 'builderSessionId';
|
|
5
|
-
export const getSessionId = async ({ canTrack }) => {
|
|
5
|
+
export const getSessionId = async ({ canTrack, }) => {
|
|
6
6
|
if (!canTrack) {
|
|
7
7
|
return undefined;
|
|
8
8
|
}
|
|
@@ -16,6 +16,7 @@ export const getSessionId = async ({ canTrack }) => {
|
|
|
16
16
|
else {
|
|
17
17
|
const newSessionId = createSessionId();
|
|
18
18
|
setSessionId({ id: newSessionId, canTrack });
|
|
19
|
+
return newSessionId;
|
|
19
20
|
}
|
|
20
21
|
};
|
|
21
22
|
export const createSessionId = () => uuid();
|
package/package/helpers/url.js
CHANGED
|
@@ -12,4 +12,10 @@ describe('getTopLevelDomain', () => {
|
|
|
12
12
|
const output = getTopLevelDomain('www.example.co.uk');
|
|
13
13
|
expect(output).toBe('example.co.uk');
|
|
14
14
|
});
|
|
15
|
+
test('handles localhost', () => {
|
|
16
|
+
const output = getTopLevelDomain('localhost');
|
|
17
|
+
expect(output).toBe('localhost');
|
|
18
|
+
const output2 = getTopLevelDomain('127.0.0.1');
|
|
19
|
+
expect(output2).toBe('127.0.0.1');
|
|
20
|
+
});
|
|
15
21
|
});
|
package/package/index.d.ts
CHANGED
|
@@ -8,6 +8,6 @@ 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
|
-
export { track } from './functions/track';
|
|
11
|
+
export { track } from './functions/track/index.js';
|
|
12
12
|
export type { RegisteredComponent } from './context/types';
|
|
13
13
|
export type { ComponentInfo } from './types/components';
|
package/package/index.js
CHANGED
|
@@ -8,4 +8,4 @@ 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
|
-
export { track } from './functions/track';
|
|
11
|
+
export { track } from './functions/track/index.js';
|
package/package.json
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import { getContext
|
|
8
|
+
import { getContext } from "svelte";
|
|
9
9
|
|
|
10
10
|
import BuilderContext from "../context/builder.context.js";
|
|
11
11
|
|
|
@@ -24,4 +24,4 @@
|
|
|
24
24
|
let builderContext = getContext(BuilderContext.key);
|
|
25
25
|
</script>
|
|
26
26
|
|
|
27
|
-
<span use:mitosis_styling={builderContext.inheritedStyles}>{text}</span>
|
|
27
|
+
<span use:mitosis_styling={builderContext.inheritedStyles}>{text}</span>
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
<script lang="ts">
|
|
11
11
|
const isEvent = (attr) => attr.startsWith("on:");
|
|
12
12
|
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
13
|
-
|
|
14
13
|
const filterAttrs = (attrs, filter) => {
|
|
15
14
|
const validAttr = {};
|
|
16
15
|
Object.keys(attrs).forEach((attr) => {
|
|
@@ -20,16 +19,12 @@
|
|
|
20
19
|
});
|
|
21
20
|
return validAttr;
|
|
22
21
|
};
|
|
23
|
-
|
|
24
22
|
const setAttrs = (node, attrs) => {
|
|
25
23
|
const attrKeys = Object.keys(attrs);
|
|
26
|
-
|
|
27
24
|
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
28
25
|
const teardown = (attr) =>
|
|
29
26
|
node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
30
|
-
|
|
31
27
|
attrKeys.map(setup);
|
|
32
|
-
|
|
33
28
|
return {
|
|
34
29
|
update(attrs) {
|
|
35
30
|
const attrKeys = Object.keys(attrs);
|
|
@@ -72,4 +67,4 @@
|
|
|
72
67
|
.button {
|
|
73
68
|
all: unset;
|
|
74
69
|
}
|
|
75
|
-
</style>
|
|
70
|
+
</style>
|
|
@@ -145,10 +145,10 @@
|
|
|
145
145
|
`;
|
|
146
146
|
};
|
|
147
147
|
$: reactNativeColumnsStyles = () => {
|
|
148
|
-
return columnStyleObjects.columns.small;
|
|
148
|
+
return this.columnStyleObjects.columns.small;
|
|
149
149
|
};
|
|
150
150
|
$: reactNativeColumnStyles = () => {
|
|
151
|
-
return columnStyleObjects.column.small;
|
|
151
|
+
return this.columnStyleObjects.column.small;
|
|
152
152
|
};
|
|
153
153
|
</script>
|
|
154
154
|
|
|
@@ -195,4 +195,4 @@
|
|
|
195
195
|
flex-direction: column;
|
|
196
196
|
align-items: stretch;
|
|
197
197
|
}
|
|
198
|
-
</style>
|
|
198
|
+
</style>
|
|
@@ -12,35 +12,37 @@ export const componentInfo: ComponentInfo = {
|
|
|
12
12
|
required: true,
|
|
13
13
|
defaultValue: '',
|
|
14
14
|
helperText: 'e.g. enter a youtube url, google map, etc',
|
|
15
|
-
onChange: serializeFn(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if (
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
15
|
+
onChange: serializeFn(
|
|
16
|
+
(options: Map<string, any>): void | Promise<void> => {
|
|
17
|
+
const url = options.get('url');
|
|
18
|
+
if (url) {
|
|
19
|
+
options.set('content', 'Loading...');
|
|
20
|
+
// TODO: get this out of here!
|
|
21
|
+
const apiKey = 'ae0e60e78201a3f2b0de4b';
|
|
22
|
+
return fetch(
|
|
23
|
+
`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`
|
|
24
|
+
)
|
|
25
|
+
.then((res) => res.json())
|
|
26
|
+
.then((data) => {
|
|
27
|
+
if (options.get('url') === url) {
|
|
28
|
+
if (data.html) {
|
|
29
|
+
options.set('content', data.html);
|
|
30
|
+
} else {
|
|
31
|
+
options.set('content', 'Invalid url, please try another');
|
|
32
|
+
}
|
|
31
33
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
34
|
+
})
|
|
35
|
+
.catch((_err) => {
|
|
36
|
+
options.set(
|
|
37
|
+
'content',
|
|
38
|
+
'There was an error embedding this URL, please try again or another URL'
|
|
39
|
+
);
|
|
40
|
+
});
|
|
41
|
+
} else {
|
|
42
|
+
options.delete('content');
|
|
43
|
+
}
|
|
42
44
|
}
|
|
43
|
-
|
|
45
|
+
),
|
|
44
46
|
},
|
|
45
47
|
{
|
|
46
48
|
name: 'content',
|
|
@@ -5,8 +5,6 @@
|
|
|
5
5
|
</script>
|
|
6
6
|
|
|
7
7
|
<script lang="ts">
|
|
8
|
-
import { afterUpdate } from "svelte";
|
|
9
|
-
|
|
10
8
|
import { isJsScript } from "./helpers.js";
|
|
11
9
|
|
|
12
10
|
export let content: EmbedProps["content"];
|
|
@@ -48,4 +46,4 @@
|
|
|
48
46
|
$: onUpdateFn_0(...[elem, ranInitFn]);
|
|
49
47
|
</script>
|
|
50
48
|
|
|
51
|
-
<div class="builder-embed" bind:this={elem}>{@html content}</div>
|
|
49
|
+
<div class="builder-embed" bind:this={elem}>{@html content}</div>
|