@builder.io/sdk-solid 0.12.7 → 0.13.0

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.
@@ -3235,8 +3235,8 @@ var generateContentUrl = (options) => {
3235
3235
  if (!apiKey) {
3236
3236
  throw new Error("Missing API key");
3237
3237
  }
3238
- if (!["v2", "v3"].includes(apiVersion)) {
3239
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
3238
+ if (!["v3"].includes(apiVersion)) {
3239
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
3240
3240
  }
3241
3241
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
3242
3242
  noTraverse = true;
@@ -3356,13 +3356,6 @@ async function fetchEntries(options) {
3356
3356
  }
3357
3357
  var getAllContent = fetchEntries;
3358
3358
 
3359
- // src/functions/is-from-trusted-host.ts
3360
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3361
- function isFromTrustedHost(trustedHosts, e) {
3362
- const url = new URL(e.origin), hostname = url.hostname;
3363
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3364
- }
3365
-
3366
3359
  // src/functions/is-previewing.ts
3367
3360
  function isPreviewing() {
3368
3361
  if (!isBrowser()) {
@@ -3610,8 +3603,15 @@ var getInteractionPropertiesForEvent = (event) => {
3610
3603
  };
3611
3604
  };
3612
3605
 
3606
+ // src/functions/is-from-trusted-host.ts
3607
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3608
+ function isFromTrustedHost(trustedHosts, e) {
3609
+ const url = new URL(e.origin), hostname = url.hostname;
3610
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3611
+ }
3612
+
3613
3613
  // src/constants/sdk-version.ts
3614
- var SDK_VERSION = "0.12.7";
3614
+ var SDK_VERSION = "0.13.0";
3615
3615
 
3616
3616
  // src/functions/register.ts
3617
3617
  var registry = {};
@@ -3747,6 +3747,66 @@ var setupBrowserForEditing = (options = {}) => {
3747
3747
  }
3748
3748
  };
3749
3749
 
3750
+ // src/helpers/subscribe-to-editor.ts
3751
+ var createEditorListener = ({
3752
+ model,
3753
+ trustedHosts,
3754
+ callbacks
3755
+ }) => {
3756
+ return (event) => {
3757
+ if (!isFromTrustedHost(trustedHosts, event)) {
3758
+ return;
3759
+ }
3760
+ const {
3761
+ data
3762
+ } = event;
3763
+ if (data) {
3764
+ switch (data.type) {
3765
+ case "builder.configureSdk": {
3766
+ callbacks.configureSdk(data.data);
3767
+ break;
3768
+ }
3769
+ case "builder.triggerAnimation": {
3770
+ callbacks.animation(data.data);
3771
+ break;
3772
+ }
3773
+ case "builder.contentUpdate": {
3774
+ const messageContent = data.data;
3775
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3776
+ const contentData = messageContent.data;
3777
+ if (key === model) {
3778
+ callbacks.contentUpdate(contentData);
3779
+ }
3780
+ break;
3781
+ }
3782
+ }
3783
+ }
3784
+ };
3785
+ };
3786
+ var subscribeToEditor = (model, callback, options) => {
3787
+ if (!isBrowser) {
3788
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3789
+ return () => {
3790
+ };
3791
+ }
3792
+ setupBrowserForEditing();
3793
+ const listener = createEditorListener({
3794
+ callbacks: {
3795
+ contentUpdate: callback,
3796
+ animation: () => {
3797
+ },
3798
+ configureSdk: () => {
3799
+ }
3800
+ },
3801
+ model,
3802
+ trustedHosts: options?.trustedHosts
3803
+ });
3804
+ window.addEventListener("message", listener);
3805
+ return () => {
3806
+ window.removeEventListener("message", listener);
3807
+ };
3808
+ };
3809
+
3750
3810
  // src/components/content/components/enable-editor.tsx
3751
3811
  function EnableEditor(props) {
3752
3812
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -3790,16 +3850,11 @@ function EnableEditor(props) {
3790
3850
  }));
3791
3851
  }
3792
3852
  function processMessage(event) {
3793
- if (!isFromTrustedHost(props.trustedHosts, event)) {
3794
- return;
3795
- }
3796
- const {
3797
- data
3798
- } = event;
3799
- if (data) {
3800
- switch (data.type) {
3801
- case "builder.configureSdk": {
3802
- const messageContent = data.data;
3853
+ return createEditorListener({
3854
+ model: props.model,
3855
+ trustedHosts: props.trustedHosts,
3856
+ callbacks: {
3857
+ configureSdk: (messageContent) => {
3803
3858
  const {
3804
3859
  breakpoints,
3805
3860
  contentId
@@ -3813,26 +3868,18 @@ function EnableEditor(props) {
3813
3868
  breakpoints
3814
3869
  }
3815
3870
  });
3816
- }
3817
- setForceReRenderCount(forceReRenderCount() + 1);
3818
- break;
3819
- }
3820
- case "builder.triggerAnimation": {
3821
- triggerAnimation(data.data);
3822
- break;
3823
- }
3824
- case "builder.contentUpdate": {
3825
- const messageContent = data.data;
3826
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3827
- const contentData = messageContent.data;
3828
- if (key === props.model) {
3829
- mergeNewContent(contentData);
3830
3871
  setForceReRenderCount(forceReRenderCount() + 1);
3831
3872
  }
3832
- break;
3873
+ },
3874
+ animation: (animation) => {
3875
+ triggerAnimation(animation);
3876
+ },
3877
+ contentUpdate: (newContent) => {
3878
+ mergeNewContent(newContent);
3879
+ setForceReRenderCount(forceReRenderCount() + 1);
3833
3880
  }
3834
3881
  }
3835
- }
3882
+ })(event);
3836
3883
  }
3837
3884
  function evaluateJsCode() {
3838
3885
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -4675,4 +4722,4 @@ var fetchBuilderProps = async (_args) => {
4675
4722
  };
4676
4723
  };
4677
4724
 
4678
- 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 };
4725
+ 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 };
@@ -2909,8 +2909,8 @@ var generateContentUrl = (options) => {
2909
2909
  if (!apiKey) {
2910
2910
  throw new Error("Missing API key");
2911
2911
  }
2912
- if (!["v2", "v3"].includes(apiVersion)) {
2913
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
2912
+ if (!["v3"].includes(apiVersion)) {
2913
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
2914
2914
  }
2915
2915
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
2916
2916
  noTraverse = true;
@@ -3030,13 +3030,6 @@ async function fetchEntries(options) {
3030
3030
  }
3031
3031
  var getAllContent = fetchEntries;
3032
3032
 
3033
- // src/functions/is-from-trusted-host.ts
3034
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3035
- function isFromTrustedHost(trustedHosts, e) {
3036
- const url = new URL(e.origin), hostname = url.hostname;
3037
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3038
- }
3039
-
3040
3033
  // src/functions/is-previewing.ts
3041
3034
  function isPreviewing() {
3042
3035
  if (!isBrowser()) {
@@ -3284,8 +3277,15 @@ var getInteractionPropertiesForEvent = (event) => {
3284
3277
  };
3285
3278
  };
3286
3279
 
3280
+ // src/functions/is-from-trusted-host.ts
3281
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3282
+ function isFromTrustedHost(trustedHosts, e) {
3283
+ const url = new URL(e.origin), hostname = url.hostname;
3284
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3285
+ }
3286
+
3287
3287
  // src/constants/sdk-version.ts
3288
- var SDK_VERSION = "0.12.7";
3288
+ var SDK_VERSION = "0.13.0";
3289
3289
 
3290
3290
  // src/functions/register.ts
3291
3291
  var registry = {};
@@ -3421,6 +3421,66 @@ var setupBrowserForEditing = (options = {}) => {
3421
3421
  }
3422
3422
  };
3423
3423
 
3424
+ // src/helpers/subscribe-to-editor.ts
3425
+ var createEditorListener = ({
3426
+ model,
3427
+ trustedHosts,
3428
+ callbacks
3429
+ }) => {
3430
+ return (event) => {
3431
+ if (!isFromTrustedHost(trustedHosts, event)) {
3432
+ return;
3433
+ }
3434
+ const {
3435
+ data
3436
+ } = event;
3437
+ if (data) {
3438
+ switch (data.type) {
3439
+ case "builder.configureSdk": {
3440
+ callbacks.configureSdk(data.data);
3441
+ break;
3442
+ }
3443
+ case "builder.triggerAnimation": {
3444
+ callbacks.animation(data.data);
3445
+ break;
3446
+ }
3447
+ case "builder.contentUpdate": {
3448
+ const messageContent = data.data;
3449
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3450
+ const contentData = messageContent.data;
3451
+ if (key === model) {
3452
+ callbacks.contentUpdate(contentData);
3453
+ }
3454
+ break;
3455
+ }
3456
+ }
3457
+ }
3458
+ };
3459
+ };
3460
+ var subscribeToEditor = (model, callback, options) => {
3461
+ if (!isBrowser) {
3462
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3463
+ return () => {
3464
+ };
3465
+ }
3466
+ setupBrowserForEditing();
3467
+ const listener = createEditorListener({
3468
+ callbacks: {
3469
+ contentUpdate: callback,
3470
+ animation: () => {
3471
+ },
3472
+ configureSdk: () => {
3473
+ }
3474
+ },
3475
+ model,
3476
+ trustedHosts: options?.trustedHosts
3477
+ });
3478
+ window.addEventListener("message", listener);
3479
+ return () => {
3480
+ window.removeEventListener("message", listener);
3481
+ };
3482
+ };
3483
+
3424
3484
  // src/components/content/components/enable-editor.tsx
3425
3485
  function EnableEditor(props) {
3426
3486
  const [forceReRenderCount, setForceReRenderCount] = createSignal10(0);
@@ -3466,14 +3526,11 @@ function EnableEditor(props) {
3466
3526
  }));
3467
3527
  }
3468
3528
  function processMessage(event) {
3469
- if (!isFromTrustedHost(props.trustedHosts, event)) {
3470
- return;
3471
- }
3472
- const { data } = event;
3473
- if (data) {
3474
- switch (data.type) {
3475
- case "builder.configureSdk": {
3476
- const messageContent = data.data;
3529
+ return createEditorListener({
3530
+ model: props.model,
3531
+ trustedHosts: props.trustedHosts,
3532
+ callbacks: {
3533
+ configureSdk: (messageContent) => {
3477
3534
  const { breakpoints, contentId } = messageContent;
3478
3535
  if (!contentId || contentId !== props.builderContextSignal.content?.id) {
3479
3536
  return;
@@ -3484,26 +3541,18 @@ function EnableEditor(props) {
3484
3541
  breakpoints
3485
3542
  }
3486
3543
  });
3487
- }
3488
- setForceReRenderCount(forceReRenderCount() + 1);
3489
- break;
3490
- }
3491
- case "builder.triggerAnimation": {
3492
- triggerAnimation(data.data);
3493
- break;
3494
- }
3495
- case "builder.contentUpdate": {
3496
- const messageContent = data.data;
3497
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3498
- const contentData = messageContent.data;
3499
- if (key === props.model) {
3500
- mergeNewContent(contentData);
3501
3544
  setForceReRenderCount(forceReRenderCount() + 1);
3502
3545
  }
3503
- break;
3546
+ },
3547
+ animation: (animation) => {
3548
+ triggerAnimation(animation);
3549
+ },
3550
+ contentUpdate: (newContent) => {
3551
+ mergeNewContent(newContent);
3552
+ setForceReRenderCount(forceReRenderCount() + 1);
3504
3553
  }
3505
3554
  }
3506
- }
3555
+ })(event);
3507
3556
  }
3508
3557
  function evaluateJsCode() {
3509
3558
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -4196,5 +4245,6 @@ export {
4196
4245
  isPreviewing,
4197
4246
  register,
4198
4247
  setEditorSettings,
4248
+ subscribeToEditor,
4199
4249
  track
4200
4250
  };
package/lib/edge/dev.js CHANGED
@@ -6400,8 +6400,8 @@ var generateContentUrl = (options) => {
6400
6400
  if (!apiKey) {
6401
6401
  throw new Error("Missing API key");
6402
6402
  }
6403
- if (!["v2", "v3"].includes(apiVersion)) {
6404
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
6403
+ if (!["v3"].includes(apiVersion)) {
6404
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
6405
6405
  }
6406
6406
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
6407
6407
  noTraverse = true;
@@ -6521,13 +6521,6 @@ async function fetchEntries(options) {
6521
6521
  }
6522
6522
  var getAllContent = fetchEntries;
6523
6523
 
6524
- // src/functions/is-from-trusted-host.ts
6525
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6526
- function isFromTrustedHost(trustedHosts, e) {
6527
- const url = new URL(e.origin), hostname = url.hostname;
6528
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6529
- }
6530
-
6531
6524
  // src/functions/is-previewing.ts
6532
6525
  function isPreviewing() {
6533
6526
  if (!isBrowser()) {
@@ -6778,8 +6771,15 @@ var getInteractionPropertiesForEvent = (event) => {
6778
6771
  };
6779
6772
  };
6780
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
+
6781
6781
  // src/constants/sdk-version.ts
6782
- var SDK_VERSION = "0.12.7";
6782
+ var SDK_VERSION = "0.13.0";
6783
6783
 
6784
6784
  // src/functions/register.ts
6785
6785
  var registry = {};
@@ -6916,6 +6916,66 @@ var setupBrowserForEditing = (options = {}) => {
6916
6916
  }
6917
6917
  };
6918
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
+
6919
6979
  // src/components/content/components/enable-editor.tsx
6920
6980
  function EnableEditor(props) {
6921
6981
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -6959,16 +7019,11 @@ function EnableEditor(props) {
6959
7019
  }));
6960
7020
  }
6961
7021
  function processMessage(event) {
6962
- if (!isFromTrustedHost(props.trustedHosts, event)) {
6963
- return;
6964
- }
6965
- const {
6966
- data
6967
- } = event;
6968
- if (data) {
6969
- switch (data.type) {
6970
- case "builder.configureSdk": {
6971
- const messageContent = data.data;
7022
+ return createEditorListener({
7023
+ model: props.model,
7024
+ trustedHosts: props.trustedHosts,
7025
+ callbacks: {
7026
+ configureSdk: (messageContent) => {
6972
7027
  const {
6973
7028
  breakpoints,
6974
7029
  contentId
@@ -6982,26 +7037,18 @@ function EnableEditor(props) {
6982
7037
  breakpoints
6983
7038
  }
6984
7039
  });
6985
- }
6986
- setForceReRenderCount(forceReRenderCount() + 1);
6987
- break;
6988
- }
6989
- case "builder.triggerAnimation": {
6990
- triggerAnimation(data.data);
6991
- break;
6992
- }
6993
- case "builder.contentUpdate": {
6994
- const messageContent = data.data;
6995
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6996
- const contentData = messageContent.data;
6997
- if (key === props.model) {
6998
- mergeNewContent(contentData);
6999
7040
  setForceReRenderCount(forceReRenderCount() + 1);
7000
7041
  }
7001
- break;
7042
+ },
7043
+ animation: (animation) => {
7044
+ triggerAnimation(animation);
7045
+ },
7046
+ contentUpdate: (newContent) => {
7047
+ mergeNewContent(newContent);
7048
+ setForceReRenderCount(forceReRenderCount() + 1);
7002
7049
  }
7003
7050
  }
7004
- }
7051
+ })(event);
7005
7052
  }
7006
7053
  function evaluateJsCode() {
7007
7054
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -7845,4 +7892,4 @@ var fetchBuilderProps = async (_args) => {
7845
7892
  };
7846
7893
  };
7847
7894
 
7848
- 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 };
package/lib/edge/dev.jsx CHANGED
@@ -6076,8 +6076,8 @@ var generateContentUrl = (options) => {
6076
6076
  if (!apiKey) {
6077
6077
  throw new Error("Missing API key");
6078
6078
  }
6079
- if (!["v2", "v3"].includes(apiVersion)) {
6080
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
6079
+ if (!["v3"].includes(apiVersion)) {
6080
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
6081
6081
  }
6082
6082
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
6083
6083
  noTraverse = true;
@@ -6197,13 +6197,6 @@ async function fetchEntries(options) {
6197
6197
  }
6198
6198
  var getAllContent = fetchEntries;
6199
6199
 
6200
- // src/functions/is-from-trusted-host.ts
6201
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6202
- function isFromTrustedHost(trustedHosts, e) {
6203
- const url = new URL(e.origin), hostname = url.hostname;
6204
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6205
- }
6206
-
6207
6200
  // src/functions/is-previewing.ts
6208
6201
  function isPreviewing() {
6209
6202
  if (!isBrowser()) {
@@ -6454,8 +6447,15 @@ var getInteractionPropertiesForEvent = (event) => {
6454
6447
  };
6455
6448
  };
6456
6449
 
6450
+ // src/functions/is-from-trusted-host.ts
6451
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
6452
+ function isFromTrustedHost(trustedHosts, e) {
6453
+ const url = new URL(e.origin), hostname = url.hostname;
6454
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
6455
+ }
6456
+
6457
6457
  // src/constants/sdk-version.ts
6458
- var SDK_VERSION = "0.12.7";
6458
+ var SDK_VERSION = "0.13.0";
6459
6459
 
6460
6460
  // src/functions/register.ts
6461
6461
  var registry = {};
@@ -6592,6 +6592,66 @@ var setupBrowserForEditing = (options = {}) => {
6592
6592
  }
6593
6593
  };
6594
6594
 
6595
+ // src/helpers/subscribe-to-editor.ts
6596
+ var createEditorListener = ({
6597
+ model,
6598
+ trustedHosts,
6599
+ callbacks
6600
+ }) => {
6601
+ return (event) => {
6602
+ if (!isFromTrustedHost(trustedHosts, event)) {
6603
+ return;
6604
+ }
6605
+ const {
6606
+ data
6607
+ } = event;
6608
+ if (data) {
6609
+ switch (data.type) {
6610
+ case "builder.configureSdk": {
6611
+ callbacks.configureSdk(data.data);
6612
+ break;
6613
+ }
6614
+ case "builder.triggerAnimation": {
6615
+ callbacks.animation(data.data);
6616
+ break;
6617
+ }
6618
+ case "builder.contentUpdate": {
6619
+ const messageContent = data.data;
6620
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6621
+ const contentData = messageContent.data;
6622
+ if (key === model) {
6623
+ callbacks.contentUpdate(contentData);
6624
+ }
6625
+ break;
6626
+ }
6627
+ }
6628
+ }
6629
+ };
6630
+ };
6631
+ var subscribeToEditor = (model, callback, options) => {
6632
+ if (!isBrowser) {
6633
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
6634
+ return () => {
6635
+ };
6636
+ }
6637
+ setupBrowserForEditing();
6638
+ const listener = createEditorListener({
6639
+ callbacks: {
6640
+ contentUpdate: callback,
6641
+ animation: () => {
6642
+ },
6643
+ configureSdk: () => {
6644
+ }
6645
+ },
6646
+ model,
6647
+ trustedHosts: options?.trustedHosts
6648
+ });
6649
+ window.addEventListener("message", listener);
6650
+ return () => {
6651
+ window.removeEventListener("message", listener);
6652
+ };
6653
+ };
6654
+
6595
6655
  // src/components/content/components/enable-editor.tsx
6596
6656
  function EnableEditor(props) {
6597
6657
  const [forceReRenderCount, setForceReRenderCount] = createSignal10(0);
@@ -6637,14 +6697,11 @@ function EnableEditor(props) {
6637
6697
  }));
6638
6698
  }
6639
6699
  function processMessage(event) {
6640
- if (!isFromTrustedHost(props.trustedHosts, event)) {
6641
- return;
6642
- }
6643
- const { data } = event;
6644
- if (data) {
6645
- switch (data.type) {
6646
- case "builder.configureSdk": {
6647
- const messageContent = data.data;
6700
+ return createEditorListener({
6701
+ model: props.model,
6702
+ trustedHosts: props.trustedHosts,
6703
+ callbacks: {
6704
+ configureSdk: (messageContent) => {
6648
6705
  const { breakpoints, contentId } = messageContent;
6649
6706
  if (!contentId || contentId !== props.builderContextSignal.content?.id) {
6650
6707
  return;
@@ -6655,26 +6712,18 @@ function EnableEditor(props) {
6655
6712
  breakpoints
6656
6713
  }
6657
6714
  });
6658
- }
6659
- setForceReRenderCount(forceReRenderCount() + 1);
6660
- break;
6661
- }
6662
- case "builder.triggerAnimation": {
6663
- triggerAnimation(data.data);
6664
- break;
6665
- }
6666
- case "builder.contentUpdate": {
6667
- const messageContent = data.data;
6668
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
6669
- const contentData = messageContent.data;
6670
- if (key === props.model) {
6671
- mergeNewContent(contentData);
6672
6715
  setForceReRenderCount(forceReRenderCount() + 1);
6673
6716
  }
6674
- break;
6717
+ },
6718
+ animation: (animation) => {
6719
+ triggerAnimation(animation);
6720
+ },
6721
+ contentUpdate: (newContent) => {
6722
+ mergeNewContent(newContent);
6723
+ setForceReRenderCount(forceReRenderCount() + 1);
6675
6724
  }
6676
6725
  }
6677
- }
6726
+ })(event);
6678
6727
  }
6679
6728
  function evaluateJsCode() {
6680
6729
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -7368,5 +7417,6 @@ export {
7368
7417
  isPreviewing,
7369
7418
  register,
7370
7419
  setEditorSettings,
7420
+ subscribeToEditor,
7371
7421
  track
7372
7422
  };