@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/lib/edge/dev.js CHANGED
@@ -3576,6 +3576,212 @@ function getProcessedBlock({
3576
3576
  }
3577
3577
  }
3578
3578
 
3579
+ // src/components/block/animator.ts
3580
+ function throttle(func, wait, options = {}) {
3581
+ let context;
3582
+ let args;
3583
+ let result;
3584
+ let timeout = null;
3585
+ let previous = 0;
3586
+ const later = function() {
3587
+ previous = options.leading === false ? 0 : Date.now();
3588
+ timeout = null;
3589
+ result = func.apply(context, args);
3590
+ if (!timeout)
3591
+ context = args = null;
3592
+ };
3593
+ return function() {
3594
+ const now = Date.now();
3595
+ if (!previous && options.leading === false)
3596
+ previous = now;
3597
+ const remaining = wait - (now - previous);
3598
+ context = this;
3599
+ args = arguments;
3600
+ if (remaining <= 0 || remaining > wait) {
3601
+ if (timeout) {
3602
+ clearTimeout(timeout);
3603
+ timeout = null;
3604
+ }
3605
+ previous = now;
3606
+ result = func.apply(context, args);
3607
+ if (!timeout)
3608
+ context = args = null;
3609
+ } else if (!timeout && options.trailing !== false) {
3610
+ timeout = setTimeout(later, remaining);
3611
+ }
3612
+ return result;
3613
+ };
3614
+ }
3615
+ function assign(target, ..._args) {
3616
+ const to = Object(target);
3617
+ for (let index = 1; index < arguments.length; index++) {
3618
+ const nextSource = arguments[index];
3619
+ if (nextSource != null) {
3620
+ for (const nextKey in nextSource) {
3621
+ if (Object.prototype.hasOwnProperty.call(nextSource, nextKey)) {
3622
+ to[nextKey] = nextSource[nextKey];
3623
+ }
3624
+ }
3625
+ }
3626
+ }
3627
+ return to;
3628
+ }
3629
+ var camelCaseToKebabCase = (str) => str ? str.replace(/([A-Z])/g, (g) => `-${g[0].toLowerCase()}`) : "";
3630
+ function bindAnimations(animations) {
3631
+ for (const animation of animations) {
3632
+ switch (animation.trigger) {
3633
+ case "pageLoad":
3634
+ triggerAnimation(animation);
3635
+ break;
3636
+ case "hover":
3637
+ bindHoverAnimation(animation);
3638
+ break;
3639
+ case "scrollInView":
3640
+ bindScrollInViewAnimation(animation);
3641
+ break;
3642
+ }
3643
+ }
3644
+ }
3645
+ function warnElementNotPresent(id2) {
3646
+ console.warn(`Cannot animate element: element with ID ${id2} not found!`);
3647
+ }
3648
+ function augmentAnimation(animation, element) {
3649
+ const stylesUsed = getAllStylesUsed(animation);
3650
+ const computedStyle = getComputedStyle(element);
3651
+ const firstStyles = animation.steps[0].styles;
3652
+ const lastStyles = animation.steps[animation.steps.length - 1].styles;
3653
+ const bothStyles = [firstStyles, lastStyles];
3654
+ for (const styles of bothStyles) {
3655
+ for (const style of stylesUsed) {
3656
+ if (!(style in styles)) {
3657
+ styles[style] = computedStyle[style];
3658
+ }
3659
+ }
3660
+ }
3661
+ }
3662
+ function getAllStylesUsed(animation) {
3663
+ const properties = [];
3664
+ for (const step of animation.steps) {
3665
+ for (const key in step.styles) {
3666
+ if (properties.indexOf(key) === -1) {
3667
+ properties.push(key);
3668
+ }
3669
+ }
3670
+ }
3671
+ return properties;
3672
+ }
3673
+ function triggerAnimation(animation) {
3674
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
3675
+ if (!elements.length) {
3676
+ warnElementNotPresent(animation.elementId || animation.id || "");
3677
+ return;
3678
+ }
3679
+ Array.from(elements).forEach((element) => {
3680
+ augmentAnimation(animation, element);
3681
+ element.style.transition = "none";
3682
+ element.style.transitionDelay = "0";
3683
+ assign(element.style, animation.steps[0].styles);
3684
+ setTimeout(() => {
3685
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
3686
+ if (animation.delay) {
3687
+ element.style.transitionDelay = animation.delay + "s";
3688
+ }
3689
+ assign(element.style, animation.steps[1].styles);
3690
+ setTimeout(() => {
3691
+ element.style.transition = "";
3692
+ element.style.transitionDelay = "";
3693
+ }, (animation.delay || 0) * 1e3 + animation.duration * 1e3 + 100);
3694
+ });
3695
+ });
3696
+ }
3697
+ function bindHoverAnimation(animation) {
3698
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
3699
+ if (!elements.length) {
3700
+ warnElementNotPresent(animation.elementId || animation.id || "");
3701
+ return;
3702
+ }
3703
+ Array.from(elements).forEach((element) => {
3704
+ augmentAnimation(animation, element);
3705
+ const defaultState = animation.steps[0].styles;
3706
+ const hoverState = animation.steps[1].styles;
3707
+ function attachDefaultState() {
3708
+ assign(element.style, defaultState);
3709
+ }
3710
+ function attachHoverState() {
3711
+ assign(element.style, hoverState);
3712
+ }
3713
+ attachDefaultState();
3714
+ element.addEventListener("mouseenter", attachHoverState);
3715
+ element.addEventListener("mouseleave", attachDefaultState);
3716
+ setTimeout(() => {
3717
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
3718
+ if (animation.delay) {
3719
+ element.style.transitionDelay = animation.delay + "s";
3720
+ }
3721
+ });
3722
+ });
3723
+ }
3724
+ function bindScrollInViewAnimation(animation) {
3725
+ const elements = Array.prototype.slice.call(document.getElementsByClassName(animation.elementId || animation.id || ""));
3726
+ if (!elements.length) {
3727
+ warnElementNotPresent(animation.elementId || animation.id || "");
3728
+ return;
3729
+ }
3730
+ Array.from(elements).forEach((element) => {
3731
+ augmentAnimation(animation, element);
3732
+ let triggered = false;
3733
+ let pendingAnimation = false;
3734
+ function immediateOnScroll() {
3735
+ if (!triggered && isScrolledIntoView(element)) {
3736
+ triggered = true;
3737
+ pendingAnimation = true;
3738
+ setTimeout(() => {
3739
+ assign(element.style, animation.steps[1].styles);
3740
+ if (!animation.repeat) {
3741
+ document.removeEventListener("scroll", onScroll);
3742
+ }
3743
+ setTimeout(() => {
3744
+ pendingAnimation = false;
3745
+ if (!animation.repeat) {
3746
+ element.style.transition = "";
3747
+ element.style.transitionDelay = "";
3748
+ }
3749
+ }, (animation.duration + (animation.delay || 0)) * 1e3 + 100);
3750
+ });
3751
+ } else if (animation.repeat && triggered && !pendingAnimation && !isScrolledIntoView(element)) {
3752
+ triggered = false;
3753
+ assign(element.style, animation.steps[0].styles);
3754
+ }
3755
+ }
3756
+ const onScroll = throttle(immediateOnScroll, 200, {
3757
+ leading: false
3758
+ });
3759
+ function isScrolledIntoView(elem) {
3760
+ const rect = elem.getBoundingClientRect();
3761
+ const windowHeight = window.innerHeight;
3762
+ const thresholdPercent = (animation.thresholdPercent || 0) / 100;
3763
+ const threshold = thresholdPercent * windowHeight;
3764
+ return rect.bottom > threshold && rect.top < windowHeight - threshold;
3765
+ }
3766
+ const defaultState = animation.steps[0].styles;
3767
+ function attachDefaultState() {
3768
+ assign(element.style, defaultState);
3769
+ }
3770
+ attachDefaultState();
3771
+ setTimeout(() => {
3772
+ element.style.transition = `all ${animation.duration}s ${camelCaseToKebabCase(animation.easing)}`;
3773
+ if (animation.delay) {
3774
+ element.style.transitionDelay = animation.delay + "s";
3775
+ }
3776
+ });
3777
+ document.addEventListener("scroll", onScroll, {
3778
+ capture: true,
3779
+ passive: true
3780
+ });
3781
+ immediateOnScroll();
3782
+ });
3783
+ }
3784
+
3579
3785
  // src/components/block/block.helpers.ts
3580
3786
  var getComponent = ({
3581
3787
  block,
@@ -4151,6 +4357,16 @@ function Block(props) {
4151
4357
  isInteractive: !blockComponent()?.isRSC
4152
4358
  };
4153
4359
  }
4360
+ onMount(() => {
4361
+ const blockId = processedBlock().id;
4362
+ const animations = processedBlock().animations;
4363
+ if (animations && blockId) {
4364
+ bindAnimations(animations.filter((item) => item.trigger !== "hover").map((animation) => ({
4365
+ ...animation,
4366
+ elementId: blockId
4367
+ })));
4368
+ }
4369
+ });
4154
4370
  return createComponent(Show, {
4155
4371
  get when() {
4156
4372
  return canShowBlock();
@@ -6305,13 +6521,6 @@ async function fetchEntries(options) {
6305
6521
  }
6306
6522
  var getAllContent = fetchEntries;
6307
6523
 
6308
- // src/functions/is-from-trusted-host.ts
6309
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6310
- function isFromTrustedHost(trustedHosts, e) {
6311
- const url = new URL(e.origin), hostname = url.hostname;
6312
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6313
- }
6314
-
6315
6524
  // src/functions/is-previewing.ts
6316
6525
  function isPreviewing() {
6317
6526
  if (!isBrowser()) {
@@ -6562,8 +6771,15 @@ var getInteractionPropertiesForEvent = (event) => {
6562
6771
  };
6563
6772
  };
6564
6773
 
6774
+ // src/functions/is-from-trusted-host.ts
6775
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6776
+ function isFromTrustedHost(trustedHosts, e) {
6777
+ const url = new URL(e.origin), hostname = url.hostname;
6778
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6779
+ }
6780
+
6565
6781
  // src/constants/sdk-version.ts
6566
- var SDK_VERSION = "0.12.6";
6782
+ var SDK_VERSION = "0.12.8";
6567
6783
 
6568
6784
  // src/functions/register.ts
6569
6785
  var registry = {};
@@ -6700,6 +6916,66 @@ var setupBrowserForEditing = (options = {}) => {
6700
6916
  }
6701
6917
  };
6702
6918
 
6919
+ // src/helpers/subscribe-to-editor.ts
6920
+ var createEditorListener = ({
6921
+ model,
6922
+ trustedHosts,
6923
+ callbacks
6924
+ }) => {
6925
+ return (event) => {
6926
+ if (!isFromTrustedHost(trustedHosts, event)) {
6927
+ return;
6928
+ }
6929
+ const {
6930
+ data
6931
+ } = event;
6932
+ if (data) {
6933
+ switch (data.type) {
6934
+ case "builder.configureSdk": {
6935
+ callbacks.configureSdk(data.data);
6936
+ break;
6937
+ }
6938
+ case "builder.triggerAnimation": {
6939
+ callbacks.animation(data.data);
6940
+ break;
6941
+ }
6942
+ case "builder.contentUpdate": {
6943
+ const messageContent = data.data;
6944
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6945
+ const contentData = messageContent.data;
6946
+ if (key === model) {
6947
+ callbacks.contentUpdate(contentData);
6948
+ }
6949
+ break;
6950
+ }
6951
+ }
6952
+ }
6953
+ };
6954
+ };
6955
+ var subscribeToEditor = (model, callback, options) => {
6956
+ if (!isBrowser) {
6957
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
6958
+ return () => {
6959
+ };
6960
+ }
6961
+ setupBrowserForEditing();
6962
+ const listener = createEditorListener({
6963
+ callbacks: {
6964
+ contentUpdate: callback,
6965
+ animation: () => {
6966
+ },
6967
+ configureSdk: () => {
6968
+ }
6969
+ },
6970
+ model,
6971
+ trustedHosts: options?.trustedHosts
6972
+ });
6973
+ window.addEventListener("message", listener);
6974
+ return () => {
6975
+ window.removeEventListener("message", listener);
6976
+ };
6977
+ };
6978
+
6703
6979
  // src/components/content/components/enable-editor.tsx
6704
6980
  function EnableEditor(props) {
6705
6981
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -6743,16 +7019,11 @@ function EnableEditor(props) {
6743
7019
  }));
6744
7020
  }
6745
7021
  function processMessage(event) {
6746
- if (!isFromTrustedHost(props.trustedHosts, event)) {
6747
- return;
6748
- }
6749
- const {
6750
- data
6751
- } = event;
6752
- if (data) {
6753
- switch (data.type) {
6754
- case "builder.configureSdk": {
6755
- const messageContent = data.data;
7022
+ return createEditorListener({
7023
+ model: props.model,
7024
+ trustedHosts: props.trustedHosts,
7025
+ callbacks: {
7026
+ configureSdk: (messageContent) => {
6756
7027
  const {
6757
7028
  breakpoints,
6758
7029
  contentId
@@ -6766,22 +7037,18 @@ function EnableEditor(props) {
6766
7037
  breakpoints
6767
7038
  }
6768
7039
  });
6769
- }
6770
- setForceReRenderCount(forceReRenderCount() + 1);
6771
- break;
6772
- }
6773
- case "builder.contentUpdate": {
6774
- const messageContent = data.data;
6775
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6776
- const contentData = messageContent.data;
6777
- if (key === props.model) {
6778
- mergeNewContent(contentData);
6779
7040
  setForceReRenderCount(forceReRenderCount() + 1);
6780
7041
  }
6781
- break;
7042
+ },
7043
+ animation: (animation) => {
7044
+ triggerAnimation(animation);
7045
+ },
7046
+ contentUpdate: (newContent) => {
7047
+ mergeNewContent(newContent);
7048
+ setForceReRenderCount(forceReRenderCount() + 1);
6782
7049
  }
6783
7050
  }
6784
- }
7051
+ })(event);
6785
7052
  }
6786
7053
  function evaluateJsCode() {
6787
7054
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -7625,4 +7892,4 @@ var fetchBuilderProps = async (_args) => {
7625
7892
  };
7626
7893
  };
7627
7894
 
7628
- 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 };
7895
+ 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 };