@builder.io/sdk-svelte 1.0.21 → 1.0.23
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/components/block/animator.d.ts +1 -1
- package/lib/browser/components/block/animator.js +1 -35
- package/lib/browser/components/block/block.svelte +1 -3
- package/lib/browser/components/block/components/block-styles.svelte +24 -1
- package/lib/browser/components/content/components/enable-editor.svelte +5 -2
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/evaluate/evaluate.js +0 -1
- package/lib/browser/functions/is-editing.js +3 -1
- package/lib/browser/functions/is-previewing.d.ts +1 -1
- package/lib/browser/functions/is-previewing.js +8 -7
- package/lib/edge/components/block/animator.d.ts +1 -1
- package/lib/edge/components/block/animator.js +1 -35
- package/lib/edge/components/block/block.svelte +1 -3
- package/lib/edge/components/block/components/block-styles.svelte +24 -1
- package/lib/edge/components/content/components/enable-editor.svelte +5 -2
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/evaluate/evaluate.js +0 -1
- package/lib/edge/functions/is-editing.js +3 -1
- package/lib/edge/functions/is-previewing.d.ts +1 -1
- package/lib/edge/functions/is-previewing.js +8 -7
- package/lib/node/components/block/animator.d.ts +1 -1
- package/lib/node/components/block/animator.js +1 -35
- package/lib/node/components/block/block.svelte +1 -3
- package/lib/node/components/block/components/block-styles.svelte +24 -1
- package/lib/node/components/content/components/enable-editor.svelte +5 -2
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/evaluate/evaluate.js +0 -1
- package/lib/node/functions/is-editing.js +3 -1
- package/lib/node/functions/is-previewing.d.ts +1 -1
- package/lib/node/functions/is-previewing.js +8 -7
- package/package.json +1 -1
- package/src/components/block/animator.ts +1 -35
- package/src/components/block/block.svelte +4 -6
- package/src/components/block/components/block-styles.svelte +27 -1
- package/src/components/content/components/enable-editor.svelte +5 -2
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/evaluate/evaluate.ts +0 -1
- package/src/functions/is-editing.ts +3 -1
- package/src/functions/is-previewing.ts +9 -7
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderAnimation } from '../../types/builder-block';
|
|
2
|
+
export declare const camelCaseToKebabCase: (str?: string) => string;
|
|
2
3
|
export declare function bindAnimations(animations: BuilderAnimation[]): void;
|
|
3
4
|
export declare function triggerAnimation(animation: BuilderAnimation): void;
|
|
4
|
-
export declare function bindHoverAnimation(animation: BuilderAnimation): void;
|
|
5
5
|
export declare function bindScrollInViewAnimation(animation: BuilderAnimation): void;
|
|
@@ -54,16 +54,13 @@ function assign(target, ..._args) {
|
|
|
54
54
|
}
|
|
55
55
|
return to;
|
|
56
56
|
}
|
|
57
|
-
const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
57
|
+
export const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
58
58
|
export function bindAnimations(animations) {
|
|
59
59
|
for (const animation of animations) {
|
|
60
60
|
switch (animation.trigger) {
|
|
61
61
|
case 'pageLoad':
|
|
62
62
|
triggerAnimation(animation);
|
|
63
63
|
break;
|
|
64
|
-
case 'hover':
|
|
65
|
-
bindHoverAnimation(animation);
|
|
66
|
-
break;
|
|
67
64
|
case 'scrollInView':
|
|
68
65
|
bindScrollInViewAnimation(animation);
|
|
69
66
|
break;
|
|
@@ -138,37 +135,6 @@ export function triggerAnimation(animation) {
|
|
|
138
135
|
});
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
|
-
export function bindHoverAnimation(animation) {
|
|
142
|
-
// TODO: is it multiple binding when editing...?
|
|
143
|
-
// TODO: unbind on element remove
|
|
144
|
-
// TODO: apply to ALL elements
|
|
145
|
-
const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
146
|
-
if (!elements.length) {
|
|
147
|
-
warnElementNotPresent(animation.elementId || animation.id || '');
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
Array.from(elements).forEach(element => {
|
|
151
|
-
augmentAnimation(animation, element);
|
|
152
|
-
const defaultState = animation.steps[0].styles;
|
|
153
|
-
const hoverState = animation.steps[1].styles;
|
|
154
|
-
function attachDefaultState() {
|
|
155
|
-
assign(element.style, defaultState);
|
|
156
|
-
}
|
|
157
|
-
function attachHoverState() {
|
|
158
|
-
assign(element.style, hoverState);
|
|
159
|
-
}
|
|
160
|
-
attachDefaultState();
|
|
161
|
-
element.addEventListener('mouseenter', attachHoverState);
|
|
162
|
-
element.addEventListener('mouseleave', attachDefaultState);
|
|
163
|
-
// TODO: queue/batch these timeouts
|
|
164
|
-
setTimeout(() => {
|
|
165
|
-
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
166
|
-
if (animation.delay) {
|
|
167
|
-
element.style.transitionDelay = animation.delay + 's';
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
138
|
// TODO: unbind on element remove
|
|
173
139
|
export function bindScrollInViewAnimation(animation) {
|
|
174
140
|
// TODO: apply to ALL matching elements
|
|
@@ -104,9 +104,7 @@ onMount(() => {
|
|
|
104
104
|
const blockId = processedBlock().id;
|
|
105
105
|
const animations = processedBlock().animations;
|
|
106
106
|
if (animations && blockId) {
|
|
107
|
-
bindAnimations(animations
|
|
108
|
-
.filter((item) => item.trigger !== "hover")
|
|
109
|
-
.map((animation) => ({
|
|
107
|
+
bindAnimations(animations.map((animation) => ({
|
|
110
108
|
...animation,
|
|
111
109
|
elementId: blockId,
|
|
112
110
|
})));
|
|
@@ -6,6 +6,7 @@ import { getProcessedBlock } from "../../../functions/get-processed-block";
|
|
|
6
6
|
import { createCssClass } from "../../../helpers/css";
|
|
7
7
|
import { checkIsDefined } from "../../../helpers/nullable";
|
|
8
8
|
import InlinedStyles from "../../inlined-styles.svelte";
|
|
9
|
+
import { camelCaseToKebabCase } from "../animator";
|
|
9
10
|
export let block;
|
|
10
11
|
export let context;
|
|
11
12
|
$: canShowBlock = () => {
|
|
@@ -65,7 +66,29 @@ $: css = () => {
|
|
|
65
66
|
mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
|
|
66
67
|
})
|
|
67
68
|
: "";
|
|
68
|
-
|
|
69
|
+
const hoverAnimation = processedBlock.animations &&
|
|
70
|
+
processedBlock.animations.find((item) => item.trigger === "hover");
|
|
71
|
+
let hoverStylesClass = "";
|
|
72
|
+
if (hoverAnimation) {
|
|
73
|
+
const hoverStyles = hoverAnimation.steps?.[1]?.styles || {};
|
|
74
|
+
hoverStylesClass =
|
|
75
|
+
createCssClass({
|
|
76
|
+
className: `${className}:hover`,
|
|
77
|
+
styles: {
|
|
78
|
+
...hoverStyles,
|
|
79
|
+
transition: `all ${hoverAnimation.duration}s ${camelCaseToKebabCase(hoverAnimation.easing)}`,
|
|
80
|
+
transitionDelay: hoverAnimation.delay
|
|
81
|
+
? `${hoverAnimation.delay}s`
|
|
82
|
+
: "0s",
|
|
83
|
+
},
|
|
84
|
+
}) || "";
|
|
85
|
+
}
|
|
86
|
+
return [
|
|
87
|
+
largeStylesClass,
|
|
88
|
+
mediumStylesClass,
|
|
89
|
+
smallStylesClass,
|
|
90
|
+
hoverStylesClass,
|
|
91
|
+
].join(" ");
|
|
69
92
|
};
|
|
70
93
|
</script>
|
|
71
94
|
|
|
@@ -249,8 +249,11 @@ onMount(() => {
|
|
|
249
249
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Override normal content in preview mode.
|
|
254
|
+
* We ignore this when editing, since the edited content is already being sent from the editor via post messages.
|
|
255
|
+
*/
|
|
256
|
+
if (isPreviewing() && !isEditing()) {
|
|
254
257
|
if (elementRef) {
|
|
255
258
|
elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
|
|
256
259
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.23";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.23";
|
|
@@ -27,7 +27,6 @@ class EvalCache {
|
|
|
27
27
|
}
|
|
28
28
|
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
|
|
29
29
|
if (code === '') {
|
|
30
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
31
30
|
return undefined;
|
|
32
31
|
}
|
|
33
32
|
const args = {
|
|
@@ -2,5 +2,7 @@ import { TARGET } from '../constants/target';
|
|
|
2
2
|
import { getSearchString } from '../helpers/search/search';
|
|
3
3
|
import { isIframe } from './is-iframe';
|
|
4
4
|
export function isEditing(search) {
|
|
5
|
-
return isIframe() && (TARGET === 'reactNative' ||
|
|
5
|
+
return isIframe() && (TARGET === 'reactNative' ||
|
|
6
|
+
// accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
|
|
7
|
+
getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
|
|
6
8
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Search } from '../helpers/search/search';
|
|
2
|
-
export declare function isPreviewing(
|
|
2
|
+
export declare function isPreviewing(_search?: Search): boolean;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { getSearchString } from '../helpers/search/search';
|
|
2
2
|
import { isBrowser } from './is-browser';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
3
|
+
export function isPreviewing(_search) {
|
|
4
|
+
const search = _search || (isBrowser() ? window.location.search : undefined);
|
|
5
|
+
/**
|
|
6
|
+
* If this function is called on the server without an explicit `search` argument,
|
|
7
|
+
* then it can't check if the user is previewing, and will return `false`.
|
|
8
|
+
*/
|
|
9
|
+
if (!search) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
+
const normalizedSearch = getSearchString(search);
|
|
12
13
|
return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
|
|
13
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderAnimation } from '../../types/builder-block';
|
|
2
|
+
export declare const camelCaseToKebabCase: (str?: string) => string;
|
|
2
3
|
export declare function bindAnimations(animations: BuilderAnimation[]): void;
|
|
3
4
|
export declare function triggerAnimation(animation: BuilderAnimation): void;
|
|
4
|
-
export declare function bindHoverAnimation(animation: BuilderAnimation): void;
|
|
5
5
|
export declare function bindScrollInViewAnimation(animation: BuilderAnimation): void;
|
|
@@ -54,16 +54,13 @@ function assign(target, ..._args) {
|
|
|
54
54
|
}
|
|
55
55
|
return to;
|
|
56
56
|
}
|
|
57
|
-
const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
57
|
+
export const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
58
58
|
export function bindAnimations(animations) {
|
|
59
59
|
for (const animation of animations) {
|
|
60
60
|
switch (animation.trigger) {
|
|
61
61
|
case 'pageLoad':
|
|
62
62
|
triggerAnimation(animation);
|
|
63
63
|
break;
|
|
64
|
-
case 'hover':
|
|
65
|
-
bindHoverAnimation(animation);
|
|
66
|
-
break;
|
|
67
64
|
case 'scrollInView':
|
|
68
65
|
bindScrollInViewAnimation(animation);
|
|
69
66
|
break;
|
|
@@ -138,37 +135,6 @@ export function triggerAnimation(animation) {
|
|
|
138
135
|
});
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
|
-
export function bindHoverAnimation(animation) {
|
|
142
|
-
// TODO: is it multiple binding when editing...?
|
|
143
|
-
// TODO: unbind on element remove
|
|
144
|
-
// TODO: apply to ALL elements
|
|
145
|
-
const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
146
|
-
if (!elements.length) {
|
|
147
|
-
warnElementNotPresent(animation.elementId || animation.id || '');
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
Array.from(elements).forEach(element => {
|
|
151
|
-
augmentAnimation(animation, element);
|
|
152
|
-
const defaultState = animation.steps[0].styles;
|
|
153
|
-
const hoverState = animation.steps[1].styles;
|
|
154
|
-
function attachDefaultState() {
|
|
155
|
-
assign(element.style, defaultState);
|
|
156
|
-
}
|
|
157
|
-
function attachHoverState() {
|
|
158
|
-
assign(element.style, hoverState);
|
|
159
|
-
}
|
|
160
|
-
attachDefaultState();
|
|
161
|
-
element.addEventListener('mouseenter', attachHoverState);
|
|
162
|
-
element.addEventListener('mouseleave', attachDefaultState);
|
|
163
|
-
// TODO: queue/batch these timeouts
|
|
164
|
-
setTimeout(() => {
|
|
165
|
-
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
166
|
-
if (animation.delay) {
|
|
167
|
-
element.style.transitionDelay = animation.delay + 's';
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
138
|
// TODO: unbind on element remove
|
|
173
139
|
export function bindScrollInViewAnimation(animation) {
|
|
174
140
|
// TODO: apply to ALL matching elements
|
|
@@ -104,9 +104,7 @@ onMount(() => {
|
|
|
104
104
|
const blockId = processedBlock().id;
|
|
105
105
|
const animations = processedBlock().animations;
|
|
106
106
|
if (animations && blockId) {
|
|
107
|
-
bindAnimations(animations
|
|
108
|
-
.filter((item) => item.trigger !== "hover")
|
|
109
|
-
.map((animation) => ({
|
|
107
|
+
bindAnimations(animations.map((animation) => ({
|
|
110
108
|
...animation,
|
|
111
109
|
elementId: blockId,
|
|
112
110
|
})));
|
|
@@ -6,6 +6,7 @@ import { getProcessedBlock } from "../../../functions/get-processed-block";
|
|
|
6
6
|
import { createCssClass } from "../../../helpers/css";
|
|
7
7
|
import { checkIsDefined } from "../../../helpers/nullable";
|
|
8
8
|
import InlinedStyles from "../../inlined-styles.svelte";
|
|
9
|
+
import { camelCaseToKebabCase } from "../animator";
|
|
9
10
|
export let block;
|
|
10
11
|
export let context;
|
|
11
12
|
$: canShowBlock = () => {
|
|
@@ -65,7 +66,29 @@ $: css = () => {
|
|
|
65
66
|
mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
|
|
66
67
|
})
|
|
67
68
|
: "";
|
|
68
|
-
|
|
69
|
+
const hoverAnimation = processedBlock.animations &&
|
|
70
|
+
processedBlock.animations.find((item) => item.trigger === "hover");
|
|
71
|
+
let hoverStylesClass = "";
|
|
72
|
+
if (hoverAnimation) {
|
|
73
|
+
const hoverStyles = hoverAnimation.steps?.[1]?.styles || {};
|
|
74
|
+
hoverStylesClass =
|
|
75
|
+
createCssClass({
|
|
76
|
+
className: `${className}:hover`,
|
|
77
|
+
styles: {
|
|
78
|
+
...hoverStyles,
|
|
79
|
+
transition: `all ${hoverAnimation.duration}s ${camelCaseToKebabCase(hoverAnimation.easing)}`,
|
|
80
|
+
transitionDelay: hoverAnimation.delay
|
|
81
|
+
? `${hoverAnimation.delay}s`
|
|
82
|
+
: "0s",
|
|
83
|
+
},
|
|
84
|
+
}) || "";
|
|
85
|
+
}
|
|
86
|
+
return [
|
|
87
|
+
largeStylesClass,
|
|
88
|
+
mediumStylesClass,
|
|
89
|
+
smallStylesClass,
|
|
90
|
+
hoverStylesClass,
|
|
91
|
+
].join(" ");
|
|
69
92
|
};
|
|
70
93
|
</script>
|
|
71
94
|
|
|
@@ -249,8 +249,11 @@ onMount(() => {
|
|
|
249
249
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Override normal content in preview mode.
|
|
254
|
+
* We ignore this when editing, since the edited content is already being sent from the editor via post messages.
|
|
255
|
+
*/
|
|
256
|
+
if (isPreviewing() && !isEditing()) {
|
|
254
257
|
if (elementRef) {
|
|
255
258
|
elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
|
|
256
259
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.23";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.23";
|
|
@@ -27,7 +27,6 @@ class EvalCache {
|
|
|
27
27
|
}
|
|
28
28
|
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
|
|
29
29
|
if (code === '') {
|
|
30
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
31
30
|
return undefined;
|
|
32
31
|
}
|
|
33
32
|
const args = {
|
|
@@ -2,5 +2,7 @@ import { TARGET } from '../constants/target';
|
|
|
2
2
|
import { getSearchString } from '../helpers/search/search';
|
|
3
3
|
import { isIframe } from './is-iframe';
|
|
4
4
|
export function isEditing(search) {
|
|
5
|
-
return isIframe() && (TARGET === 'reactNative' ||
|
|
5
|
+
return isIframe() && (TARGET === 'reactNative' ||
|
|
6
|
+
// accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
|
|
7
|
+
getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
|
|
6
8
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Search } from '../helpers/search/search';
|
|
2
|
-
export declare function isPreviewing(
|
|
2
|
+
export declare function isPreviewing(_search?: Search): boolean;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { getSearchString } from '../helpers/search/search';
|
|
2
2
|
import { isBrowser } from './is-browser';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
3
|
+
export function isPreviewing(_search) {
|
|
4
|
+
const search = _search || (isBrowser() ? window.location.search : undefined);
|
|
5
|
+
/**
|
|
6
|
+
* If this function is called on the server without an explicit `search` argument,
|
|
7
|
+
* then it can't check if the user is previewing, and will return `false`.
|
|
8
|
+
*/
|
|
9
|
+
if (!search) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
+
const normalizedSearch = getSearchString(search);
|
|
12
13
|
return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
|
|
13
14
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderAnimation } from '../../types/builder-block';
|
|
2
|
+
export declare const camelCaseToKebabCase: (str?: string) => string;
|
|
2
3
|
export declare function bindAnimations(animations: BuilderAnimation[]): void;
|
|
3
4
|
export declare function triggerAnimation(animation: BuilderAnimation): void;
|
|
4
|
-
export declare function bindHoverAnimation(animation: BuilderAnimation): void;
|
|
5
5
|
export declare function bindScrollInViewAnimation(animation: BuilderAnimation): void;
|
|
@@ -54,16 +54,13 @@ function assign(target, ..._args) {
|
|
|
54
54
|
}
|
|
55
55
|
return to;
|
|
56
56
|
}
|
|
57
|
-
const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
57
|
+
export const camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
58
58
|
export function bindAnimations(animations) {
|
|
59
59
|
for (const animation of animations) {
|
|
60
60
|
switch (animation.trigger) {
|
|
61
61
|
case 'pageLoad':
|
|
62
62
|
triggerAnimation(animation);
|
|
63
63
|
break;
|
|
64
|
-
case 'hover':
|
|
65
|
-
bindHoverAnimation(animation);
|
|
66
|
-
break;
|
|
67
64
|
case 'scrollInView':
|
|
68
65
|
bindScrollInViewAnimation(animation);
|
|
69
66
|
break;
|
|
@@ -138,37 +135,6 @@ export function triggerAnimation(animation) {
|
|
|
138
135
|
});
|
|
139
136
|
});
|
|
140
137
|
}
|
|
141
|
-
export function bindHoverAnimation(animation) {
|
|
142
|
-
// TODO: is it multiple binding when editing...?
|
|
143
|
-
// TODO: unbind on element remove
|
|
144
|
-
// TODO: apply to ALL elements
|
|
145
|
-
const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ''));
|
|
146
|
-
if (!elements.length) {
|
|
147
|
-
warnElementNotPresent(animation.elementId || animation.id || '');
|
|
148
|
-
return;
|
|
149
|
-
}
|
|
150
|
-
Array.from(elements).forEach(element => {
|
|
151
|
-
augmentAnimation(animation, element);
|
|
152
|
-
const defaultState = animation.steps[0].styles;
|
|
153
|
-
const hoverState = animation.steps[1].styles;
|
|
154
|
-
function attachDefaultState() {
|
|
155
|
-
assign(element.style, defaultState);
|
|
156
|
-
}
|
|
157
|
-
function attachHoverState() {
|
|
158
|
-
assign(element.style, hoverState);
|
|
159
|
-
}
|
|
160
|
-
attachDefaultState();
|
|
161
|
-
element.addEventListener('mouseenter', attachHoverState);
|
|
162
|
-
element.addEventListener('mouseleave', attachDefaultState);
|
|
163
|
-
// TODO: queue/batch these timeouts
|
|
164
|
-
setTimeout(() => {
|
|
165
|
-
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
166
|
-
if (animation.delay) {
|
|
167
|
-
element.style.transitionDelay = animation.delay + 's';
|
|
168
|
-
}
|
|
169
|
-
});
|
|
170
|
-
});
|
|
171
|
-
}
|
|
172
138
|
// TODO: unbind on element remove
|
|
173
139
|
export function bindScrollInViewAnimation(animation) {
|
|
174
140
|
// TODO: apply to ALL matching elements
|
|
@@ -104,9 +104,7 @@ onMount(() => {
|
|
|
104
104
|
const blockId = processedBlock().id;
|
|
105
105
|
const animations = processedBlock().animations;
|
|
106
106
|
if (animations && blockId) {
|
|
107
|
-
bindAnimations(animations
|
|
108
|
-
.filter((item) => item.trigger !== "hover")
|
|
109
|
-
.map((animation) => ({
|
|
107
|
+
bindAnimations(animations.map((animation) => ({
|
|
110
108
|
...animation,
|
|
111
109
|
elementId: blockId,
|
|
112
110
|
})));
|
|
@@ -6,6 +6,7 @@ import { getProcessedBlock } from "../../../functions/get-processed-block";
|
|
|
6
6
|
import { createCssClass } from "../../../helpers/css";
|
|
7
7
|
import { checkIsDefined } from "../../../helpers/nullable";
|
|
8
8
|
import InlinedStyles from "../../inlined-styles.svelte";
|
|
9
|
+
import { camelCaseToKebabCase } from "../animator";
|
|
9
10
|
export let block;
|
|
10
11
|
export let context;
|
|
11
12
|
$: canShowBlock = () => {
|
|
@@ -65,7 +66,29 @@ $: css = () => {
|
|
|
65
66
|
mediaQuery: getMaxWidthQueryForSize("small", sizesWithUpdatedBreakpoints),
|
|
66
67
|
})
|
|
67
68
|
: "";
|
|
68
|
-
|
|
69
|
+
const hoverAnimation = processedBlock.animations &&
|
|
70
|
+
processedBlock.animations.find((item) => item.trigger === "hover");
|
|
71
|
+
let hoverStylesClass = "";
|
|
72
|
+
if (hoverAnimation) {
|
|
73
|
+
const hoverStyles = hoverAnimation.steps?.[1]?.styles || {};
|
|
74
|
+
hoverStylesClass =
|
|
75
|
+
createCssClass({
|
|
76
|
+
className: `${className}:hover`,
|
|
77
|
+
styles: {
|
|
78
|
+
...hoverStyles,
|
|
79
|
+
transition: `all ${hoverAnimation.duration}s ${camelCaseToKebabCase(hoverAnimation.easing)}`,
|
|
80
|
+
transitionDelay: hoverAnimation.delay
|
|
81
|
+
? `${hoverAnimation.delay}s`
|
|
82
|
+
: "0s",
|
|
83
|
+
},
|
|
84
|
+
}) || "";
|
|
85
|
+
}
|
|
86
|
+
return [
|
|
87
|
+
largeStylesClass,
|
|
88
|
+
mediumStylesClass,
|
|
89
|
+
smallStylesClass,
|
|
90
|
+
hoverStylesClass,
|
|
91
|
+
].join(" ");
|
|
69
92
|
};
|
|
70
93
|
</script>
|
|
71
94
|
|
|
@@ -249,8 +249,11 @@ onMount(() => {
|
|
|
249
249
|
variationId: variationId !== contentId ? variationId : undefined,
|
|
250
250
|
});
|
|
251
251
|
}
|
|
252
|
-
|
|
253
|
-
|
|
252
|
+
/**
|
|
253
|
+
* Override normal content in preview mode.
|
|
254
|
+
* We ignore this when editing, since the edited content is already being sent from the editor via post messages.
|
|
255
|
+
*/
|
|
256
|
+
if (isPreviewing() && !isEditing()) {
|
|
254
257
|
if (elementRef) {
|
|
255
258
|
elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
|
|
256
259
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.23";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.23";
|
|
@@ -27,7 +27,6 @@ class EvalCache {
|
|
|
27
27
|
}
|
|
28
28
|
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, enableCache }) {
|
|
29
29
|
if (code === '') {
|
|
30
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
31
30
|
return undefined;
|
|
32
31
|
}
|
|
33
32
|
const args = {
|
|
@@ -2,5 +2,7 @@ import { TARGET } from '../constants/target';
|
|
|
2
2
|
import { getSearchString } from '../helpers/search/search';
|
|
3
3
|
import { isIframe } from './is-iframe';
|
|
4
4
|
export function isEditing(search) {
|
|
5
|
-
return isIframe() && (TARGET === 'reactNative' ||
|
|
5
|
+
return isIframe() && (TARGET === 'reactNative' ||
|
|
6
|
+
// accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
|
|
7
|
+
getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
|
|
6
8
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { Search } from '../helpers/search/search';
|
|
2
|
-
export declare function isPreviewing(
|
|
2
|
+
export declare function isPreviewing(_search?: Search): boolean;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { getSearchString } from '../helpers/search/search';
|
|
2
2
|
import { isBrowser } from './is-browser';
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
if (
|
|
3
|
+
export function isPreviewing(_search) {
|
|
4
|
+
const search = _search || (isBrowser() ? window.location.search : undefined);
|
|
5
|
+
/**
|
|
6
|
+
* If this function is called on the server without an explicit `search` argument,
|
|
7
|
+
* then it can't check if the user is previewing, and will return `false`.
|
|
8
|
+
*/
|
|
9
|
+
if (!search) {
|
|
10
10
|
return false;
|
|
11
11
|
}
|
|
12
|
+
const normalizedSearch = getSearchString(search);
|
|
12
13
|
return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
|
|
13
14
|
}
|
package/package.json
CHANGED
|
@@ -52,16 +52,13 @@ function assign(target: object, ..._args: any[]) {
|
|
|
52
52
|
}
|
|
53
53
|
return to;
|
|
54
54
|
}
|
|
55
|
-
const camelCaseToKebabCase = (str?: string) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
55
|
+
export const camelCaseToKebabCase = (str?: string) => str ? str.replace(/([A-Z])/g, g => `-${g[0].toLowerCase()}`) : '';
|
|
56
56
|
export function bindAnimations(animations: BuilderAnimation[]) {
|
|
57
57
|
for (const animation of animations) {
|
|
58
58
|
switch (animation.trigger) {
|
|
59
59
|
case 'pageLoad':
|
|
60
60
|
triggerAnimation(animation);
|
|
61
61
|
break;
|
|
62
|
-
case 'hover':
|
|
63
|
-
bindHoverAnimation(animation);
|
|
64
|
-
break;
|
|
65
62
|
case 'scrollInView':
|
|
66
63
|
bindScrollInViewAnimation(animation);
|
|
67
64
|
break;
|
|
@@ -140,37 +137,6 @@ export function triggerAnimation(animation: BuilderAnimation) {
|
|
|
140
137
|
});
|
|
141
138
|
});
|
|
142
139
|
}
|
|
143
|
-
export function bindHoverAnimation(animation: BuilderAnimation) {
|
|
144
|
-
// TODO: is it multiple binding when editing...?
|
|
145
|
-
// TODO: unbind on element remove
|
|
146
|
-
// TODO: apply to ALL elements
|
|
147
|
-
const elements = (Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || '')) as HTMLElement[]);
|
|
148
|
-
if (!elements.length) {
|
|
149
|
-
warnElementNotPresent(animation.elementId || animation.id || '');
|
|
150
|
-
return;
|
|
151
|
-
}
|
|
152
|
-
Array.from(elements).forEach(element => {
|
|
153
|
-
augmentAnimation(animation, element);
|
|
154
|
-
const defaultState = animation.steps[0].styles;
|
|
155
|
-
const hoverState = animation.steps[1].styles;
|
|
156
|
-
function attachDefaultState() {
|
|
157
|
-
assign(element!.style, defaultState);
|
|
158
|
-
}
|
|
159
|
-
function attachHoverState() {
|
|
160
|
-
assign(element!.style, hoverState);
|
|
161
|
-
}
|
|
162
|
-
attachDefaultState();
|
|
163
|
-
element.addEventListener('mouseenter', attachHoverState);
|
|
164
|
-
element.addEventListener('mouseleave', attachDefaultState);
|
|
165
|
-
// TODO: queue/batch these timeouts
|
|
166
|
-
setTimeout(() => {
|
|
167
|
-
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
168
|
-
if (animation.delay) {
|
|
169
|
-
element.style.transitionDelay = animation.delay + 's';
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
140
|
|
|
175
141
|
// TODO: unbind on element remove
|
|
176
142
|
export function bindScrollInViewAnimation(animation: BuilderAnimation) {
|
|
@@ -131,12 +131,10 @@
|
|
|
131
131
|
const animations = processedBlock().animations;
|
|
132
132
|
if (animations && blockId) {
|
|
133
133
|
bindAnimations(
|
|
134
|
-
animations
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
elementId: blockId,
|
|
139
|
-
}))
|
|
134
|
+
animations.map((animation) => ({
|
|
135
|
+
...animation,
|
|
136
|
+
elementId: blockId,
|
|
137
|
+
}))
|
|
140
138
|
);
|
|
141
139
|
}
|
|
142
140
|
});
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { checkIsDefined } from "../../../helpers/nullable";
|
|
18
18
|
import type { BuilderBlock } from "../../../types/builder-block";
|
|
19
19
|
import InlinedStyles from "../../inlined-styles.svelte";
|
|
20
|
+
import { camelCaseToKebabCase } from "../animator";
|
|
20
21
|
|
|
21
22
|
export let block: BlockStylesProps["block"];
|
|
22
23
|
export let context: BlockStylesProps["context"];
|
|
@@ -86,7 +87,32 @@
|
|
|
86
87
|
),
|
|
87
88
|
})
|
|
88
89
|
: "";
|
|
89
|
-
|
|
90
|
+
const hoverAnimation =
|
|
91
|
+
processedBlock.animations &&
|
|
92
|
+
processedBlock.animations.find((item) => item.trigger === "hover");
|
|
93
|
+
let hoverStylesClass = "";
|
|
94
|
+
if (hoverAnimation) {
|
|
95
|
+
const hoverStyles = hoverAnimation.steps?.[1]?.styles || {};
|
|
96
|
+
hoverStylesClass =
|
|
97
|
+
createCssClass({
|
|
98
|
+
className: `${className}:hover`,
|
|
99
|
+
styles: {
|
|
100
|
+
...hoverStyles,
|
|
101
|
+
transition: `all ${hoverAnimation.duration}s ${camelCaseToKebabCase(
|
|
102
|
+
hoverAnimation.easing
|
|
103
|
+
)}`,
|
|
104
|
+
transitionDelay: hoverAnimation.delay
|
|
105
|
+
? `${hoverAnimation.delay}s`
|
|
106
|
+
: "0s",
|
|
107
|
+
},
|
|
108
|
+
}) || "";
|
|
109
|
+
}
|
|
110
|
+
return [
|
|
111
|
+
largeStylesClass,
|
|
112
|
+
mediumStylesClass,
|
|
113
|
+
smallStylesClass,
|
|
114
|
+
hoverStylesClass,
|
|
115
|
+
].join(" ");
|
|
90
116
|
};
|
|
91
117
|
</script>
|
|
92
118
|
|
|
@@ -306,8 +306,11 @@
|
|
|
306
306
|
});
|
|
307
307
|
}
|
|
308
308
|
|
|
309
|
-
|
|
310
|
-
|
|
309
|
+
/**
|
|
310
|
+
* Override normal content in preview mode.
|
|
311
|
+
* We ignore this when editing, since the edited content is already being sent from the editor via post messages.
|
|
312
|
+
*/
|
|
313
|
+
if (isPreviewing() && !isEditing()) {
|
|
311
314
|
if (elementRef) {
|
|
312
315
|
elementRef.dispatchEvent(new CustomEvent("initpreviewingbldr"));
|
|
313
316
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.23"
|
|
@@ -2,5 +2,7 @@ import { TARGET } from '../constants/target';
|
|
|
2
2
|
import { getSearchString, type Search } from '../helpers/search/search';
|
|
3
3
|
import { isIframe } from './is-iframe';
|
|
4
4
|
export function isEditing(search?: Search) {
|
|
5
|
-
return isIframe() && (TARGET === 'reactNative' ||
|
|
5
|
+
return isIframe() && (TARGET === 'reactNative' ||
|
|
6
|
+
// accessing window.location.search is safe here because `isIframe()` is only `true` if we're in a browser.
|
|
7
|
+
getSearchString(search || window.location.search).indexOf('builder.frameEditing=') !== -1);
|
|
6
8
|
}
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import type { Search } from '../helpers/search/search';
|
|
2
2
|
import { getSearchString } from '../helpers/search/search';
|
|
3
3
|
import { isBrowser } from './is-browser';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
export function isPreviewing(_search?: Search) {
|
|
5
|
+
const search = _search || (isBrowser() ? window.location.search : undefined);
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* If this function is called on the server without an explicit `search` argument,
|
|
9
|
+
* then it can't check if the user is previewing, and will return `false`.
|
|
10
|
+
*/
|
|
11
|
+
if (!search) {
|
|
11
12
|
return false;
|
|
12
13
|
}
|
|
14
|
+
const normalizedSearch = getSearchString(search);
|
|
13
15
|
return Boolean(normalizedSearch.indexOf('builder.preview=') !== -1);
|
|
14
16
|
}
|