@builder.io/sdk-qwik 0.12.7 → 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.
@@ -3352,17 +3352,6 @@ async function fetchEntries(options) {
3352
3352
  }
3353
3353
  }
3354
3354
  const getAllContent = fetchEntries;
3355
- const DEFAULT_TRUSTED_HOSTS = [
3356
- "*.beta.builder.io",
3357
- "beta.builder.io",
3358
- "builder.io",
3359
- "localhost",
3360
- "qa.builder.io"
3361
- ];
3362
- function isFromTrustedHost(trustedHosts, e) {
3363
- const url = new URL(e.origin), hostname = url.hostname;
3364
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3365
- }
3366
3355
  function isPreviewing() {
3367
3356
  if (!isBrowser())
3368
3357
  return false;
@@ -3562,7 +3551,18 @@ const getInteractionPropertiesForEvent = (event) => {
3562
3551
  }
3563
3552
  };
3564
3553
  };
3565
- const SDK_VERSION = "0.12.7";
3554
+ const DEFAULT_TRUSTED_HOSTS = [
3555
+ "*.beta.builder.io",
3556
+ "beta.builder.io",
3557
+ "builder.io",
3558
+ "localhost",
3559
+ "qa.builder.io"
3560
+ ];
3561
+ function isFromTrustedHost(trustedHosts, e) {
3562
+ const url = new URL(e.origin), hostname = url.hostname;
3563
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3564
+ }
3565
+ const SDK_VERSION = "0.12.8";
3566
3566
  const registry = {};
3567
3567
  function register(type, info) {
3568
3568
  let typeList = registry[type];
@@ -3698,6 +3698,53 @@ const setupBrowserForEditing = (options = {}) => {
3698
3698
  });
3699
3699
  }
3700
3700
  };
3701
+ const createEditorListener = ({ model, trustedHosts, callbacks }) => {
3702
+ return (event) => {
3703
+ if (!isFromTrustedHost(trustedHosts, event))
3704
+ return;
3705
+ const { data } = event;
3706
+ if (data)
3707
+ switch (data.type) {
3708
+ case "builder.configureSdk":
3709
+ callbacks.configureSdk(data.data);
3710
+ break;
3711
+ case "builder.triggerAnimation":
3712
+ callbacks.animation(data.data);
3713
+ break;
3714
+ case "builder.contentUpdate": {
3715
+ const messageContent = data.data;
3716
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3717
+ const contentData = messageContent.data;
3718
+ if (key === model)
3719
+ callbacks.contentUpdate(contentData);
3720
+ break;
3721
+ }
3722
+ }
3723
+ };
3724
+ };
3725
+ const subscribeToEditor = (model, callback, options) => {
3726
+ if (!isBrowser) {
3727
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3728
+ return () => {
3729
+ };
3730
+ }
3731
+ setupBrowserForEditing();
3732
+ const listener = createEditorListener({
3733
+ callbacks: {
3734
+ contentUpdate: callback,
3735
+ animation: () => {
3736
+ },
3737
+ configureSdk: () => {
3738
+ }
3739
+ },
3740
+ model,
3741
+ trustedHosts: options == null ? void 0 : options.trustedHosts
3742
+ });
3743
+ window.addEventListener("message", listener);
3744
+ return () => {
3745
+ window.removeEventListener("message", listener);
3746
+ };
3747
+ };
3701
3748
  const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
3702
3749
  var _a, _b;
3703
3750
  const combinedState = {
@@ -3727,40 +3774,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
3727
3774
  props.builderContextSignal.content = newContentValue;
3728
3775
  };
3729
3776
  const processMessage = function processMessage2(props, state, elementRef, event) {
3730
- var _a;
3731
- if (!isFromTrustedHost(props.trustedHosts, event))
3732
- return;
3733
- const { data } = event;
3734
- if (data)
3735
- switch (data.type) {
3736
- case "builder.configureSdk": {
3737
- const messageContent = data.data;
3777
+ return createEditorListener({
3778
+ model: props.model,
3779
+ trustedHosts: props.trustedHosts,
3780
+ callbacks: {
3781
+ configureSdk: (messageContent) => {
3782
+ var _a;
3738
3783
  const { breakpoints, contentId } = messageContent;
3739
3784
  if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
3740
3785
  return;
3741
- if (breakpoints)
3786
+ if (breakpoints) {
3742
3787
  mergeNewContent(props, state, elementRef, {
3743
3788
  meta: {
3744
3789
  breakpoints
3745
3790
  }
3746
3791
  });
3747
- state.forceReRenderCount = state.forceReRenderCount + 1;
3748
- break;
3749
- }
3750
- case "builder.triggerAnimation":
3751
- triggerAnimation(data.data);
3752
- break;
3753
- case "builder.contentUpdate": {
3754
- const messageContent = data.data;
3755
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3756
- const contentData = messageContent.data;
3757
- if (key === props.model) {
3758
- mergeNewContent(props, state, elementRef, contentData);
3759
3792
  state.forceReRenderCount = state.forceReRenderCount + 1;
3760
3793
  }
3761
- break;
3794
+ },
3795
+ animation: (animation) => {
3796
+ triggerAnimation(animation);
3797
+ },
3798
+ contentUpdate: (newContent) => {
3799
+ mergeNewContent(props, state, elementRef, newContent);
3800
+ state.forceReRenderCount = state.forceReRenderCount + 1;
3762
3801
  }
3763
3802
  }
3803
+ })(event);
3764
3804
  };
3765
3805
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
3766
3806
  var _a, _b;
@@ -4893,4 +4933,5 @@ exports.isEditing = isEditing;
4893
4933
  exports.isPreviewing = isPreviewing;
4894
4934
  exports.register = register;
4895
4935
  exports.setEditorSettings = setEditorSettings;
4936
+ exports.subscribeToEditor = subscribeToEditor;
4896
4937
  exports.track = track;
@@ -3350,17 +3350,6 @@ async function fetchEntries(options) {
3350
3350
  }
3351
3351
  }
3352
3352
  const getAllContent = fetchEntries;
3353
- const DEFAULT_TRUSTED_HOSTS = [
3354
- "*.beta.builder.io",
3355
- "beta.builder.io",
3356
- "builder.io",
3357
- "localhost",
3358
- "qa.builder.io"
3359
- ];
3360
- function isFromTrustedHost(trustedHosts, e) {
3361
- const url = new URL(e.origin), hostname = url.hostname;
3362
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3363
- }
3364
3353
  function isPreviewing() {
3365
3354
  if (!isBrowser())
3366
3355
  return false;
@@ -3560,7 +3549,18 @@ const getInteractionPropertiesForEvent = (event) => {
3560
3549
  }
3561
3550
  };
3562
3551
  };
3563
- const SDK_VERSION = "0.12.7";
3552
+ const DEFAULT_TRUSTED_HOSTS = [
3553
+ "*.beta.builder.io",
3554
+ "beta.builder.io",
3555
+ "builder.io",
3556
+ "localhost",
3557
+ "qa.builder.io"
3558
+ ];
3559
+ function isFromTrustedHost(trustedHosts, e) {
3560
+ const url = new URL(e.origin), hostname = url.hostname;
3561
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3562
+ }
3563
+ const SDK_VERSION = "0.12.8";
3564
3564
  const registry = {};
3565
3565
  function register(type, info) {
3566
3566
  let typeList = registry[type];
@@ -3696,6 +3696,53 @@ const setupBrowserForEditing = (options = {}) => {
3696
3696
  });
3697
3697
  }
3698
3698
  };
3699
+ const createEditorListener = ({ model, trustedHosts, callbacks }) => {
3700
+ return (event) => {
3701
+ if (!isFromTrustedHost(trustedHosts, event))
3702
+ return;
3703
+ const { data } = event;
3704
+ if (data)
3705
+ switch (data.type) {
3706
+ case "builder.configureSdk":
3707
+ callbacks.configureSdk(data.data);
3708
+ break;
3709
+ case "builder.triggerAnimation":
3710
+ callbacks.animation(data.data);
3711
+ break;
3712
+ case "builder.contentUpdate": {
3713
+ const messageContent = data.data;
3714
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3715
+ const contentData = messageContent.data;
3716
+ if (key === model)
3717
+ callbacks.contentUpdate(contentData);
3718
+ break;
3719
+ }
3720
+ }
3721
+ };
3722
+ };
3723
+ const subscribeToEditor = (model, callback, options) => {
3724
+ if (!isBrowser) {
3725
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3726
+ return () => {
3727
+ };
3728
+ }
3729
+ setupBrowserForEditing();
3730
+ const listener = createEditorListener({
3731
+ callbacks: {
3732
+ contentUpdate: callback,
3733
+ animation: () => {
3734
+ },
3735
+ configureSdk: () => {
3736
+ }
3737
+ },
3738
+ model,
3739
+ trustedHosts: options == null ? void 0 : options.trustedHosts
3740
+ });
3741
+ window.addEventListener("message", listener);
3742
+ return () => {
3743
+ window.removeEventListener("message", listener);
3744
+ };
3745
+ };
3699
3746
  const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
3700
3747
  var _a, _b;
3701
3748
  const combinedState = {
@@ -3725,40 +3772,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
3725
3772
  props.builderContextSignal.content = newContentValue;
3726
3773
  };
3727
3774
  const processMessage = function processMessage2(props, state, elementRef, event) {
3728
- var _a;
3729
- if (!isFromTrustedHost(props.trustedHosts, event))
3730
- return;
3731
- const { data } = event;
3732
- if (data)
3733
- switch (data.type) {
3734
- case "builder.configureSdk": {
3735
- const messageContent = data.data;
3775
+ return createEditorListener({
3776
+ model: props.model,
3777
+ trustedHosts: props.trustedHosts,
3778
+ callbacks: {
3779
+ configureSdk: (messageContent) => {
3780
+ var _a;
3736
3781
  const { breakpoints, contentId } = messageContent;
3737
3782
  if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
3738
3783
  return;
3739
- if (breakpoints)
3784
+ if (breakpoints) {
3740
3785
  mergeNewContent(props, state, elementRef, {
3741
3786
  meta: {
3742
3787
  breakpoints
3743
3788
  }
3744
3789
  });
3745
- state.forceReRenderCount = state.forceReRenderCount + 1;
3746
- break;
3747
- }
3748
- case "builder.triggerAnimation":
3749
- triggerAnimation(data.data);
3750
- break;
3751
- case "builder.contentUpdate": {
3752
- const messageContent = data.data;
3753
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3754
- const contentData = messageContent.data;
3755
- if (key === props.model) {
3756
- mergeNewContent(props, state, elementRef, contentData);
3757
3790
  state.forceReRenderCount = state.forceReRenderCount + 1;
3758
3791
  }
3759
- break;
3792
+ },
3793
+ animation: (animation) => {
3794
+ triggerAnimation(animation);
3795
+ },
3796
+ contentUpdate: (newContent) => {
3797
+ mergeNewContent(props, state, elementRef, newContent);
3798
+ state.forceReRenderCount = state.forceReRenderCount + 1;
3760
3799
  }
3761
3800
  }
3801
+ })(event);
3762
3802
  };
3763
3803
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
3764
3804
  var _a, _b;
@@ -4892,5 +4932,6 @@ export {
4892
4932
  isPreviewing,
4893
4933
  register,
4894
4934
  setEditorSettings,
4935
+ subscribeToEditor,
4895
4936
  track
4896
4937
  };
@@ -6583,17 +6583,6 @@ async function fetchEntries(options) {
6583
6583
  }
6584
6584
  }
6585
6585
  const getAllContent = fetchEntries;
6586
- const DEFAULT_TRUSTED_HOSTS = [
6587
- "*.beta.builder.io",
6588
- "beta.builder.io",
6589
- "builder.io",
6590
- "localhost",
6591
- "qa.builder.io"
6592
- ];
6593
- function isFromTrustedHost(trustedHosts, e) {
6594
- const url = new URL(e.origin), hostname = url.hostname;
6595
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6596
- }
6597
6586
  function isPreviewing() {
6598
6587
  if (!isBrowser())
6599
6588
  return false;
@@ -6793,7 +6782,18 @@ const getInteractionPropertiesForEvent = (event) => {
6793
6782
  }
6794
6783
  };
6795
6784
  };
6796
- const SDK_VERSION = "0.12.7";
6785
+ const DEFAULT_TRUSTED_HOSTS = [
6786
+ "*.beta.builder.io",
6787
+ "beta.builder.io",
6788
+ "builder.io",
6789
+ "localhost",
6790
+ "qa.builder.io"
6791
+ ];
6792
+ function isFromTrustedHost(trustedHosts, e) {
6793
+ const url = new URL(e.origin), hostname = url.hostname;
6794
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6795
+ }
6796
+ const SDK_VERSION = "0.12.8";
6797
6797
  const registry = {};
6798
6798
  function register(type, info) {
6799
6799
  let typeList = registry[type];
@@ -6929,6 +6929,53 @@ const setupBrowserForEditing = (options = {}) => {
6929
6929
  });
6930
6930
  }
6931
6931
  };
6932
+ const createEditorListener = ({ model, trustedHosts, callbacks }) => {
6933
+ return (event) => {
6934
+ if (!isFromTrustedHost(trustedHosts, event))
6935
+ return;
6936
+ const { data } = event;
6937
+ if (data)
6938
+ switch (data.type) {
6939
+ case "builder.configureSdk":
6940
+ callbacks.configureSdk(data.data);
6941
+ break;
6942
+ case "builder.triggerAnimation":
6943
+ callbacks.animation(data.data);
6944
+ break;
6945
+ case "builder.contentUpdate": {
6946
+ const messageContent = data.data;
6947
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6948
+ const contentData = messageContent.data;
6949
+ if (key === model)
6950
+ callbacks.contentUpdate(contentData);
6951
+ break;
6952
+ }
6953
+ }
6954
+ };
6955
+ };
6956
+ const subscribeToEditor = (model, callback, options) => {
6957
+ if (!isBrowser) {
6958
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
6959
+ return () => {
6960
+ };
6961
+ }
6962
+ setupBrowserForEditing();
6963
+ const listener = createEditorListener({
6964
+ callbacks: {
6965
+ contentUpdate: callback,
6966
+ animation: () => {
6967
+ },
6968
+ configureSdk: () => {
6969
+ }
6970
+ },
6971
+ model,
6972
+ trustedHosts: options == null ? void 0 : options.trustedHosts
6973
+ });
6974
+ window.addEventListener("message", listener);
6975
+ return () => {
6976
+ window.removeEventListener("message", listener);
6977
+ };
6978
+ };
6932
6979
  const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
6933
6980
  var _a, _b;
6934
6981
  const combinedState = {
@@ -6958,40 +7005,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
6958
7005
  props.builderContextSignal.content = newContentValue;
6959
7006
  };
6960
7007
  const processMessage = function processMessage2(props, state, elementRef, event) {
6961
- var _a;
6962
- if (!isFromTrustedHost(props.trustedHosts, event))
6963
- return;
6964
- const { data } = event;
6965
- if (data)
6966
- switch (data.type) {
6967
- case "builder.configureSdk": {
6968
- const messageContent = data.data;
7008
+ return createEditorListener({
7009
+ model: props.model,
7010
+ trustedHosts: props.trustedHosts,
7011
+ callbacks: {
7012
+ configureSdk: (messageContent) => {
7013
+ var _a;
6969
7014
  const { breakpoints, contentId } = messageContent;
6970
7015
  if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
6971
7016
  return;
6972
- if (breakpoints)
7017
+ if (breakpoints) {
6973
7018
  mergeNewContent(props, state, elementRef, {
6974
7019
  meta: {
6975
7020
  breakpoints
6976
7021
  }
6977
7022
  });
6978
- state.forceReRenderCount = state.forceReRenderCount + 1;
6979
- break;
6980
- }
6981
- case "builder.triggerAnimation":
6982
- triggerAnimation(data.data);
6983
- break;
6984
- case "builder.contentUpdate": {
6985
- const messageContent = data.data;
6986
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6987
- const contentData = messageContent.data;
6988
- if (key === props.model) {
6989
- mergeNewContent(props, state, elementRef, contentData);
6990
7023
  state.forceReRenderCount = state.forceReRenderCount + 1;
6991
7024
  }
6992
- break;
7025
+ },
7026
+ animation: (animation) => {
7027
+ triggerAnimation(animation);
7028
+ },
7029
+ contentUpdate: (newContent) => {
7030
+ mergeNewContent(props, state, elementRef, newContent);
7031
+ state.forceReRenderCount = state.forceReRenderCount + 1;
6993
7032
  }
6994
7033
  }
7034
+ })(event);
6995
7035
  };
6996
7036
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
6997
7037
  var _a, _b;
@@ -8124,4 +8164,5 @@ exports.isEditing = isEditing;
8124
8164
  exports.isPreviewing = isPreviewing;
8125
8165
  exports.register = register;
8126
8166
  exports.setEditorSettings = setEditorSettings;
8167
+ exports.subscribeToEditor = subscribeToEditor;
8127
8168
  exports.track = track;
@@ -6581,17 +6581,6 @@ async function fetchEntries(options) {
6581
6581
  }
6582
6582
  }
6583
6583
  const getAllContent = fetchEntries;
6584
- const DEFAULT_TRUSTED_HOSTS = [
6585
- "*.beta.builder.io",
6586
- "beta.builder.io",
6587
- "builder.io",
6588
- "localhost",
6589
- "qa.builder.io"
6590
- ];
6591
- function isFromTrustedHost(trustedHosts, e) {
6592
- const url = new URL(e.origin), hostname = url.hostname;
6593
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6594
- }
6595
6584
  function isPreviewing() {
6596
6585
  if (!isBrowser())
6597
6586
  return false;
@@ -6791,7 +6780,18 @@ const getInteractionPropertiesForEvent = (event) => {
6791
6780
  }
6792
6781
  };
6793
6782
  };
6794
- const SDK_VERSION = "0.12.7";
6783
+ const DEFAULT_TRUSTED_HOSTS = [
6784
+ "*.beta.builder.io",
6785
+ "beta.builder.io",
6786
+ "builder.io",
6787
+ "localhost",
6788
+ "qa.builder.io"
6789
+ ];
6790
+ function isFromTrustedHost(trustedHosts, e) {
6791
+ const url = new URL(e.origin), hostname = url.hostname;
6792
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6793
+ }
6794
+ const SDK_VERSION = "0.12.8";
6795
6795
  const registry = {};
6796
6796
  function register(type, info) {
6797
6797
  let typeList = registry[type];
@@ -6927,6 +6927,53 @@ const setupBrowserForEditing = (options = {}) => {
6927
6927
  });
6928
6928
  }
6929
6929
  };
6930
+ const createEditorListener = ({ model, trustedHosts, callbacks }) => {
6931
+ return (event) => {
6932
+ if (!isFromTrustedHost(trustedHosts, event))
6933
+ return;
6934
+ const { data } = event;
6935
+ if (data)
6936
+ switch (data.type) {
6937
+ case "builder.configureSdk":
6938
+ callbacks.configureSdk(data.data);
6939
+ break;
6940
+ case "builder.triggerAnimation":
6941
+ callbacks.animation(data.data);
6942
+ break;
6943
+ case "builder.contentUpdate": {
6944
+ const messageContent = data.data;
6945
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6946
+ const contentData = messageContent.data;
6947
+ if (key === model)
6948
+ callbacks.contentUpdate(contentData);
6949
+ break;
6950
+ }
6951
+ }
6952
+ };
6953
+ };
6954
+ const subscribeToEditor = (model, callback, options) => {
6955
+ if (!isBrowser) {
6956
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
6957
+ return () => {
6958
+ };
6959
+ }
6960
+ setupBrowserForEditing();
6961
+ const listener = createEditorListener({
6962
+ callbacks: {
6963
+ contentUpdate: callback,
6964
+ animation: () => {
6965
+ },
6966
+ configureSdk: () => {
6967
+ }
6968
+ },
6969
+ model,
6970
+ trustedHosts: options == null ? void 0 : options.trustedHosts
6971
+ });
6972
+ window.addEventListener("message", listener);
6973
+ return () => {
6974
+ window.removeEventListener("message", listener);
6975
+ };
6976
+ };
6930
6977
  const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
6931
6978
  var _a, _b;
6932
6979
  const combinedState = {
@@ -6956,40 +7003,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
6956
7003
  props.builderContextSignal.content = newContentValue;
6957
7004
  };
6958
7005
  const processMessage = function processMessage2(props, state, elementRef, event) {
6959
- var _a;
6960
- if (!isFromTrustedHost(props.trustedHosts, event))
6961
- return;
6962
- const { data } = event;
6963
- if (data)
6964
- switch (data.type) {
6965
- case "builder.configureSdk": {
6966
- const messageContent = data.data;
7006
+ return createEditorListener({
7007
+ model: props.model,
7008
+ trustedHosts: props.trustedHosts,
7009
+ callbacks: {
7010
+ configureSdk: (messageContent) => {
7011
+ var _a;
6967
7012
  const { breakpoints, contentId } = messageContent;
6968
7013
  if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
6969
7014
  return;
6970
- if (breakpoints)
7015
+ if (breakpoints) {
6971
7016
  mergeNewContent(props, state, elementRef, {
6972
7017
  meta: {
6973
7018
  breakpoints
6974
7019
  }
6975
7020
  });
6976
- state.forceReRenderCount = state.forceReRenderCount + 1;
6977
- break;
6978
- }
6979
- case "builder.triggerAnimation":
6980
- triggerAnimation(data.data);
6981
- break;
6982
- case "builder.contentUpdate": {
6983
- const messageContent = data.data;
6984
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6985
- const contentData = messageContent.data;
6986
- if (key === props.model) {
6987
- mergeNewContent(props, state, elementRef, contentData);
6988
7021
  state.forceReRenderCount = state.forceReRenderCount + 1;
6989
7022
  }
6990
- break;
7023
+ },
7024
+ animation: (animation) => {
7025
+ triggerAnimation(animation);
7026
+ },
7027
+ contentUpdate: (newContent) => {
7028
+ mergeNewContent(props, state, elementRef, newContent);
7029
+ state.forceReRenderCount = state.forceReRenderCount + 1;
6991
7030
  }
6992
7031
  }
7032
+ })(event);
6993
7033
  };
6994
7034
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
6995
7035
  var _a, _b;
@@ -8123,5 +8163,6 @@ export {
8123
8163
  isPreviewing,
8124
8164
  register,
8125
8165
  setEditorSettings,
8166
+ subscribeToEditor,
8126
8167
  track
8127
8168
  };
@@ -3453,17 +3453,6 @@ async function fetchEntries(options) {
3453
3453
  }
3454
3454
  }
3455
3455
  const getAllContent = fetchEntries;
3456
- const DEFAULT_TRUSTED_HOSTS = [
3457
- "*.beta.builder.io",
3458
- "beta.builder.io",
3459
- "builder.io",
3460
- "localhost",
3461
- "qa.builder.io"
3462
- ];
3463
- function isFromTrustedHost(trustedHosts, e) {
3464
- const url = new URL(e.origin), hostname = url.hostname;
3465
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3466
- }
3467
3456
  function isPreviewing() {
3468
3457
  if (!isBrowser())
3469
3458
  return false;
@@ -3663,7 +3652,18 @@ const getInteractionPropertiesForEvent = (event) => {
3663
3652
  }
3664
3653
  };
3665
3654
  };
3666
- const SDK_VERSION = "0.12.7";
3655
+ const DEFAULT_TRUSTED_HOSTS = [
3656
+ "*.beta.builder.io",
3657
+ "beta.builder.io",
3658
+ "builder.io",
3659
+ "localhost",
3660
+ "qa.builder.io"
3661
+ ];
3662
+ function isFromTrustedHost(trustedHosts, e) {
3663
+ const url = new URL(e.origin), hostname = url.hostname;
3664
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3665
+ }
3666
+ const SDK_VERSION = "0.12.8";
3667
3667
  const registry = {};
3668
3668
  function register(type, info) {
3669
3669
  let typeList = registry[type];
@@ -3799,6 +3799,53 @@ const setupBrowserForEditing = (options = {}) => {
3799
3799
  });
3800
3800
  }
3801
3801
  };
3802
+ const createEditorListener = ({ model, trustedHosts, callbacks }) => {
3803
+ return (event) => {
3804
+ if (!isFromTrustedHost(trustedHosts, event))
3805
+ return;
3806
+ const { data } = event;
3807
+ if (data)
3808
+ switch (data.type) {
3809
+ case "builder.configureSdk":
3810
+ callbacks.configureSdk(data.data);
3811
+ break;
3812
+ case "builder.triggerAnimation":
3813
+ callbacks.animation(data.data);
3814
+ break;
3815
+ case "builder.contentUpdate": {
3816
+ const messageContent = data.data;
3817
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3818
+ const contentData = messageContent.data;
3819
+ if (key === model)
3820
+ callbacks.contentUpdate(contentData);
3821
+ break;
3822
+ }
3823
+ }
3824
+ };
3825
+ };
3826
+ const subscribeToEditor = (model, callback, options) => {
3827
+ if (!isBrowser) {
3828
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3829
+ return () => {
3830
+ };
3831
+ }
3832
+ setupBrowserForEditing();
3833
+ const listener = createEditorListener({
3834
+ callbacks: {
3835
+ contentUpdate: callback,
3836
+ animation: () => {
3837
+ },
3838
+ configureSdk: () => {
3839
+ }
3840
+ },
3841
+ model,
3842
+ trustedHosts: options == null ? void 0 : options.trustedHosts
3843
+ });
3844
+ window.addEventListener("message", listener);
3845
+ return () => {
3846
+ window.removeEventListener("message", listener);
3847
+ };
3848
+ };
3802
3849
  const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
3803
3850
  var _a, _b;
3804
3851
  const combinedState = {
@@ -3828,40 +3875,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
3828
3875
  props.builderContextSignal.content = newContentValue;
3829
3876
  };
3830
3877
  const processMessage = function processMessage2(props, state, elementRef, event) {
3831
- var _a;
3832
- if (!isFromTrustedHost(props.trustedHosts, event))
3833
- return;
3834
- const { data } = event;
3835
- if (data)
3836
- switch (data.type) {
3837
- case "builder.configureSdk": {
3838
- const messageContent = data.data;
3878
+ return createEditorListener({
3879
+ model: props.model,
3880
+ trustedHosts: props.trustedHosts,
3881
+ callbacks: {
3882
+ configureSdk: (messageContent) => {
3883
+ var _a;
3839
3884
  const { breakpoints, contentId } = messageContent;
3840
3885
  if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
3841
3886
  return;
3842
- if (breakpoints)
3887
+ if (breakpoints) {
3843
3888
  mergeNewContent(props, state, elementRef, {
3844
3889
  meta: {
3845
3890
  breakpoints
3846
3891
  }
3847
3892
  });
3848
- state.forceReRenderCount = state.forceReRenderCount + 1;
3849
- break;
3850
- }
3851
- case "builder.triggerAnimation":
3852
- triggerAnimation(data.data);
3853
- break;
3854
- case "builder.contentUpdate": {
3855
- const messageContent = data.data;
3856
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3857
- const contentData = messageContent.data;
3858
- if (key === props.model) {
3859
- mergeNewContent(props, state, elementRef, contentData);
3860
3893
  state.forceReRenderCount = state.forceReRenderCount + 1;
3861
3894
  }
3862
- break;
3895
+ },
3896
+ animation: (animation) => {
3897
+ triggerAnimation(animation);
3898
+ },
3899
+ contentUpdate: (newContent) => {
3900
+ mergeNewContent(props, state, elementRef, newContent);
3901
+ state.forceReRenderCount = state.forceReRenderCount + 1;
3863
3902
  }
3864
3903
  }
3904
+ })(event);
3865
3905
  };
3866
3906
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
3867
3907
  var _a, _b;
@@ -4994,4 +5034,5 @@ exports.isEditing = isEditing;
4994
5034
  exports.isPreviewing = isPreviewing;
4995
5035
  exports.register = register;
4996
5036
  exports.setEditorSettings = setEditorSettings;
5037
+ exports.subscribeToEditor = subscribeToEditor;
4997
5038
  exports.track = track;
@@ -3451,17 +3451,6 @@ async function fetchEntries(options) {
3451
3451
  }
3452
3452
  }
3453
3453
  const getAllContent = fetchEntries;
3454
- const DEFAULT_TRUSTED_HOSTS = [
3455
- "*.beta.builder.io",
3456
- "beta.builder.io",
3457
- "builder.io",
3458
- "localhost",
3459
- "qa.builder.io"
3460
- ];
3461
- function isFromTrustedHost(trustedHosts, e) {
3462
- const url = new URL(e.origin), hostname = url.hostname;
3463
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3464
- }
3465
3454
  function isPreviewing() {
3466
3455
  if (!isBrowser())
3467
3456
  return false;
@@ -3661,7 +3650,18 @@ const getInteractionPropertiesForEvent = (event) => {
3661
3650
  }
3662
3651
  };
3663
3652
  };
3664
- const SDK_VERSION = "0.12.7";
3653
+ const DEFAULT_TRUSTED_HOSTS = [
3654
+ "*.beta.builder.io",
3655
+ "beta.builder.io",
3656
+ "builder.io",
3657
+ "localhost",
3658
+ "qa.builder.io"
3659
+ ];
3660
+ function isFromTrustedHost(trustedHosts, e) {
3661
+ const url = new URL(e.origin), hostname = url.hostname;
3662
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3663
+ }
3664
+ const SDK_VERSION = "0.12.8";
3665
3665
  const registry = {};
3666
3666
  function register(type, info) {
3667
3667
  let typeList = registry[type];
@@ -3797,6 +3797,53 @@ const setupBrowserForEditing = (options = {}) => {
3797
3797
  });
3798
3798
  }
3799
3799
  };
3800
+ const createEditorListener = ({ model, trustedHosts, callbacks }) => {
3801
+ return (event) => {
3802
+ if (!isFromTrustedHost(trustedHosts, event))
3803
+ return;
3804
+ const { data } = event;
3805
+ if (data)
3806
+ switch (data.type) {
3807
+ case "builder.configureSdk":
3808
+ callbacks.configureSdk(data.data);
3809
+ break;
3810
+ case "builder.triggerAnimation":
3811
+ callbacks.animation(data.data);
3812
+ break;
3813
+ case "builder.contentUpdate": {
3814
+ const messageContent = data.data;
3815
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3816
+ const contentData = messageContent.data;
3817
+ if (key === model)
3818
+ callbacks.contentUpdate(contentData);
3819
+ break;
3820
+ }
3821
+ }
3822
+ };
3823
+ };
3824
+ const subscribeToEditor = (model, callback, options) => {
3825
+ if (!isBrowser) {
3826
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3827
+ return () => {
3828
+ };
3829
+ }
3830
+ setupBrowserForEditing();
3831
+ const listener = createEditorListener({
3832
+ callbacks: {
3833
+ contentUpdate: callback,
3834
+ animation: () => {
3835
+ },
3836
+ configureSdk: () => {
3837
+ }
3838
+ },
3839
+ model,
3840
+ trustedHosts: options == null ? void 0 : options.trustedHosts
3841
+ });
3842
+ window.addEventListener("message", listener);
3843
+ return () => {
3844
+ window.removeEventListener("message", listener);
3845
+ };
3846
+ };
3800
3847
  const mergeNewRootState = function mergeNewRootState2(props, state, elementRef, newData) {
3801
3848
  var _a, _b;
3802
3849
  const combinedState = {
@@ -3826,40 +3873,33 @@ const mergeNewContent = function mergeNewContent2(props, state, elementRef, newC
3826
3873
  props.builderContextSignal.content = newContentValue;
3827
3874
  };
3828
3875
  const processMessage = function processMessage2(props, state, elementRef, event) {
3829
- var _a;
3830
- if (!isFromTrustedHost(props.trustedHosts, event))
3831
- return;
3832
- const { data } = event;
3833
- if (data)
3834
- switch (data.type) {
3835
- case "builder.configureSdk": {
3836
- const messageContent = data.data;
3876
+ return createEditorListener({
3877
+ model: props.model,
3878
+ trustedHosts: props.trustedHosts,
3879
+ callbacks: {
3880
+ configureSdk: (messageContent) => {
3881
+ var _a;
3837
3882
  const { breakpoints, contentId } = messageContent;
3838
3883
  if (!contentId || contentId !== ((_a = props.builderContextSignal.content) == null ? void 0 : _a.id))
3839
3884
  return;
3840
- if (breakpoints)
3885
+ if (breakpoints) {
3841
3886
  mergeNewContent(props, state, elementRef, {
3842
3887
  meta: {
3843
3888
  breakpoints
3844
3889
  }
3845
3890
  });
3846
- state.forceReRenderCount = state.forceReRenderCount + 1;
3847
- break;
3848
- }
3849
- case "builder.triggerAnimation":
3850
- triggerAnimation(data.data);
3851
- break;
3852
- case "builder.contentUpdate": {
3853
- const messageContent = data.data;
3854
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3855
- const contentData = messageContent.data;
3856
- if (key === props.model) {
3857
- mergeNewContent(props, state, elementRef, contentData);
3858
3891
  state.forceReRenderCount = state.forceReRenderCount + 1;
3859
3892
  }
3860
- break;
3893
+ },
3894
+ animation: (animation) => {
3895
+ triggerAnimation(animation);
3896
+ },
3897
+ contentUpdate: (newContent) => {
3898
+ mergeNewContent(props, state, elementRef, newContent);
3899
+ state.forceReRenderCount = state.forceReRenderCount + 1;
3861
3900
  }
3862
3901
  }
3902
+ })(event);
3863
3903
  };
3864
3904
  const evaluateJsCode = function evaluateJsCode2(props, state, elementRef) {
3865
3905
  var _a, _b;
@@ -4993,5 +5033,6 @@ export {
4993
5033
  isPreviewing,
4994
5034
  register,
4995
5035
  setEditorSettings,
5036
+ subscribeToEditor,
4996
5037
  track
4997
5038
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.12.7",
3
+ "version": "0.12.8",
4
4
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/qwik",
5
5
  "repository": {
6
6
  "type": "git",
@@ -6,7 +6,7 @@ export declare const getVariants: (content: Nullable<BuilderContent>) => {
6
6
  data?: {
7
7
  [key: string]: any;
8
8
  title?: string | undefined;
9
- blocks?: import("../../types/builder-block.js").BuilderBlock[] | undefined;
9
+ blocks?: import("../../server-index.js").BuilderBlock[] | undefined;
10
10
  inputs?: import("../../types/input.js").Input[] | undefined;
11
11
  state?: {
12
12
  [key: string]: any;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.12.7";
1
+ export declare const SDK_VERSION = "0.12.8";
@@ -0,0 +1,35 @@
1
+ import type { ContentProps } from '../components/content/content.types.js';
2
+ import type { BuilderAnimation } from '../types/builder-block.js';
3
+ import type { BuilderContent } from '../types/builder-content.js';
4
+ type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
5
+ callbacks: {
6
+ contentUpdate: (updatedContent: BuilderContent) => void;
7
+ animation: (updatedContent: BuilderAnimation) => void;
8
+ configureSdk: (updatedContent: any) => void;
9
+ };
10
+ };
11
+ export declare const createEditorListener: ({ model, trustedHosts, callbacks }: ContentListener) => (event: MessageEvent<any>) => void;
12
+ type SubscribeToEditor = (
13
+ /**
14
+ * The Builder `model` to subscribe to
15
+ */
16
+ model: string,
17
+ /**
18
+ * The callback function to call when the content is updated.
19
+ */
20
+ callback: (updatedContent: BuilderContent) => void,
21
+ /**
22
+ * Extra options for the listener.
23
+ */
24
+ options?: {
25
+ /**
26
+ * List of hosts to allow editing content from.
27
+ */
28
+ trustedHosts?: string[] | undefined;
29
+ }) => () => void;
30
+ /**
31
+ * Subscribes to the Builder editor and listens to `content` updates of a certain `model`.
32
+ * Sends the updated `content` to the `callback` function.
33
+ */
34
+ export declare const subscribeToEditor: SubscribeToEditor;
35
+ export {};
@@ -1,4 +1,7 @@
1
1
  export * from './index-helpers/top-of-file.js';
2
+ /**
3
+ * Component Prop types
4
+ */
2
5
  export type { ButtonProps } from './blocks/button/button.types.js';
3
6
  export type { ColumnProps } from './blocks/columns/columns.types.js';
4
7
  export type { FragmentProps } from './blocks/fragment/fragment.types.js';
@@ -9,6 +12,16 @@ export type { TextProps } from './blocks/text/text.types.js';
9
12
  export type { VideoProps } from './blocks/video/video.types.js';
10
13
  export type { BlocksProps } from './components/blocks/blocks.types.js';
11
14
  export type { ContentVariantsPrps as ContentProps } from './components/content-variants/content-variants.types.js';
15
+ /**
16
+ * General Builder types
17
+ */
18
+ export type { RegisteredComponent } from './context/types.js';
19
+ export type { BuilderBlock } from './types/builder-block.js';
20
+ export type { BuilderContent } from './types/builder-content.js';
21
+ export type { ComponentInfo } from './types/components.js';
22
+ /**
23
+ * Helper functions
24
+ */
12
25
  export { isEditing } from './functions/is-editing.js';
13
26
  export { isPreviewing } from './functions/is-previewing.js';
14
27
  export { createRegisterComponentMessage } from './functions/register-component.js';
@@ -16,9 +29,11 @@ export { register } from './functions/register.js';
16
29
  export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
17
30
  export { setEditorSettings } from './functions/set-editor-settings.js';
18
31
  export type { Settings } from './functions/set-editor-settings.js';
19
- export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';
20
32
  export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
21
33
  export { track } from './functions/track/index.js';
22
- export type { RegisteredComponent } from './context/types.js';
23
- export type { ComponentInfo } from './types/components.js';
34
+ export { subscribeToEditor } from './helpers/subscribe-to-editor.js';
35
+ /**
36
+ * Content fetching
37
+ */
24
38
  export { fetchBuilderProps } from './functions/fetch-builder-props.js';
39
+ export { _processContentResult, fetchEntries, fetchOneEntry, getAllContent, getContent } from './functions/get-content/index.js';