@builder.io/sdk-solid 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.
@@ -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.12.8";
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.12.8",
4
4
  "description": "",
5
5
  "files": [
6
6
  "dist",