@builder.io/sdk-solid 4.1.3 → 4.2.1

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/dist/index.d.ts CHANGED
@@ -814,6 +814,22 @@ type DeepPartial<T> = {
814
814
  [P in keyof T]?: T[P] extends Array<infer U> ? Array<DeepPartial<U>> : T[P] extends ReadonlyArray<infer U> ? ReadonlyArray<DeepPartial<U>> : DeepPartial<T[P]>;
815
815
  };
816
816
 
817
+ interface Action {
818
+ name: string;
819
+ inputs?: readonly Input[];
820
+ returnType?: Input;
821
+ action: (options: Record<string, any>) => string;
822
+ /**
823
+ * Is an action for expression (e.g. calculating a binding like a formula
824
+ * to fill a value based on locale) or a function (e.g. something to trigger
825
+ * on an event like add to cart) or either (e.g. a custom code block)
826
+ */
827
+ kind: 'expression' | 'function' | 'any';
828
+ /**
829
+ * Globally unique ID for an action, e.g. "@builder.io:setState"
830
+ */
831
+ id: string;
832
+ }
817
833
  interface InsertMenuItem {
818
834
  name: string;
819
835
  icon?: string;
@@ -828,6 +844,7 @@ interface InsertMenuConfig {
828
844
  }
829
845
  declare function register(type: 'insertMenu', info: InsertMenuConfig): void;
830
846
  declare function register(type: string, info: any): void;
847
+ declare function registerAction(action: Action): void;
831
848
 
832
849
  type Settings = {
833
850
  customInsertMenu?: boolean;
@@ -1123,4 +1140,4 @@ declare const _processContentResult: (options: GetContentOptions, content: Conte
1123
1140
  */
1124
1141
  declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
1125
1142
 
1126
- export { Blocks, BlocksProps, BuilderBlock, BuilderContent, _default as BuilderContext, BuilderContextInterface, Button, ButtonProps, ColumnProps, Columns, ComponentInfo, ContentVariants as Content, ContentVariantsPrps as ContentProps, FragmentComponent as Fragment, FragmentProps, GetContentOptions, Image, ImageProps, InsertMenuConfig, InsertMenuItem, RegisteredComponent, RegisteredComponents, SectionComponent as Section, SectionProps, Settings, Symbol, SymbolProps, Text, TextProps, Video, VideoProps, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, setClientUserAttributes, setEditorSettings, subscribeToEditor, track };
1143
+ export { Blocks, BlocksProps, BuilderBlock, BuilderContent, _default as BuilderContext, BuilderContextInterface, Button, ButtonProps, ColumnProps, Columns, ComponentInfo, ContentVariants as Content, ContentVariantsPrps as ContentProps, FragmentComponent as Fragment, FragmentProps, GetContentOptions, Image, ImageProps, InsertMenuConfig, InsertMenuItem, RegisteredComponent, RegisteredComponents, SectionComponent as Section, SectionProps, Settings, Symbol, SymbolProps, Text, TextProps, Video, VideoProps, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, registerAction, setClientUserAttributes, setEditorSettings, subscribeToEditor, track };
@@ -4512,9 +4512,9 @@ function logFetch(url) {
4512
4512
  }
4513
4513
 
4514
4514
  // src/blocks/form/form/form.tsx
4515
- var _tmpl$15 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-7430044e">`);
4515
+ var _tmpl$15 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-fdf23968">`);
4516
4516
  var _tmpl$26 = /* @__PURE__ */ template(`<form>`);
4517
- var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-7430044e {
4517
+ var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-fdf23968 {
4518
4518
  padding: 10px;
4519
4519
  color: red;
4520
4520
  text-align: center;
@@ -4551,13 +4551,13 @@ function FormComponent(props) {
4551
4551
  const headers = props.customHeaders || {};
4552
4552
  let body;
4553
4553
  const formData = new FormData(el);
4554
- const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).map((el2) => {
4554
+ const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).filter((el2) => !!el2.name && (el2.type !== "radio" || el2.checked)).map((el2) => {
4555
4555
  let value;
4556
4556
  const key = el2.name;
4557
4557
  if (el2 instanceof HTMLInputElement) {
4558
4558
  if (el2.type === "radio") {
4559
4559
  if (el2.checked) {
4560
- value = el2.name;
4560
+ value = el2.value;
4561
4561
  return {
4562
4562
  key,
4563
4563
  value
@@ -5502,7 +5502,7 @@ function getPreviewContent(_searchParams) {
5502
5502
  }
5503
5503
 
5504
5504
  // src/constants/sdk-version.ts
5505
- var SDK_VERSION = "4.1.3";
5505
+ var SDK_VERSION = "4.2.1";
5506
5506
 
5507
5507
  // src/helpers/sdk-headers.ts
5508
5508
  var getSdkHeaders = () => ({
@@ -6408,13 +6408,15 @@ function EnableEditor(props) {
6408
6408
  }
6409
6409
  function runHttpRequests() {
6410
6410
  const requests = props.builderContextSignal.content?.data?.httpRequests ?? {};
6411
- Object.entries(requests).forEach(([key, url]) => {
6412
- if (!url)
6411
+ Object.entries(requests).forEach(([key, httpRequest]) => {
6412
+ if (!httpRequest)
6413
6413
  return;
6414
+ const isCoreRequest = typeof httpRequest === "object" && httpRequest["@type"] === "@builder.io/core:Request";
6414
6415
  if (httpReqsPending()[key])
6415
6416
  return;
6416
6417
  if (httpReqsData()[key] && !isEditing())
6417
6418
  return;
6419
+ const url = isCoreRequest ? httpRequest.request.url : httpRequest;
6418
6420
  httpReqsPending()[key] = true;
6419
6421
  const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
6420
6422
  code: group,
@@ -6423,14 +6425,27 @@ function EnableEditor(props) {
6423
6425
  rootState: props.builderContextSignal.rootState,
6424
6426
  rootSetState: props.builderContextSignal.rootSetState
6425
6427
  })));
6426
- logFetch(evaluatedUrl);
6427
- fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
6428
+ const fetchRequestObj = isCoreRequest ? {
6429
+ url: evaluatedUrl,
6430
+ method: httpRequest.request.method,
6431
+ headers: httpRequest.request.headers,
6432
+ body: httpRequest.request.body
6433
+ } : {
6434
+ url: evaluatedUrl,
6435
+ method: "GET"
6436
+ };
6437
+ logFetch(JSON.stringify(fetchRequestObj));
6438
+ fetch(fetchRequestObj.url, {
6439
+ method: fetchRequestObj.method,
6440
+ headers: fetchRequestObj.headers,
6441
+ body: fetchRequestObj.body
6442
+ }).then((response) => response.json()).then((json) => {
6428
6443
  mergeNewRootState({
6429
6444
  [key]: json
6430
6445
  });
6431
6446
  httpReqsData()[key] = true;
6432
6447
  }).catch((err) => {
6433
- console.error("error fetching dynamic data", url, err);
6448
+ console.error("error fetching dynamic data", JSON.stringify(httpRequest), err);
6434
6449
  }).finally(() => {
6435
6450
  httpReqsPending()[key] = false;
6436
6451
  });
@@ -7202,6 +7217,18 @@ function register(type, info) {
7202
7217
  }
7203
7218
  }
7204
7219
  }
7220
+ function registerAction(action) {
7221
+ if (isBrowser()) {
7222
+ const actionClone = JSON.parse(JSON.stringify(action));
7223
+ if (action.action) {
7224
+ actionClone.action = action.action.toString();
7225
+ }
7226
+ window.parent?.postMessage({
7227
+ type: "builder.registerAction",
7228
+ data: actionClone
7229
+ }, "*");
7230
+ }
7231
+ }
7205
7232
 
7206
7233
  // src/functions/set-editor-settings.ts
7207
7234
  var settings = {};
@@ -7238,4 +7265,4 @@ var fetchBuilderProps = async (_args) => {
7238
7265
  };
7239
7266
  };
7240
7267
 
7241
- export { blocks_default as Blocks, builder_context_default as BuilderContext, button_default as Button, columns_default as Columns, content_variants_default as Content, fragment_default as Fragment, image_default as Image, section_default as Section, symbol_default as Symbol, text_default as Text, video_default as Video, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, setClientUserAttributes, setEditorSettings, subscribeToEditor, track };
7268
+ export { blocks_default as Blocks, builder_context_default as BuilderContext, button_default as Button, columns_default as Columns, content_variants_default as Content, fragment_default as Fragment, image_default as Image, section_default as Section, symbol_default as Symbol, text_default as Text, video_default as Video, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, registerAction, setClientUserAttributes, setEditorSettings, subscribeToEditor, track };
@@ -4152,13 +4152,15 @@ function FormComponent(props) {
4152
4152
  const headers = props.customHeaders || {};
4153
4153
  let body;
4154
4154
  const formData = new FormData(el);
4155
- const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).map((el2) => {
4155
+ const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).filter(
4156
+ (el2) => !!el2.name && (el2.type !== "radio" || el2.checked)
4157
+ ).map((el2) => {
4156
4158
  let value;
4157
4159
  const key = el2.name;
4158
4160
  if (el2 instanceof HTMLInputElement) {
4159
4161
  if (el2.type === "radio") {
4160
4162
  if (el2.checked) {
4161
- value = el2.name;
4163
+ value = el2.value;
4162
4164
  return {
4163
4165
  key,
4164
4166
  value
@@ -4351,14 +4353,14 @@ function FormComponent(props) {
4351
4353
  blocks={props.sendingMessage}
4352
4354
  context={props.builderContext}
4353
4355
  /></Show12>
4354
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4356
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-fdf23968">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4355
4357
  <Show12 when={submissionState() === "success"}><Blocks_default
4356
4358
  path="successMessage"
4357
4359
  blocks={props.successMessage}
4358
4360
  context={props.builderContext}
4359
4361
  /></Show12>
4360
4362
  </form>
4361
- <style>{`.pre-7430044e {
4363
+ <style>{`.pre-fdf23968 {
4362
4364
  padding: 10px;
4363
4365
  color: red;
4364
4366
  text-align: center;
@@ -4994,7 +4996,7 @@ function getPreviewContent(_searchParams) {
4994
4996
  }
4995
4997
 
4996
4998
  // src/constants/sdk-version.ts
4997
- var SDK_VERSION = "4.1.3";
4999
+ var SDK_VERSION = "4.2.1";
4998
5000
 
4999
5001
  // src/helpers/sdk-headers.ts
5000
5002
  var getSdkHeaders = () => ({
@@ -5899,38 +5901,59 @@ function EnableEditor(props) {
5899
5901
  }
5900
5902
  function runHttpRequests() {
5901
5903
  const requests = props.builderContextSignal.content?.data?.httpRequests ?? {};
5902
- Object.entries(requests).forEach(([key, url]) => {
5903
- if (!url)
5904
- return;
5905
- if (httpReqsPending()[key])
5906
- return;
5907
- if (httpReqsData()[key] && !isEditing())
5908
- return;
5909
- httpReqsPending()[key] = true;
5910
- const evaluatedUrl = url.replace(
5911
- /{{([^}]+)}}/g,
5912
- (_match, group) => String(
5913
- evaluate({
5914
- code: group,
5915
- context: props.context || {},
5916
- localState: void 0,
5917
- rootState: props.builderContextSignal.rootState,
5918
- rootSetState: props.builderContextSignal.rootSetState
5919
- })
5920
- )
5921
- );
5922
- logFetch(evaluatedUrl);
5923
- fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
5924
- mergeNewRootState({
5925
- [key]: json
5904
+ Object.entries(requests).forEach(
5905
+ ([key, httpRequest]) => {
5906
+ if (!httpRequest)
5907
+ return;
5908
+ const isCoreRequest = typeof httpRequest === "object" && httpRequest["@type"] === "@builder.io/core:Request";
5909
+ if (httpReqsPending()[key])
5910
+ return;
5911
+ if (httpReqsData()[key] && !isEditing())
5912
+ return;
5913
+ const url = isCoreRequest ? httpRequest.request.url : httpRequest;
5914
+ httpReqsPending()[key] = true;
5915
+ const evaluatedUrl = url.replace(
5916
+ /{{([^}]+)}}/g,
5917
+ (_match, group) => String(
5918
+ evaluate({
5919
+ code: group,
5920
+ context: props.context || {},
5921
+ localState: void 0,
5922
+ rootState: props.builderContextSignal.rootState,
5923
+ rootSetState: props.builderContextSignal.rootSetState
5924
+ })
5925
+ )
5926
+ );
5927
+ const fetchRequestObj = isCoreRequest ? {
5928
+ url: evaluatedUrl,
5929
+ method: httpRequest.request.method,
5930
+ headers: httpRequest.request.headers,
5931
+ body: httpRequest.request.body
5932
+ } : {
5933
+ url: evaluatedUrl,
5934
+ method: "GET"
5935
+ };
5936
+ logFetch(JSON.stringify(fetchRequestObj));
5937
+ fetch(fetchRequestObj.url, {
5938
+ method: fetchRequestObj.method,
5939
+ headers: fetchRequestObj.headers,
5940
+ body: fetchRequestObj.body
5941
+ }).then((response) => response.json()).then((json) => {
5942
+ mergeNewRootState({
5943
+ [key]: json
5944
+ });
5945
+ httpReqsData()[key] = true;
5946
+ }).catch((err) => {
5947
+ console.error(
5948
+ "error fetching dynamic data",
5949
+ JSON.stringify(httpRequest),
5950
+ err
5951
+ );
5952
+ }).finally(() => {
5953
+ httpReqsPending()[key] = false;
5926
5954
  });
5927
- httpReqsData()[key] = true;
5928
- }).catch((err) => {
5929
- console.error("error fetching dynamic data", url, err);
5930
- }).finally(() => {
5931
- httpReqsPending()[key] = false;
5932
- });
5933
- });
5955
+ }
5956
+ );
5934
5957
  }
5935
5958
  function emitStateUpdate() {
5936
5959
  if (isEditing()) {
@@ -6502,6 +6525,18 @@ function register(type, info) {
6502
6525
  }
6503
6526
  }
6504
6527
  }
6528
+ function registerAction(action) {
6529
+ if (isBrowser()) {
6530
+ const actionClone = JSON.parse(JSON.stringify(action));
6531
+ if (action.action) {
6532
+ actionClone.action = action.action.toString();
6533
+ }
6534
+ window.parent?.postMessage({
6535
+ type: "builder.registerAction",
6536
+ data: actionClone
6537
+ }, "*");
6538
+ }
6539
+ }
6505
6540
 
6506
6541
  // src/functions/set-editor-settings.ts
6507
6542
  var settings = {};
@@ -6558,6 +6593,7 @@ export {
6558
6593
  isEditing,
6559
6594
  isPreviewing,
6560
6595
  register,
6596
+ registerAction,
6561
6597
  setClientUserAttributes,
6562
6598
  setEditorSettings,
6563
6599
  subscribeToEditor,
@@ -4501,9 +4501,9 @@ function logFetch(url) {
4501
4501
  }
4502
4502
 
4503
4503
  // src/blocks/form/form/form.tsx
4504
- var _tmpl$15 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-7430044e">`);
4504
+ var _tmpl$15 = /* @__PURE__ */ template(`<pre class="builder-form-error-text pre-fdf23968">`);
4505
4505
  var _tmpl$26 = /* @__PURE__ */ template(`<form>`);
4506
- var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-7430044e {
4506
+ var _tmpl$34 = /* @__PURE__ */ template(`<style>.pre-fdf23968 {
4507
4507
  padding: 10px;
4508
4508
  color: red;
4509
4509
  text-align: center;
@@ -4540,13 +4540,13 @@ function FormComponent(props) {
4540
4540
  const headers = props.customHeaders || {};
4541
4541
  let body;
4542
4542
  const formData = new FormData(el);
4543
- const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).map((el2) => {
4543
+ const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).filter((el2) => !!el2.name && (el2.type !== "radio" || el2.checked)).map((el2) => {
4544
4544
  let value;
4545
4545
  const key = el2.name;
4546
4546
  if (el2 instanceof HTMLInputElement) {
4547
4547
  if (el2.type === "radio") {
4548
4548
  if (el2.checked) {
4549
- value = el2.name;
4549
+ value = el2.value;
4550
4550
  return {
4551
4551
  key,
4552
4552
  value
@@ -5489,7 +5489,7 @@ function getPreviewContent(_searchParams) {
5489
5489
  }
5490
5490
 
5491
5491
  // src/constants/sdk-version.ts
5492
- var SDK_VERSION = "4.1.3";
5492
+ var SDK_VERSION = "4.2.1";
5493
5493
 
5494
5494
  // src/helpers/sdk-headers.ts
5495
5495
  var getSdkHeaders = () => ({
@@ -6390,13 +6390,15 @@ function EnableEditor(props) {
6390
6390
  }
6391
6391
  function runHttpRequests() {
6392
6392
  const requests = props.builderContextSignal.content?.data?.httpRequests ?? {};
6393
- Object.entries(requests).forEach(([key, url]) => {
6394
- if (!url)
6393
+ Object.entries(requests).forEach(([key, httpRequest]) => {
6394
+ if (!httpRequest)
6395
6395
  return;
6396
+ const isCoreRequest = typeof httpRequest === "object" && httpRequest["@type"] === "@builder.io/core:Request";
6396
6397
  if (httpReqsPending()[key])
6397
6398
  return;
6398
6399
  if (httpReqsData()[key] && !isEditing())
6399
6400
  return;
6401
+ const url = isCoreRequest ? httpRequest.request.url : httpRequest;
6400
6402
  httpReqsPending()[key] = true;
6401
6403
  const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
6402
6404
  code: group,
@@ -6405,8 +6407,21 @@ function EnableEditor(props) {
6405
6407
  rootState: props.builderContextSignal.rootState,
6406
6408
  rootSetState: props.builderContextSignal.rootSetState
6407
6409
  })));
6408
- logFetch(evaluatedUrl);
6409
- fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
6410
+ const fetchRequestObj = isCoreRequest ? {
6411
+ url: evaluatedUrl,
6412
+ method: httpRequest.request.method,
6413
+ headers: httpRequest.request.headers,
6414
+ body: httpRequest.request.body
6415
+ } : {
6416
+ url: evaluatedUrl,
6417
+ method: "GET"
6418
+ };
6419
+ logFetch(JSON.stringify(fetchRequestObj));
6420
+ fetch(fetchRequestObj.url, {
6421
+ method: fetchRequestObj.method,
6422
+ headers: fetchRequestObj.headers,
6423
+ body: fetchRequestObj.body
6424
+ }).then((response) => response.json()).then((json) => {
6410
6425
  mergeNewRootState({
6411
6426
  [key]: json
6412
6427
  });
@@ -7182,6 +7197,18 @@ function register(type, info) {
7182
7197
  }
7183
7198
  }
7184
7199
  }
7200
+ function registerAction(action) {
7201
+ if (isBrowser()) {
7202
+ const actionClone = JSON.parse(JSON.stringify(action));
7203
+ if (action.action) {
7204
+ actionClone.action = action.action.toString();
7205
+ }
7206
+ window.parent?.postMessage({
7207
+ type: "builder.registerAction",
7208
+ data: actionClone
7209
+ }, "*");
7210
+ }
7211
+ }
7185
7212
 
7186
7213
  // src/functions/set-editor-settings.ts
7187
7214
  var settings = {};
@@ -7218,4 +7245,4 @@ var fetchBuilderProps = async (_args) => {
7218
7245
  };
7219
7246
  };
7220
7247
 
7221
- export { blocks_default as Blocks, builder_context_default as BuilderContext, button_default as Button, columns_default as Columns, content_variants_default as Content, fragment_default as Fragment, image_default as Image, section_default as Section, symbol_default as Symbol, text_default as Text, video_default as Video, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, setClientUserAttributes, setEditorSettings, subscribeToEditor, track };
7248
+ export { blocks_default as Blocks, builder_context_default as BuilderContext, button_default as Button, columns_default as Columns, content_variants_default as Content, fragment_default as Fragment, image_default as Image, section_default as Section, symbol_default as Symbol, text_default as Text, video_default as Video, _processContentResult, createRegisterComponentMessage, fetchBuilderProps, fetchEntries, fetchOneEntry, getBuilderSearchParams, isEditing, isPreviewing, register, registerAction, setClientUserAttributes, setEditorSettings, subscribeToEditor, track };
@@ -4143,13 +4143,15 @@ function FormComponent(props) {
4143
4143
  const headers = props.customHeaders || {};
4144
4144
  let body;
4145
4145
  const formData = new FormData(el);
4146
- const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).map((el2) => {
4146
+ const formPairs = Array.from(el.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).filter(
4147
+ (el2) => !!el2.name && (el2.type !== "radio" || el2.checked)
4148
+ ).map((el2) => {
4147
4149
  let value;
4148
4150
  const key = el2.name;
4149
4151
  if (el2 instanceof HTMLInputElement) {
4150
4152
  if (el2.type === "radio") {
4151
4153
  if (el2.checked) {
4152
- value = el2.name;
4154
+ value = el2.value;
4153
4155
  return {
4154
4156
  key,
4155
4157
  value
@@ -4341,14 +4343,14 @@ function FormComponent(props) {
4341
4343
  blocks={props.sendingMessage}
4342
4344
  context={props.builderContext}
4343
4345
  /></Show12>
4344
- <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-7430044e">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4346
+ <Show12 when={submissionState() === "error" && responseData()}><pre class="builder-form-error-text pre-fdf23968">{JSON.stringify(responseData(), null, 2)}</pre></Show12>
4345
4347
  <Show12 when={submissionState() === "success"}><Blocks_default
4346
4348
  path="successMessage"
4347
4349
  blocks={props.successMessage}
4348
4350
  context={props.builderContext}
4349
4351
  /></Show12>
4350
4352
  </form>
4351
- <style>{`.pre-7430044e {
4353
+ <style>{`.pre-fdf23968 {
4352
4354
  padding: 10px;
4353
4355
  color: red;
4354
4356
  text-align: center;
@@ -4983,7 +4985,7 @@ function getPreviewContent(_searchParams) {
4983
4985
  }
4984
4986
 
4985
4987
  // src/constants/sdk-version.ts
4986
- var SDK_VERSION = "4.1.3";
4988
+ var SDK_VERSION = "4.2.1";
4987
4989
 
4988
4990
  // src/helpers/sdk-headers.ts
4989
4991
  var getSdkHeaders = () => ({
@@ -5883,37 +5885,54 @@ function EnableEditor(props) {
5883
5885
  }
5884
5886
  function runHttpRequests() {
5885
5887
  const requests = props.builderContextSignal.content?.data?.httpRequests ?? {};
5886
- Object.entries(requests).forEach(([key, url]) => {
5887
- if (!url)
5888
- return;
5889
- if (httpReqsPending()[key])
5890
- return;
5891
- if (httpReqsData()[key] && !isEditing())
5892
- return;
5893
- httpReqsPending()[key] = true;
5894
- const evaluatedUrl = url.replace(
5895
- /{{([^}]+)}}/g,
5896
- (_match, group) => String(
5897
- evaluate({
5898
- code: group,
5899
- context: props.context || {},
5900
- localState: void 0,
5901
- rootState: props.builderContextSignal.rootState,
5902
- rootSetState: props.builderContextSignal.rootSetState
5903
- })
5904
- )
5905
- );
5906
- logFetch(evaluatedUrl);
5907
- fetch(evaluatedUrl).then((response) => response.json()).then((json) => {
5908
- mergeNewRootState({
5909
- [key]: json
5888
+ Object.entries(requests).forEach(
5889
+ ([key, httpRequest]) => {
5890
+ if (!httpRequest)
5891
+ return;
5892
+ const isCoreRequest = typeof httpRequest === "object" && httpRequest["@type"] === "@builder.io/core:Request";
5893
+ if (httpReqsPending()[key])
5894
+ return;
5895
+ if (httpReqsData()[key] && !isEditing())
5896
+ return;
5897
+ const url = isCoreRequest ? httpRequest.request.url : httpRequest;
5898
+ httpReqsPending()[key] = true;
5899
+ const evaluatedUrl = url.replace(
5900
+ /{{([^}]+)}}/g,
5901
+ (_match, group) => String(
5902
+ evaluate({
5903
+ code: group,
5904
+ context: props.context || {},
5905
+ localState: void 0,
5906
+ rootState: props.builderContextSignal.rootState,
5907
+ rootSetState: props.builderContextSignal.rootSetState
5908
+ })
5909
+ )
5910
+ );
5911
+ const fetchRequestObj = isCoreRequest ? {
5912
+ url: evaluatedUrl,
5913
+ method: httpRequest.request.method,
5914
+ headers: httpRequest.request.headers,
5915
+ body: httpRequest.request.body
5916
+ } : {
5917
+ url: evaluatedUrl,
5918
+ method: "GET"
5919
+ };
5920
+ logFetch(JSON.stringify(fetchRequestObj));
5921
+ fetch(fetchRequestObj.url, {
5922
+ method: fetchRequestObj.method,
5923
+ headers: fetchRequestObj.headers,
5924
+ body: fetchRequestObj.body
5925
+ }).then((response) => response.json()).then((json) => {
5926
+ mergeNewRootState({
5927
+ [key]: json
5928
+ });
5929
+ httpReqsData()[key] = true;
5930
+ }).catch((err) => {
5931
+ }).finally(() => {
5932
+ httpReqsPending()[key] = false;
5910
5933
  });
5911
- httpReqsData()[key] = true;
5912
- }).catch((err) => {
5913
- }).finally(() => {
5914
- httpReqsPending()[key] = false;
5915
- });
5916
- });
5934
+ }
5935
+ );
5917
5936
  }
5918
5937
  function emitStateUpdate() {
5919
5938
  if (isEditing()) {
@@ -6484,6 +6503,18 @@ function register(type, info) {
6484
6503
  }
6485
6504
  }
6486
6505
  }
6506
+ function registerAction(action) {
6507
+ if (isBrowser()) {
6508
+ const actionClone = JSON.parse(JSON.stringify(action));
6509
+ if (action.action) {
6510
+ actionClone.action = action.action.toString();
6511
+ }
6512
+ window.parent?.postMessage({
6513
+ type: "builder.registerAction",
6514
+ data: actionClone
6515
+ }, "*");
6516
+ }
6517
+ }
6487
6518
 
6488
6519
  // src/functions/set-editor-settings.ts
6489
6520
  var settings = {};
@@ -6540,6 +6571,7 @@ export {
6540
6571
  isEditing,
6541
6572
  isPreviewing,
6542
6573
  register,
6574
+ registerAction,
6543
6575
  setClientUserAttributes,
6544
6576
  setEditorSettings,
6545
6577
  subscribeToEditor,