@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.
package/lib/node/index.js CHANGED
@@ -3358,8 +3358,8 @@ var generateContentUrl = (options) => {
3358
3358
  if (!apiKey) {
3359
3359
  throw new Error("Missing API key");
3360
3360
  }
3361
- if (!["v2", "v3"].includes(apiVersion)) {
3362
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
3361
+ if (!["v3"].includes(apiVersion)) {
3362
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
3363
3363
  }
3364
3364
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
3365
3365
  noTraverse = true;
@@ -3479,13 +3479,6 @@ async function fetchEntries(options) {
3479
3479
  }
3480
3480
  var getAllContent = fetchEntries;
3481
3481
 
3482
- // src/functions/is-from-trusted-host.ts
3483
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3484
- function isFromTrustedHost(trustedHosts, e) {
3485
- const url = new URL(e.origin), hostname = url.hostname;
3486
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3487
- }
3488
-
3489
3482
  // src/functions/is-previewing.ts
3490
3483
  function isPreviewing() {
3491
3484
  if (!isBrowser()) {
@@ -3733,8 +3726,15 @@ var getInteractionPropertiesForEvent = (event) => {
3733
3726
  };
3734
3727
  };
3735
3728
 
3729
+ // src/functions/is-from-trusted-host.ts
3730
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3731
+ function isFromTrustedHost(trustedHosts, e) {
3732
+ const url = new URL(e.origin), hostname = url.hostname;
3733
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3734
+ }
3735
+
3736
3736
  // src/constants/sdk-version.ts
3737
- var SDK_VERSION = "0.12.7";
3737
+ var SDK_VERSION = "0.13.0";
3738
3738
 
3739
3739
  // src/functions/register.ts
3740
3740
  var registry = {};
@@ -3870,6 +3870,66 @@ var setupBrowserForEditing = (options = {}) => {
3870
3870
  }
3871
3871
  };
3872
3872
 
3873
+ // src/helpers/subscribe-to-editor.ts
3874
+ var createEditorListener = ({
3875
+ model,
3876
+ trustedHosts,
3877
+ callbacks
3878
+ }) => {
3879
+ return (event) => {
3880
+ if (!isFromTrustedHost(trustedHosts, event)) {
3881
+ return;
3882
+ }
3883
+ const {
3884
+ data
3885
+ } = event;
3886
+ if (data) {
3887
+ switch (data.type) {
3888
+ case "builder.configureSdk": {
3889
+ callbacks.configureSdk(data.data);
3890
+ break;
3891
+ }
3892
+ case "builder.triggerAnimation": {
3893
+ callbacks.animation(data.data);
3894
+ break;
3895
+ }
3896
+ case "builder.contentUpdate": {
3897
+ const messageContent = data.data;
3898
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3899
+ const contentData = messageContent.data;
3900
+ if (key === model) {
3901
+ callbacks.contentUpdate(contentData);
3902
+ }
3903
+ break;
3904
+ }
3905
+ }
3906
+ }
3907
+ };
3908
+ };
3909
+ var subscribeToEditor = (model, callback, options) => {
3910
+ if (!isBrowser) {
3911
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3912
+ return () => {
3913
+ };
3914
+ }
3915
+ setupBrowserForEditing();
3916
+ const listener = createEditorListener({
3917
+ callbacks: {
3918
+ contentUpdate: callback,
3919
+ animation: () => {
3920
+ },
3921
+ configureSdk: () => {
3922
+ }
3923
+ },
3924
+ model,
3925
+ trustedHosts: options?.trustedHosts
3926
+ });
3927
+ window.addEventListener("message", listener);
3928
+ return () => {
3929
+ window.removeEventListener("message", listener);
3930
+ };
3931
+ };
3932
+
3873
3933
  // src/components/content/components/enable-editor.tsx
3874
3934
  function EnableEditor(props) {
3875
3935
  const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
@@ -3913,16 +3973,11 @@ function EnableEditor(props) {
3913
3973
  }));
3914
3974
  }
3915
3975
  function processMessage(event) {
3916
- if (!isFromTrustedHost(props.trustedHosts, event)) {
3917
- return;
3918
- }
3919
- const {
3920
- data
3921
- } = event;
3922
- if (data) {
3923
- switch (data.type) {
3924
- case "builder.configureSdk": {
3925
- const messageContent = data.data;
3976
+ return createEditorListener({
3977
+ model: props.model,
3978
+ trustedHosts: props.trustedHosts,
3979
+ callbacks: {
3980
+ configureSdk: (messageContent) => {
3926
3981
  const {
3927
3982
  breakpoints,
3928
3983
  contentId
@@ -3936,26 +3991,18 @@ function EnableEditor(props) {
3936
3991
  breakpoints
3937
3992
  }
3938
3993
  });
3939
- }
3940
- setForceReRenderCount(forceReRenderCount() + 1);
3941
- break;
3942
- }
3943
- case "builder.triggerAnimation": {
3944
- triggerAnimation(data.data);
3945
- break;
3946
- }
3947
- case "builder.contentUpdate": {
3948
- const messageContent = data.data;
3949
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3950
- const contentData = messageContent.data;
3951
- if (key === props.model) {
3952
- mergeNewContent(contentData);
3953
3994
  setForceReRenderCount(forceReRenderCount() + 1);
3954
3995
  }
3955
- break;
3996
+ },
3997
+ animation: (animation) => {
3998
+ triggerAnimation(animation);
3999
+ },
4000
+ contentUpdate: (newContent) => {
4001
+ mergeNewContent(newContent);
4002
+ setForceReRenderCount(forceReRenderCount() + 1);
3956
4003
  }
3957
4004
  }
3958
- }
4005
+ })(event);
3959
4006
  }
3960
4007
  function evaluateJsCode() {
3961
4008
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -4798,4 +4845,4 @@ var fetchBuilderProps = async (_args) => {
4798
4845
  };
4799
4846
  };
4800
4847
 
4801
- 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 };
4848
+ 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 };
@@ -3034,8 +3034,8 @@ var generateContentUrl = (options) => {
3034
3034
  if (!apiKey) {
3035
3035
  throw new Error("Missing API key");
3036
3036
  }
3037
- if (!["v2", "v3"].includes(apiVersion)) {
3038
- throw new Error(`Invalid apiVersion: expected 'v2' or 'v3', received '${apiVersion}'`);
3037
+ if (!["v3"].includes(apiVersion)) {
3038
+ throw new Error(`Invalid apiVersion: expected 'v3', received '${apiVersion}'`);
3039
3039
  }
3040
3040
  if ((options.limit === void 0 || options.limit > 1) && !("noTraverse" in options)) {
3041
3041
  noTraverse = true;
@@ -3155,13 +3155,6 @@ async function fetchEntries(options) {
3155
3155
  }
3156
3156
  var getAllContent = fetchEntries;
3157
3157
 
3158
- // src/functions/is-from-trusted-host.ts
3159
- var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3160
- function isFromTrustedHost(trustedHosts, e) {
3161
- const url = new URL(e.origin), hostname = url.hostname;
3162
- return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3163
- }
3164
-
3165
3158
  // src/functions/is-previewing.ts
3166
3159
  function isPreviewing() {
3167
3160
  if (!isBrowser()) {
@@ -3409,8 +3402,15 @@ var getInteractionPropertiesForEvent = (event) => {
3409
3402
  };
3410
3403
  };
3411
3404
 
3405
+ // src/functions/is-from-trusted-host.ts
3406
+ var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
3407
+ function isFromTrustedHost(trustedHosts, e) {
3408
+ const url = new URL(e.origin), hostname = url.hostname;
3409
+ return (trustedHosts || DEFAULT_TRUSTED_HOSTS).findIndex((trustedHost) => trustedHost.startsWith("*.") ? hostname.endsWith(trustedHost.slice(1)) : trustedHost === hostname) > -1;
3410
+ }
3411
+
3412
3412
  // src/constants/sdk-version.ts
3413
- var SDK_VERSION = "0.12.7";
3413
+ var SDK_VERSION = "0.13.0";
3414
3414
 
3415
3415
  // src/functions/register.ts
3416
3416
  var registry = {};
@@ -3546,6 +3546,66 @@ var setupBrowserForEditing = (options = {}) => {
3546
3546
  }
3547
3547
  };
3548
3548
 
3549
+ // src/helpers/subscribe-to-editor.ts
3550
+ var createEditorListener = ({
3551
+ model,
3552
+ trustedHosts,
3553
+ callbacks
3554
+ }) => {
3555
+ return (event) => {
3556
+ if (!isFromTrustedHost(trustedHosts, event)) {
3557
+ return;
3558
+ }
3559
+ const {
3560
+ data
3561
+ } = event;
3562
+ if (data) {
3563
+ switch (data.type) {
3564
+ case "builder.configureSdk": {
3565
+ callbacks.configureSdk(data.data);
3566
+ break;
3567
+ }
3568
+ case "builder.triggerAnimation": {
3569
+ callbacks.animation(data.data);
3570
+ break;
3571
+ }
3572
+ case "builder.contentUpdate": {
3573
+ const messageContent = data.data;
3574
+ const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3575
+ const contentData = messageContent.data;
3576
+ if (key === model) {
3577
+ callbacks.contentUpdate(contentData);
3578
+ }
3579
+ break;
3580
+ }
3581
+ }
3582
+ }
3583
+ };
3584
+ };
3585
+ var subscribeToEditor = (model, callback, options) => {
3586
+ if (!isBrowser) {
3587
+ logger.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server.");
3588
+ return () => {
3589
+ };
3590
+ }
3591
+ setupBrowserForEditing();
3592
+ const listener = createEditorListener({
3593
+ callbacks: {
3594
+ contentUpdate: callback,
3595
+ animation: () => {
3596
+ },
3597
+ configureSdk: () => {
3598
+ }
3599
+ },
3600
+ model,
3601
+ trustedHosts: options?.trustedHosts
3602
+ });
3603
+ window.addEventListener("message", listener);
3604
+ return () => {
3605
+ window.removeEventListener("message", listener);
3606
+ };
3607
+ };
3608
+
3549
3609
  // src/components/content/components/enable-editor.tsx
3550
3610
  function EnableEditor(props) {
3551
3611
  const [forceReRenderCount, setForceReRenderCount] = createSignal10(0);
@@ -3591,14 +3651,11 @@ function EnableEditor(props) {
3591
3651
  }));
3592
3652
  }
3593
3653
  function processMessage(event) {
3594
- if (!isFromTrustedHost(props.trustedHosts, event)) {
3595
- return;
3596
- }
3597
- const { data } = event;
3598
- if (data) {
3599
- switch (data.type) {
3600
- case "builder.configureSdk": {
3601
- const messageContent = data.data;
3654
+ return createEditorListener({
3655
+ model: props.model,
3656
+ trustedHosts: props.trustedHosts,
3657
+ callbacks: {
3658
+ configureSdk: (messageContent) => {
3602
3659
  const { breakpoints, contentId } = messageContent;
3603
3660
  if (!contentId || contentId !== props.builderContextSignal.content?.id) {
3604
3661
  return;
@@ -3609,26 +3666,18 @@ function EnableEditor(props) {
3609
3666
  breakpoints
3610
3667
  }
3611
3668
  });
3612
- }
3613
- setForceReRenderCount(forceReRenderCount() + 1);
3614
- break;
3615
- }
3616
- case "builder.triggerAnimation": {
3617
- triggerAnimation(data.data);
3618
- break;
3619
- }
3620
- case "builder.contentUpdate": {
3621
- const messageContent = data.data;
3622
- const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
3623
- const contentData = messageContent.data;
3624
- if (key === props.model) {
3625
- mergeNewContent(contentData);
3626
3669
  setForceReRenderCount(forceReRenderCount() + 1);
3627
3670
  }
3628
- break;
3671
+ },
3672
+ animation: (animation) => {
3673
+ triggerAnimation(animation);
3674
+ },
3675
+ contentUpdate: (newContent) => {
3676
+ mergeNewContent(newContent);
3677
+ setForceReRenderCount(forceReRenderCount() + 1);
3629
3678
  }
3630
3679
  }
3631
- }
3680
+ })(event);
3632
3681
  }
3633
3682
  function evaluateJsCode() {
3634
3683
  const jsCode = props.builderContextSignal.content?.data?.jsCode;
@@ -4321,5 +4370,6 @@ export {
4321
4370
  isPreviewing,
4322
4371
  register,
4323
4372
  setEditorSettings,
4373
+ subscribeToEditor,
4324
4374
  track
4325
4375
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.12.7",
3
+ "version": "0.13.0",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist",