@builder.io/sdk-solid 0.12.6 → 0.12.8
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/dist/index.d.ts +125 -84
- package/lib/browser/dev.js +298 -31
- package/lib/browser/dev.jsx +310 -38
- package/lib/browser/index.js +297 -31
- package/lib/browser/index.jsx +309 -38
- package/lib/edge/dev.js +298 -31
- package/lib/edge/dev.jsx +310 -38
- package/lib/edge/index.js +297 -31
- package/lib/edge/index.jsx +309 -38
- package/lib/node/dev.js +298 -31
- package/lib/node/dev.jsx +310 -38
- package/lib/node/index.js +297 -31
- package/lib/node/index.jsx +309 -38
- package/package.json +1 -1
package/lib/edge/index.js
CHANGED
|
@@ -3574,6 +3574,211 @@ function getProcessedBlock({
|
|
|
3574
3574
|
}
|
|
3575
3575
|
}
|
|
3576
3576
|
|
|
3577
|
+
// src/components/block/animator.ts
|
|
3578
|
+
function throttle(func, wait, options = {}) {
|
|
3579
|
+
let context;
|
|
3580
|
+
let args;
|
|
3581
|
+
let result;
|
|
3582
|
+
let timeout = null;
|
|
3583
|
+
let previous = 0;
|
|
3584
|
+
const later = function() {
|
|
3585
|
+
previous = options.leading === false ? 0 : Date.now();
|
|
3586
|
+
timeout = null;
|
|
3587
|
+
result = func.apply(context, args);
|
|
3588
|
+
if (!timeout)
|
|
3589
|
+
context = args = null;
|
|
3590
|
+
};
|
|
3591
|
+
return function() {
|
|
3592
|
+
const now = Date.now();
|
|
3593
|
+
if (!previous && options.leading === false)
|
|
3594
|
+
previous = now;
|
|
3595
|
+
const remaining = wait - (now - previous);
|
|
3596
|
+
context = this;
|
|
3597
|
+
args = arguments;
|
|
3598
|
+
if (remaining <= 0 || remaining > wait) {
|
|
3599
|
+
if (timeout) {
|
|
3600
|
+
clearTimeout(timeout);
|
|
3601
|
+
timeout = null;
|
|
3602
|
+
}
|
|
3603
|
+
previous = now;
|
|
3604
|
+
result = func.apply(context, args);
|
|
3605
|
+
if (!timeout)
|
|
3606
|
+
context = args = null;
|
|
3607
|
+
} else if (!timeout && options.trailing !== false) {
|
|
3608
|
+
timeout = setTimeout(later, remaining);
|
|
3609
|
+
}
|
|
3610
|
+
return result;
|
|
3611
|
+
};
|
|
3612
|
+
}
|
|
3613
|
+
function assign(target, ..._args) {
|
|
3614
|
+
const to = Object(target);
|
|
3615
|
+
for (let index = 1; index < arguments.length; index++) {
|
|
3616
|
+
const nextSource = arguments[index];
|
|
3617
|
+
if (nextSource != null) {
|
|
3618
|
+
for (const nextKey in nextSource) {
|
|
3619
|
+
if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
|
|
3620
|
+
to[nextKey] = nextSource[nextKey];
|
|
3621
|
+
}
|
|
3622
|
+
}
|
|
3623
|
+
}
|
|
3624
|
+
}
|
|
3625
|
+
return to;
|
|
3626
|
+
}
|
|
3627
|
+
var camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
|
|
3628
|
+
function bindAnimations(animations) {
|
|
3629
|
+
for (const animation of animations) {
|
|
3630
|
+
switch (animation.trigger) {
|
|
3631
|
+
case "pageLoad":
|
|
3632
|
+
triggerAnimation(animation);
|
|
3633
|
+
break;
|
|
3634
|
+
case "hover":
|
|
3635
|
+
bindHoverAnimation(animation);
|
|
3636
|
+
break;
|
|
3637
|
+
case "scrollInView":
|
|
3638
|
+
bindScrollInViewAnimation(animation);
|
|
3639
|
+
break;
|
|
3640
|
+
}
|
|
3641
|
+
}
|
|
3642
|
+
}
|
|
3643
|
+
function warnElementNotPresent(id2) {
|
|
3644
|
+
}
|
|
3645
|
+
function augmentAnimation(animation, element) {
|
|
3646
|
+
const stylesUsed = getAllStylesUsed(animation);
|
|
3647
|
+
const computedStyle = getComputedStyle(element);
|
|
3648
|
+
const firstStyles = animation.steps[0].styles;
|
|
3649
|
+
const lastStyles = animation.steps[animation.steps.length - 1].styles;
|
|
3650
|
+
const bothStyles = [firstStyles, lastStyles];
|
|
3651
|
+
for (const styles of bothStyles) {
|
|
3652
|
+
for (const style of stylesUsed) {
|
|
3653
|
+
if (!(style in styles)) {
|
|
3654
|
+
styles[style] = computedStyle[style];
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
}
|
|
3658
|
+
}
|
|
3659
|
+
function getAllStylesUsed(animation) {
|
|
3660
|
+
const properties = [];
|
|
3661
|
+
for (const step of animation.steps) {
|
|
3662
|
+
for (const key in step.styles) {
|
|
3663
|
+
if (properties.indexOf(key) === -1) {
|
|
3664
|
+
properties.push(key);
|
|
3665
|
+
}
|
|
3666
|
+
}
|
|
3667
|
+
}
|
|
3668
|
+
return properties;
|
|
3669
|
+
}
|
|
3670
|
+
function triggerAnimation(animation) {
|
|
3671
|
+
const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
|
|
3672
|
+
if (!elements.length) {
|
|
3673
|
+
warnElementNotPresent(animation.elementId || animation.id || "");
|
|
3674
|
+
return;
|
|
3675
|
+
}
|
|
3676
|
+
Array.from(elements).forEach((element) => {
|
|
3677
|
+
augmentAnimation(animation, element);
|
|
3678
|
+
element.style.transition = "none";
|
|
3679
|
+
element.style.transitionDelay = "0";
|
|
3680
|
+
assign(element.style, animation.steps[0].styles);
|
|
3681
|
+
setTimeout(() => {
|
|
3682
|
+
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
3683
|
+
if (animation.delay) {
|
|
3684
|
+
element.style.transitionDelay = animation.delay + "s";
|
|
3685
|
+
}
|
|
3686
|
+
assign(element.style, animation.steps[1].styles);
|
|
3687
|
+
setTimeout(() => {
|
|
3688
|
+
element.style.transition = "";
|
|
3689
|
+
element.style.transitionDelay = "";
|
|
3690
|
+
}, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
|
|
3691
|
+
});
|
|
3692
|
+
});
|
|
3693
|
+
}
|
|
3694
|
+
function bindHoverAnimation(animation) {
|
|
3695
|
+
const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
|
|
3696
|
+
if (!elements.length) {
|
|
3697
|
+
warnElementNotPresent(animation.elementId || animation.id || "");
|
|
3698
|
+
return;
|
|
3699
|
+
}
|
|
3700
|
+
Array.from(elements).forEach((element) => {
|
|
3701
|
+
augmentAnimation(animation, element);
|
|
3702
|
+
const defaultState = animation.steps[0].styles;
|
|
3703
|
+
const hoverState = animation.steps[1].styles;
|
|
3704
|
+
function attachDefaultState() {
|
|
3705
|
+
assign(element.style, defaultState);
|
|
3706
|
+
}
|
|
3707
|
+
function attachHoverState() {
|
|
3708
|
+
assign(element.style, hoverState);
|
|
3709
|
+
}
|
|
3710
|
+
attachDefaultState();
|
|
3711
|
+
element.addEventListener("mouseenter", attachHoverState);
|
|
3712
|
+
element.addEventListener("mouseleave", attachDefaultState);
|
|
3713
|
+
setTimeout(() => {
|
|
3714
|
+
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
3715
|
+
if (animation.delay) {
|
|
3716
|
+
element.style.transitionDelay = animation.delay + "s";
|
|
3717
|
+
}
|
|
3718
|
+
});
|
|
3719
|
+
});
|
|
3720
|
+
}
|
|
3721
|
+
function bindScrollInViewAnimation(animation) {
|
|
3722
|
+
const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
|
|
3723
|
+
if (!elements.length) {
|
|
3724
|
+
warnElementNotPresent(animation.elementId || animation.id || "");
|
|
3725
|
+
return;
|
|
3726
|
+
}
|
|
3727
|
+
Array.from(elements).forEach((element) => {
|
|
3728
|
+
augmentAnimation(animation, element);
|
|
3729
|
+
let triggered = false;
|
|
3730
|
+
let pendingAnimation = false;
|
|
3731
|
+
function immediateOnScroll() {
|
|
3732
|
+
if (!triggered && isScrolledIntoView(element)) {
|
|
3733
|
+
triggered = true;
|
|
3734
|
+
pendingAnimation = true;
|
|
3735
|
+
setTimeout(() => {
|
|
3736
|
+
assign(element.style, animation.steps[1].styles);
|
|
3737
|
+
if (!animation.repeat) {
|
|
3738
|
+
document.removeEventListener("scroll", onScroll);
|
|
3739
|
+
}
|
|
3740
|
+
setTimeout(() => {
|
|
3741
|
+
pendingAnimation = false;
|
|
3742
|
+
if (!animation.repeat) {
|
|
3743
|
+
element.style.transition = "";
|
|
3744
|
+
element.style.transitionDelay = "";
|
|
3745
|
+
}
|
|
3746
|
+
}, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
|
|
3747
|
+
});
|
|
3748
|
+
} else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
|
|
3749
|
+
triggered = false;
|
|
3750
|
+
assign(element.style, animation.steps[0].styles);
|
|
3751
|
+
}
|
|
3752
|
+
}
|
|
3753
|
+
const onScroll = throttle(immediateOnScroll, 200, {
|
|
3754
|
+
leading: false
|
|
3755
|
+
});
|
|
3756
|
+
function isScrolledIntoView(elem) {
|
|
3757
|
+
const rect = elem.getBoundingClientRect();
|
|
3758
|
+
const windowHeight = window.innerHeight;
|
|
3759
|
+
const thresholdPercent = (animation.thresholdPercent || 0) / 100;
|
|
3760
|
+
const threshold = thresholdPercent * windowHeight;
|
|
3761
|
+
return rect.bottom > threshold && rect.top < windowHeight - threshold;
|
|
3762
|
+
}
|
|
3763
|
+
const defaultState = animation.steps[0].styles;
|
|
3764
|
+
function attachDefaultState() {
|
|
3765
|
+
assign(element.style, defaultState);
|
|
3766
|
+
}
|
|
3767
|
+
attachDefaultState();
|
|
3768
|
+
setTimeout(() => {
|
|
3769
|
+
element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
|
|
3770
|
+
if (animation.delay) {
|
|
3771
|
+
element.style.transitionDelay = animation.delay + "s";
|
|
3772
|
+
}
|
|
3773
|
+
});
|
|
3774
|
+
document.addEventListener("scroll", onScroll, {
|
|
3775
|
+
capture: true,
|
|
3776
|
+
passive: true
|
|
3777
|
+
});
|
|
3778
|
+
immediateOnScroll();
|
|
3779
|
+
});
|
|
3780
|
+
}
|
|
3781
|
+
|
|
3577
3782
|
// src/components/block/block.helpers.ts
|
|
3578
3783
|
var getComponent = ({
|
|
3579
3784
|
block,
|
|
@@ -4146,6 +4351,16 @@ function Block(props) {
|
|
|
4146
4351
|
isInteractive: !blockComponent()?.isRSC
|
|
4147
4352
|
};
|
|
4148
4353
|
}
|
|
4354
|
+
onMount(() => {
|
|
4355
|
+
const blockId = processedBlock().id;
|
|
4356
|
+
const animations = processedBlock().animations;
|
|
4357
|
+
if (animations && blockId) {
|
|
4358
|
+
bindAnimations(animations.filter((item) => item.trigger !== "hover").map((animation) => ({
|
|
4359
|
+
...animation,
|
|
4360
|
+
elementId: blockId
|
|
4361
|
+
})));
|
|
4362
|
+
}
|
|
4363
|
+
});
|
|
4149
4364
|
return createComponent(Show, {
|
|
4150
4365
|
get when() {
|
|
4151
4366
|
return canShowBlock();
|
|
@@ -6294,13 +6509,6 @@ async function fetchEntries(options) {
|
|
|
6294
6509
|
}
|
|
6295
6510
|
var getAllContent = fetchEntries;
|
|
6296
6511
|
|
|
6297
|
-
// src/functions/is-from-trusted-host.ts
|
|
6298
|
-
var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
6299
|
-
function isFromTrustedHost(trustedHosts, e) {
|
|
6300
|
-
const url = new URL(e.origin), hostname = url.hostname;
|
|
6301
|
-
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
6302
|
-
}
|
|
6303
|
-
|
|
6304
6512
|
// src/functions/is-previewing.ts
|
|
6305
6513
|
function isPreviewing() {
|
|
6306
6514
|
if (!isBrowser()) {
|
|
@@ -6548,8 +6756,15 @@ var getInteractionPropertiesForEvent = (event) => {
|
|
|
6548
6756
|
};
|
|
6549
6757
|
};
|
|
6550
6758
|
|
|
6759
|
+
// src/functions/is-from-trusted-host.ts
|
|
6760
|
+
var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
6761
|
+
function isFromTrustedHost(trustedHosts, e) {
|
|
6762
|
+
const url = new URL(e.origin), hostname = url.hostname;
|
|
6763
|
+
return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
|
|
6764
|
+
}
|
|
6765
|
+
|
|
6551
6766
|
// src/constants/sdk-version.ts
|
|
6552
|
-
var SDK_VERSION = "0.12.
|
|
6767
|
+
var SDK_VERSION = "0.12.8";
|
|
6553
6768
|
|
|
6554
6769
|
// src/functions/register.ts
|
|
6555
6770
|
var registry = {};
|
|
@@ -6685,6 +6900,66 @@ var setupBrowserForEditing = (options = {}) => {
|
|
|
6685
6900
|
}
|
|
6686
6901
|
};
|
|
6687
6902
|
|
|
6903
|
+
// src/helpers/subscribe-to-editor.ts
|
|
6904
|
+
var createEditorListener = ({
|
|
6905
|
+
model,
|
|
6906
|
+
trustedHosts,
|
|
6907
|
+
callbacks
|
|
6908
|
+
}) => {
|
|
6909
|
+
return (event) => {
|
|
6910
|
+
if (!isFromTrustedHost(trustedHosts, event)) {
|
|
6911
|
+
return;
|
|
6912
|
+
}
|
|
6913
|
+
const {
|
|
6914
|
+
data
|
|
6915
|
+
} = event;
|
|
6916
|
+
if (data) {
|
|
6917
|
+
switch (data.type) {
|
|
6918
|
+
case "builder.configureSdk": {
|
|
6919
|
+
callbacks.configureSdk(data.data);
|
|
6920
|
+
break;
|
|
6921
|
+
}
|
|
6922
|
+
case "builder.triggerAnimation": {
|
|
6923
|
+
callbacks.animation(data.data);
|
|
6924
|
+
break;
|
|
6925
|
+
}
|
|
6926
|
+
case "builder.contentUpdate": {
|
|
6927
|
+
const messageContent = data.data;
|
|
6928
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
6929
|
+
const contentData = messageContent.data;
|
|
6930
|
+
if (key === model) {
|
|
6931
|
+
callbacks.contentUpdate(contentData);
|
|
6932
|
+
}
|
|
6933
|
+
break;
|
|
6934
|
+
}
|
|
6935
|
+
}
|
|
6936
|
+
}
|
|
6937
|
+
};
|
|
6938
|
+
};
|
|
6939
|
+
var subscribeToEditor = (model, callback, options) => {
|
|
6940
|
+
if (!isBrowser) {
|
|
6941
|
+
logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
|
|
6942
|
+
return () => {
|
|
6943
|
+
};
|
|
6944
|
+
}
|
|
6945
|
+
setupBrowserForEditing();
|
|
6946
|
+
const listener = createEditorListener({
|
|
6947
|
+
callbacks: {
|
|
6948
|
+
contentUpdate: callback,
|
|
6949
|
+
animation: () => {
|
|
6950
|
+
},
|
|
6951
|
+
configureSdk: () => {
|
|
6952
|
+
}
|
|
6953
|
+
},
|
|
6954
|
+
model,
|
|
6955
|
+
trustedHosts: options?.trustedHosts
|
|
6956
|
+
});
|
|
6957
|
+
window.addEventListener("message", listener);
|
|
6958
|
+
return () => {
|
|
6959
|
+
window.removeEventListener("message", listener);
|
|
6960
|
+
};
|
|
6961
|
+
};
|
|
6962
|
+
|
|
6688
6963
|
// src/components/content/components/enable-editor.tsx
|
|
6689
6964
|
function EnableEditor(props) {
|
|
6690
6965
|
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
@@ -6728,16 +7003,11 @@ function EnableEditor(props) {
|
|
|
6728
7003
|
}));
|
|
6729
7004
|
}
|
|
6730
7005
|
function processMessage(event) {
|
|
6731
|
-
|
|
6732
|
-
|
|
6733
|
-
|
|
6734
|
-
|
|
6735
|
-
|
|
6736
|
-
} = event;
|
|
6737
|
-
if (data) {
|
|
6738
|
-
switch (data.type) {
|
|
6739
|
-
case "builder.configureSdk": {
|
|
6740
|
-
const messageContent = data.data;
|
|
7006
|
+
return createEditorListener({
|
|
7007
|
+
model: props.model,
|
|
7008
|
+
trustedHosts: props.trustedHosts,
|
|
7009
|
+
callbacks: {
|
|
7010
|
+
configureSdk: (messageContent) => {
|
|
6741
7011
|
const {
|
|
6742
7012
|
breakpoints,
|
|
6743
7013
|
contentId
|
|
@@ -6751,22 +7021,18 @@ function EnableEditor(props) {
|
|
|
6751
7021
|
breakpoints
|
|
6752
7022
|
}
|
|
6753
7023
|
});
|
|
6754
|
-
}
|
|
6755
|
-
setForceReRenderCount(forceReRenderCount() + 1);
|
|
6756
|
-
break;
|
|
6757
|
-
}
|
|
6758
|
-
case "builder.contentUpdate": {
|
|
6759
|
-
const messageContent = data.data;
|
|
6760
|
-
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
6761
|
-
const contentData = messageContent.data;
|
|
6762
|
-
if (key === props.model) {
|
|
6763
|
-
mergeNewContent(contentData);
|
|
6764
7024
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
6765
7025
|
}
|
|
6766
|
-
|
|
7026
|
+
},
|
|
7027
|
+
animation: (animation) => {
|
|
7028
|
+
triggerAnimation(animation);
|
|
7029
|
+
},
|
|
7030
|
+
contentUpdate: (newContent) => {
|
|
7031
|
+
mergeNewContent(newContent);
|
|
7032
|
+
setForceReRenderCount(forceReRenderCount() + 1);
|
|
6767
7033
|
}
|
|
6768
7034
|
}
|
|
6769
|
-
}
|
|
7035
|
+
})(event);
|
|
6770
7036
|
}
|
|
6771
7037
|
function evaluateJsCode() {
|
|
6772
7038
|
const jsCode = props.builderContextSignal.content?.data?.jsCode;
|
|
@@ -7609,4 +7875,4 @@ var fetchBuilderProps = async (_args) => {
|
|
|
7609
7875
|
};
|
|
7610
7876
|
};
|
|
7611
7877
|
|
|
7612
|
-
export { blocks_default as Blocks, button_default as Button, columns_default as Columns, content_variants_default as Content, fragment_default as Fragment, image_default as Image, RenderBlocks, RenderContent, section_default as Section, symbol_default as Symbol, text_default as Text, video_default as Video, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getAllContent, getBuilderSearchParams, getContent, isEditing, isPreviewing, register, setEditorSettings, track };
|
|
7878
|
+
export { blocks_default as Blocks, button_default as Button, columns_default as Columns, content_variants_default as Content, fragment_default as Fragment, image_default as Image, RenderBlocks, RenderContent, section_default as Section, symbol_default as Symbol, text_default as Text, video_default as Video, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getAllContent, getBuilderSearchParams, getContent, isEditing, isPreviewing, register, setEditorSettings, subscribeToEditor, track };
|