@builder.io/sdk-svelte 0.1.2 → 0.1.3-1
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 +4 -3
- package/package/CHANGELOG.md +5 -0
- package/package/blocks/BaseText.svelte +1 -1
- package/package/blocks/button/button.svelte +2 -2
- 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 +2 -2
- package/package/blocks/fragment/fragment.svelte +1 -1
- package/package/blocks/image/image.svelte +1 -2
- package/package/blocks/img/img.svelte +2 -2
- package/package/blocks/input/input.svelte +2 -2
- package/package/blocks/raw-text/raw-text.svelte +1 -1
- package/package/blocks/section/section.svelte +2 -2
- package/package/blocks/select/select.svelte +2 -2
- package/package/blocks/submit-button/submit-button.svelte +2 -2
- package/package/blocks/symbol/symbol.svelte +5 -3
- package/package/blocks/text/text.svelte +1 -1
- package/package/blocks/textarea/textarea.svelte +2 -2
- package/package/blocks/video/video.svelte +2 -2
- 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 +60 -54
- 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/functions/track/interaction.d.ts +13 -0
- package/package/functions/track/interaction.js +54 -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 +2 -7
- package/src/blocks/columns/columns.svelte +3 -3
- package/src/blocks/custom-code/custom-code.svelte +1 -1
- package/src/blocks/embed/embed.svelte +1 -3
- package/src/blocks/form/form.svelte +3 -8
- package/src/blocks/fragment/fragment.svelte +1 -1
- package/src/blocks/image/image.svelte +1 -2
- package/src/blocks/img/img.svelte +2 -7
- package/src/blocks/input/input.svelte +2 -7
- package/src/blocks/raw-text/raw-text.svelte +1 -1
- package/src/blocks/section/section.svelte +2 -7
- package/src/blocks/select/select.svelte +2 -7
- package/src/blocks/submit-button/submit-button.svelte +2 -7
- package/src/blocks/symbol/symbol.svelte +6 -9
- package/src/blocks/text/text.svelte +1 -1
- package/src/blocks/textarea/textarea.svelte +2 -7
- package/src/blocks/video/video.svelte +2 -7
- 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 +66 -65
- 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/functions/track/interaction.ts +80 -0
- 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
|
@@ -44,11 +44,11 @@ function getCssFromFont(font) {
|
|
|
44
44
|
}
|
|
45
45
|
function getFontCss({ customFonts }) {
|
|
46
46
|
// TODO: flag for this
|
|
47
|
-
// if (!builder.allowCustomFonts) {
|
|
47
|
+
// if (!this.builder.allowCustomFonts) {
|
|
48
48
|
// return '';
|
|
49
49
|
// }
|
|
50
50
|
// TODO: separate internal data from external
|
|
51
|
-
return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
|
|
51
|
+
return (customFonts?.map((font) => this.getCssFromFont(font))?.join(" ") || "");
|
|
52
52
|
}
|
|
53
53
|
$: injectedStyles = () => {
|
|
54
54
|
return `
|
|
@@ -59,4 +59,4 @@ ${getFontCss({
|
|
|
59
59
|
};
|
|
60
60
|
</script>
|
|
61
61
|
|
|
62
|
-
<RenderInlinedStyles styles={injectedStyles()} />
|
|
62
|
+
<RenderInlinedStyles styles={injectedStyles()} />
|
|
@@ -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,12 +10,13 @@ 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
18
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
19
|
+
import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
|
|
19
20
|
export let content;
|
|
20
21
|
export let data;
|
|
21
22
|
export let canTrack;
|
|
@@ -25,7 +26,7 @@ export let customComponents;
|
|
|
25
26
|
export let model;
|
|
26
27
|
export let apiKey;
|
|
27
28
|
export let includeRefs;
|
|
28
|
-
setContext(
|
|
29
|
+
setContext(builderContext.key, {
|
|
29
30
|
get content() {
|
|
30
31
|
return useContent();
|
|
31
32
|
},
|
|
@@ -33,13 +34,13 @@ setContext(BuilderContext.key, {
|
|
|
33
34
|
return contentState();
|
|
34
35
|
},
|
|
35
36
|
get context() {
|
|
36
|
-
return contextContext
|
|
37
|
+
return contextContext;
|
|
37
38
|
},
|
|
38
39
|
get apiKey() {
|
|
39
40
|
return apiKey;
|
|
40
41
|
},
|
|
41
42
|
get registeredComponents() {
|
|
42
|
-
return allRegisteredComponents
|
|
43
|
+
return allRegisteredComponents;
|
|
43
44
|
},
|
|
44
45
|
});
|
|
45
46
|
function processMessage(event) {
|
|
@@ -82,28 +83,33 @@ function evaluateJsCode() {
|
|
|
82
83
|
if (jsCode) {
|
|
83
84
|
evaluate({
|
|
84
85
|
code: jsCode,
|
|
85
|
-
context: contextContext
|
|
86
|
+
context: contextContext,
|
|
86
87
|
state: contentState(),
|
|
87
88
|
});
|
|
88
89
|
}
|
|
89
90
|
}
|
|
90
|
-
function onClick(
|
|
91
|
+
function onClick(event) {
|
|
91
92
|
if (useContent()) {
|
|
92
93
|
const variationId = useContent?.()?.testVariationId;
|
|
93
94
|
const contentId = useContent?.()?.id;
|
|
94
95
|
_track({
|
|
95
96
|
type: "click",
|
|
96
|
-
canTrack: canTrackToUse
|
|
97
|
+
canTrack: canTrackToUse,
|
|
97
98
|
contentId,
|
|
98
99
|
apiKey: apiKey,
|
|
99
100
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
101
|
+
...getInteractionPropertiesForEvent(event),
|
|
102
|
+
unique: !clicked,
|
|
100
103
|
});
|
|
101
104
|
}
|
|
105
|
+
if (!clicked) {
|
|
106
|
+
clicked = true;
|
|
107
|
+
}
|
|
102
108
|
}
|
|
103
109
|
function evalExpression(expression) {
|
|
104
110
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
105
111
|
code: group,
|
|
106
|
-
context: contextContext
|
|
112
|
+
context: contextContext,
|
|
107
113
|
state: contentState(),
|
|
108
114
|
}));
|
|
109
115
|
}
|
|
@@ -124,7 +130,7 @@ function handleRequest({ url, key }) {
|
|
|
124
130
|
function runHttpRequests() {
|
|
125
131
|
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
126
132
|
Object.entries(requests).forEach(([key, url]) => {
|
|
127
|
-
if (url && (!httpReqsData
|
|
133
|
+
if (url && (!httpReqsData[key] || isEditing())) {
|
|
128
134
|
const evaluatedUrl = evalExpression(url);
|
|
129
135
|
handleRequest({
|
|
130
136
|
url: evaluatedUrl,
|
|
@@ -149,7 +155,7 @@ $: useContent = () => {
|
|
|
149
155
|
if (!content && !overrideContent) {
|
|
150
156
|
return undefined;
|
|
151
157
|
}
|
|
152
|
-
|
|
158
|
+
return {
|
|
153
159
|
...content,
|
|
154
160
|
...overrideContent,
|
|
155
161
|
data: {
|
|
@@ -165,10 +171,6 @@ $: useContent = () => {
|
|
|
165
171
|
content?.meta?.breakpoints,
|
|
166
172
|
},
|
|
167
173
|
};
|
|
168
|
-
return mergedContent;
|
|
169
|
-
};
|
|
170
|
-
$: canTrackToUse = () => {
|
|
171
|
-
return checkIsDefined(canTrack) ? canTrack : true;
|
|
172
174
|
};
|
|
173
175
|
$: contentState = () => {
|
|
174
176
|
return {
|
|
@@ -182,29 +184,6 @@ $: contentState = () => {
|
|
|
182
184
|
...overrideState,
|
|
183
185
|
};
|
|
184
186
|
};
|
|
185
|
-
$: contextContext = () => {
|
|
186
|
-
return context || {};
|
|
187
|
-
};
|
|
188
|
-
$: allRegisteredComponents = () => {
|
|
189
|
-
const allComponentsArray = [
|
|
190
|
-
...getDefaultRegisteredComponents(),
|
|
191
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
192
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
193
|
-
// existing usage.
|
|
194
|
-
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
195
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
196
|
-
...components,
|
|
197
|
-
...(customComponents || []),
|
|
198
|
-
];
|
|
199
|
-
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
200
|
-
...acc,
|
|
201
|
-
[curr.name]: curr,
|
|
202
|
-
}), {});
|
|
203
|
-
return allComponents;
|
|
204
|
-
};
|
|
205
|
-
$: httpReqsData = () => {
|
|
206
|
-
return {};
|
|
207
|
-
};
|
|
208
187
|
$: shouldRenderContentStyles = () => {
|
|
209
188
|
return Boolean((useContent?.()?.data?.cssCode ||
|
|
210
189
|
useContent?.()?.data?.customFonts?.length) &&
|
|
@@ -215,7 +194,24 @@ let forceReRenderCount = 0;
|
|
|
215
194
|
let overrideContent = null;
|
|
216
195
|
let update = 0;
|
|
217
196
|
let useBreakpoints = null;
|
|
197
|
+
let canTrackToUse = checkIsDefined(canTrack) ? canTrack : true;
|
|
218
198
|
let overrideState = {};
|
|
199
|
+
let contextContext = context || {};
|
|
200
|
+
let allRegisteredComponents = [
|
|
201
|
+
...getDefaultRegisteredComponents(),
|
|
202
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
203
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
204
|
+
// existing usage.
|
|
205
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
206
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
207
|
+
...components,
|
|
208
|
+
...(customComponents || []),
|
|
209
|
+
].reduce((acc, curr) => ({
|
|
210
|
+
...acc,
|
|
211
|
+
[curr.name]: curr,
|
|
212
|
+
}), {});
|
|
213
|
+
let httpReqsData = {};
|
|
214
|
+
let clicked = false;
|
|
219
215
|
onMount(() => {
|
|
220
216
|
if (!apiKey) {
|
|
221
217
|
console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
@@ -236,7 +232,7 @@ onMount(() => {
|
|
|
236
232
|
}
|
|
237
233
|
: {}),
|
|
238
234
|
});
|
|
239
|
-
Object.values(allRegisteredComponents
|
|
235
|
+
Object.values(allRegisteredComponents).forEach((registeredComponent) => {
|
|
240
236
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
241
237
|
window.parent?.postMessage(message, "*");
|
|
242
238
|
});
|
|
@@ -248,7 +244,7 @@ onMount(() => {
|
|
|
248
244
|
const contentId = useContent?.()?.id;
|
|
249
245
|
_track({
|
|
250
246
|
type: "impression",
|
|
251
|
-
canTrack: canTrackToUse
|
|
247
|
+
canTrack: canTrackToUse,
|
|
252
248
|
contentId,
|
|
253
249
|
apiKey: apiKey,
|
|
254
250
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
@@ -257,18 +253,28 @@ onMount(() => {
|
|
|
257
253
|
// override normal content in preview mode
|
|
258
254
|
if (isPreviewing()) {
|
|
259
255
|
const searchParams = new URL(location.href).searchParams;
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
256
|
+
const searchParamPreview = searchParams.get("builder.preview");
|
|
257
|
+
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
258
|
+
/**
|
|
259
|
+
* Make sure that:
|
|
260
|
+
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
|
|
261
|
+
* at the same time, e.g. header/page/footer.
|
|
262
|
+
* - the API key is the same, since we don't want to preview content from other organizations.
|
|
263
|
+
*
|
|
264
|
+
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
265
|
+
* this break scenarios where the item is not published yet?
|
|
266
|
+
*
|
|
267
|
+
* TO-DO: should we only update the state when there is a change?
|
|
268
|
+
**/
|
|
269
|
+
if (searchParamPreview === model && previewApiKey === apiKey) {
|
|
270
|
+
getContent({
|
|
271
|
+
model: model,
|
|
272
|
+
apiKey: apiKey,
|
|
273
|
+
}).then((content) => {
|
|
274
|
+
if (content) {
|
|
275
|
+
overrideContent = content;
|
|
276
|
+
}
|
|
277
|
+
});
|
|
272
278
|
}
|
|
273
279
|
}
|
|
274
280
|
evaluateJsCode();
|
|
@@ -316,4 +322,4 @@ onDestroy(() => {
|
|
|
316
322
|
key={forceReRenderCount}
|
|
317
323
|
/>
|
|
318
324
|
</div>
|
|
319
|
-
{/if}
|
|
325
|
+
{/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
|
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
declare type Offset = {
|
|
2
|
+
x: number;
|
|
3
|
+
y: number;
|
|
4
|
+
};
|
|
5
|
+
export declare const getInteractionPropertiesForEvent: (event: MouseEvent) => {
|
|
6
|
+
targetBuilderElement: string | undefined;
|
|
7
|
+
metadata: {
|
|
8
|
+
targetOffset: Offset | undefined;
|
|
9
|
+
builderTargetOffset: Offset | undefined;
|
|
10
|
+
builderElementIndex: number | undefined;
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
function round(num) {
|
|
2
|
+
return Math.round(num * 1000) / 1000;
|
|
3
|
+
}
|
|
4
|
+
const findParentElement = (target, callback, checkElement = true) => {
|
|
5
|
+
if (!(target instanceof HTMLElement)) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
let parent = checkElement ? target : target.parentElement;
|
|
9
|
+
do {
|
|
10
|
+
if (!parent) {
|
|
11
|
+
return null;
|
|
12
|
+
}
|
|
13
|
+
const matches = callback(parent);
|
|
14
|
+
if (matches) {
|
|
15
|
+
return parent;
|
|
16
|
+
}
|
|
17
|
+
} while ((parent = parent.parentElement));
|
|
18
|
+
return null;
|
|
19
|
+
};
|
|
20
|
+
const findBuilderParent = (target) => findParentElement(target, (el) => {
|
|
21
|
+
const id = el.getAttribute('builder-id') || el.id;
|
|
22
|
+
return Boolean(id?.indexOf('builder-') === 0);
|
|
23
|
+
});
|
|
24
|
+
const computeOffset = ({ event, target, }) => {
|
|
25
|
+
const targetRect = target.getBoundingClientRect();
|
|
26
|
+
const xOffset = event.clientX - targetRect.left;
|
|
27
|
+
const yOffset = event.clientY - targetRect.top;
|
|
28
|
+
const xRatio = round(xOffset / targetRect.width);
|
|
29
|
+
const yRatio = round(yOffset / targetRect.height);
|
|
30
|
+
return {
|
|
31
|
+
x: xRatio,
|
|
32
|
+
y: yRatio,
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
export const getInteractionPropertiesForEvent = (event) => {
|
|
36
|
+
const target = event.target;
|
|
37
|
+
const targetBuilderElement = target && findBuilderParent(target);
|
|
38
|
+
const builderId = targetBuilderElement?.getAttribute('builder-id') ||
|
|
39
|
+
targetBuilderElement?.id;
|
|
40
|
+
return {
|
|
41
|
+
targetBuilderElement: builderId || undefined,
|
|
42
|
+
metadata: {
|
|
43
|
+
targetOffset: target ? computeOffset({ event, target }) : undefined,
|
|
44
|
+
builderTargetOffset: targetBuilderElement
|
|
45
|
+
? computeOffset({ event, target: targetBuilderElement })
|
|
46
|
+
: undefined,
|
|
47
|
+
builderElementIndex: targetBuilderElement && builderId
|
|
48
|
+
? [].slice
|
|
49
|
+
.call(document.getElementsByClassName(builderId))
|
|
50
|
+
.indexOf(targetBuilderElement)
|
|
51
|
+
: undefined,
|
|
52
|
+
},
|
|
53
|
+
};
|
|
54
|
+
};
|
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,8 +10,7 @@
|
|
|
10
10
|
<script lang="ts">
|
|
11
11
|
const isEvent = (attr) => attr.startsWith("on:");
|
|
12
12
|
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
13
|
-
|
|
14
|
-
const filterAttrs = (attrs, filter) => {
|
|
13
|
+
const filterAttrs = (attrs = {}, filter) => {
|
|
15
14
|
const validAttr = {};
|
|
16
15
|
Object.keys(attrs).forEach((attr) => {
|
|
17
16
|
if (filter(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>
|
|
@@ -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>
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
</script>
|
|
59
59
|
|
|
60
60
|
<script lang="ts">
|
|
61
|
-
import { getContext
|
|
61
|
+
import { getContext } from "svelte";
|
|
62
62
|
|
|
63
63
|
import RenderBlock from "../../components/render-block/render-block.svelte";
|
|
64
64
|
import BuilderBlocks from "../../components/render-blocks.svelte";
|
|
@@ -66,8 +66,7 @@
|
|
|
66
66
|
|
|
67
67
|
const isEvent = (attr) => attr.startsWith("on:");
|
|
68
68
|
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
69
|
-
|
|
70
|
-
const filterAttrs = (attrs, filter) => {
|
|
69
|
+
const filterAttrs = (attrs = {}, filter) => {
|
|
71
70
|
const validAttr = {};
|
|
72
71
|
Object.keys(attrs).forEach((attr) => {
|
|
73
72
|
if (filter(attr)) {
|
|
@@ -76,16 +75,12 @@
|
|
|
76
75
|
});
|
|
77
76
|
return validAttr;
|
|
78
77
|
};
|
|
79
|
-
|
|
80
78
|
const setAttrs = (node, attrs) => {
|
|
81
79
|
const attrKeys = Object.keys(attrs);
|
|
82
|
-
|
|
83
80
|
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
84
81
|
const teardown = (attr) =>
|
|
85
82
|
node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
86
|
-
|
|
87
83
|
attrKeys.map(setup);
|
|
88
|
-
|
|
89
84
|
return {
|
|
90
85
|
update(attrs) {
|
|
91
86
|
const attrKeys = Object.keys(attrs);
|
|
@@ -364,4 +359,4 @@
|
|
|
364
359
|
color: red;
|
|
365
360
|
text-align: center;
|
|
366
361
|
}
|
|
367
|
-
</style>
|
|
362
|
+
</style>
|
|
@@ -106,7 +106,6 @@
|
|
|
106
106
|
srcset={srcSetToUse()}
|
|
107
107
|
{sizes}
|
|
108
108
|
/>
|
|
109
|
-
<source srcset={srcSetToUse()} />
|
|
110
109
|
</picture>
|
|
111
110
|
|
|
112
111
|
{#if aspectRatio && !(builderBlock?.children?.length && fitContent)}
|
|
@@ -150,4 +149,4 @@
|
|
|
150
149
|
width: 100%;
|
|
151
150
|
height: 100%;
|
|
152
151
|
}
|
|
153
|
-
</style>
|
|
152
|
+
</style>
|
|
@@ -23,8 +23,7 @@
|
|
|
23
23
|
|
|
24
24
|
const isEvent = (attr) => attr.startsWith("on:");
|
|
25
25
|
const isNonEvent = (attr) => !attr.startsWith("on:");
|
|
26
|
-
|
|
27
|
-
const filterAttrs = (attrs, filter) => {
|
|
26
|
+
const filterAttrs = (attrs = {}, filter) => {
|
|
28
27
|
const validAttr = {};
|
|
29
28
|
Object.keys(attrs).forEach((attr) => {
|
|
30
29
|
if (filter(attr)) {
|
|
@@ -33,16 +32,12 @@
|
|
|
33
32
|
});
|
|
34
33
|
return validAttr;
|
|
35
34
|
};
|
|
36
|
-
|
|
37
35
|
const setAttrs = (node, attrs) => {
|
|
38
36
|
const attrKeys = Object.keys(attrs);
|
|
39
|
-
|
|
40
37
|
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
41
38
|
const teardown = (attr) =>
|
|
42
39
|
node.removeEventListener(attr.substr(3), attrs[attr]);
|
|
43
|
-
|
|
44
40
|
attrKeys.map(setup);
|
|
45
|
-
|
|
46
41
|
return {
|
|
47
42
|
update(attrs) {
|
|
48
43
|
const attrKeys = Object.keys(attrs);
|
|
@@ -83,4 +78,4 @@
|
|
|
83
78
|
src={imgSrc || image}
|
|
84
79
|
{...filterAttrs(attributes, isNonEvent)}
|
|
85
80
|
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
86
|
-
/>
|
|
81
|
+
/>
|