@builder.io/sdk-react-native 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.
Files changed (78) hide show
  1. package/lib/browser/commonjs/blocks/form/form/form.js +2 -2
  2. package/lib/browser/commonjs/blocks/form/form/form.js.map +1 -1
  3. package/lib/browser/commonjs/components/content/components/enable-editor.js +20 -5
  4. package/lib/browser/commonjs/components/content/components/enable-editor.js.map +1 -1
  5. package/lib/browser/commonjs/constants/sdk-version.js +1 -1
  6. package/lib/browser/commonjs/functions/register.js +14 -0
  7. package/lib/browser/commonjs/functions/register.js.map +1 -1
  8. package/lib/browser/commonjs/server-index.js +7 -0
  9. package/lib/browser/commonjs/server-index.js.map +1 -1
  10. package/lib/browser/module/blocks/form/form/form.js +2 -2
  11. package/lib/browser/module/blocks/form/form/form.js.map +1 -1
  12. package/lib/browser/module/components/content/components/enable-editor.js +20 -5
  13. package/lib/browser/module/components/content/components/enable-editor.js.map +1 -1
  14. package/lib/browser/module/constants/sdk-version.js +1 -1
  15. package/lib/browser/module/functions/register.js +13 -0
  16. package/lib/browser/module/functions/register.js.map +1 -1
  17. package/lib/browser/module/server-index.js +1 -1
  18. package/lib/browser/module/server-index.js.map +1 -1
  19. package/lib/browser/typescript/components/content/components/enable-editor.d.ts.map +1 -1
  20. package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
  21. package/lib/browser/typescript/functions/register.d.ts +18 -0
  22. package/lib/browser/typescript/functions/register.d.ts.map +1 -1
  23. package/lib/browser/typescript/server-index.d.ts +1 -1
  24. package/lib/browser/typescript/server-index.d.ts.map +1 -1
  25. package/lib/edge/commonjs/blocks/form/form/form.js +2 -2
  26. package/lib/edge/commonjs/blocks/form/form/form.js.map +1 -1
  27. package/lib/edge/commonjs/components/content/components/enable-editor.js +20 -5
  28. package/lib/edge/commonjs/components/content/components/enable-editor.js.map +1 -1
  29. package/lib/edge/commonjs/constants/sdk-version.js +1 -1
  30. package/lib/edge/commonjs/functions/register.js +14 -0
  31. package/lib/edge/commonjs/functions/register.js.map +1 -1
  32. package/lib/edge/commonjs/server-index.js +7 -0
  33. package/lib/edge/commonjs/server-index.js.map +1 -1
  34. package/lib/edge/module/blocks/form/form/form.js +2 -2
  35. package/lib/edge/module/blocks/form/form/form.js.map +1 -1
  36. package/lib/edge/module/components/content/components/enable-editor.js +20 -5
  37. package/lib/edge/module/components/content/components/enable-editor.js.map +1 -1
  38. package/lib/edge/module/constants/sdk-version.js +1 -1
  39. package/lib/edge/module/functions/register.js +13 -0
  40. package/lib/edge/module/functions/register.js.map +1 -1
  41. package/lib/edge/module/server-index.js +1 -1
  42. package/lib/edge/module/server-index.js.map +1 -1
  43. package/lib/edge/typescript/components/content/components/enable-editor.d.ts.map +1 -1
  44. package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
  45. package/lib/edge/typescript/functions/register.d.ts +18 -0
  46. package/lib/edge/typescript/functions/register.d.ts.map +1 -1
  47. package/lib/edge/typescript/server-index.d.ts +1 -1
  48. package/lib/edge/typescript/server-index.d.ts.map +1 -1
  49. package/lib/node/commonjs/blocks/form/form/form.js +2 -2
  50. package/lib/node/commonjs/blocks/form/form/form.js.map +1 -1
  51. package/lib/node/commonjs/components/content/components/enable-editor.js +20 -5
  52. package/lib/node/commonjs/components/content/components/enable-editor.js.map +1 -1
  53. package/lib/node/commonjs/constants/sdk-version.js +1 -1
  54. package/lib/node/commonjs/functions/register.js +14 -0
  55. package/lib/node/commonjs/functions/register.js.map +1 -1
  56. package/lib/node/commonjs/server-index.js +7 -0
  57. package/lib/node/commonjs/server-index.js.map +1 -1
  58. package/lib/node/module/blocks/form/form/form.js +2 -2
  59. package/lib/node/module/blocks/form/form/form.js.map +1 -1
  60. package/lib/node/module/components/content/components/enable-editor.js +20 -5
  61. package/lib/node/module/components/content/components/enable-editor.js.map +1 -1
  62. package/lib/node/module/constants/sdk-version.js +1 -1
  63. package/lib/node/module/functions/register.js +13 -0
  64. package/lib/node/module/functions/register.js.map +1 -1
  65. package/lib/node/module/server-index.js +1 -1
  66. package/lib/node/module/server-index.js.map +1 -1
  67. package/lib/node/typescript/components/content/components/enable-editor.d.ts.map +1 -1
  68. package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
  69. package/lib/node/typescript/functions/register.d.ts +18 -0
  70. package/lib/node/typescript/functions/register.d.ts.map +1 -1
  71. package/lib/node/typescript/server-index.d.ts +1 -1
  72. package/lib/node/typescript/server-index.d.ts.map +1 -1
  73. package/package.json +1 -1
  74. package/src/blocks/form/form/form.tsx +7 -1
  75. package/src/components/content/components/enable-editor.tsx +83 -33
  76. package/src/constants/sdk-version.ts +1 -1
  77. package/src/functions/register.ts +29 -0
  78. package/src/server-index.ts +1 -1
@@ -14,7 +14,7 @@ export * from "./index-helpers/top-of-file";
14
14
  export { isEditing } from "./functions/is-editing";
15
15
  export { isPreviewing } from "./functions/is-previewing";
16
16
  export { createRegisterComponentMessage } from "./functions/register-component";
17
- export { register } from "./functions/register";
17
+ export { register, registerAction } from "./functions/register";
18
18
  export { setEditorSettings } from "./functions/set-editor-settings";
19
19
  export { getBuilderSearchParams } from "./functions/get-builder-search-params/index";
20
20
  export { track } from "./functions/track/index";
@@ -1 +1 @@
1
- {"version":3,"names":["isEditing","isPreviewing","createRegisterComponentMessage","register","setEditorSettings","getBuilderSearchParams","track","subscribeToEditor","fetchBuilderProps","_processContentResult","fetchEntries","fetchOneEntry"],"sourceRoot":"../../../src","sources":["server-index.ts"],"mappings":"AAAA;;AAEA;AACA;AACA;;AAYA;AACA;AACA;;AAMA;AACA;AACA;AACA,SAASA,SAAS;AAClB,SAASC,YAAY;AACrB,SAASC,8BAA8B;AACvC,SAASC,QAAQ;AAEjB,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,KAAK;AACd,SAASC,iBAAiB;;AAE1B;AACA;AACA;AACA,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB,EAAEC,YAAY,EAAEC,aAAa"}
1
+ {"version":3,"names":["isEditing","isPreviewing","createRegisterComponentMessage","register","registerAction","setEditorSettings","getBuilderSearchParams","track","subscribeToEditor","fetchBuilderProps","_processContentResult","fetchEntries","fetchOneEntry"],"sourceRoot":"../../../src","sources":["server-index.ts"],"mappings":"AAAA;;AAEA;AACA;AACA;;AAYA;AACA;AACA;;AAMA;AACA;AACA;AACA,SAASA,SAAS;AAClB,SAASC,YAAY;AACrB,SAASC,8BAA8B;AACvC,SAASC,QAAQ,EAAEC,cAAc;AAEjC,SAASC,iBAAiB;AAE1B,SAASC,sBAAsB;AAC/B,SAASC,KAAK;AACd,SAASC,iBAAiB;;AAE1B;AACA;AACA;AACA,SAASC,iBAAiB;AAC1B,SAASC,qBAAqB,EAAEC,YAAY,EAAEC,aAAa"}
@@ -1 +1 @@
1
- {"version":3,"file":"enable-editor.d.ts","sourceRoot":"","sources":["../../../../../../src/components/content/components/enable-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAgB/B,KAAK,kBAAkB,GAAG,IAAI,CAC5B,YAAY,EACV,kBAAkB,GAClB,YAAY,GACZ,aAAa,GACb,eAAe,GACf,oBAAoB,GACpB,eAAe,CAClB,GAAG;IACF,oBAAoB,EAAE,uBAAuB,CAAC;IAC9C,uBAAuB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC/C,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,CAAC;AAEF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAqBtE,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAI1B,iBAAS,YAAY,CAAC,KAAK,EAAE,kBAAkB,qBA+a9C;AAED,eAAe,YAAY,CAAC"}
1
+ {"version":3,"file":"enable-editor.d.ts","sourceRoot":"","sources":["../../../../../../src/components/content/components/enable-editor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAgB/B,KAAK,kBAAkB,GAAG,IAAI,CAC5B,YAAY,EACV,kBAAkB,GAClB,YAAY,GACZ,aAAa,GACb,eAAe,GACf,oBAAoB,GACpB,eAAe,CAClB,GAAG;IACF,oBAAoB,EAAE,uBAAuB,CAAC;IAC9C,uBAAuB,CAAC,EAAE,CAAC,MAAM,EAAE,GAAG,KAAK,GAAG,CAAC;IAC/C,QAAQ,CAAC,EAAE,GAAG,CAAC;CAChB,CAAC;AAuBF,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,wBAAwB,CAAC;AAqBtE,OAAO,KAAK,EAEV,YAAY,EACb,MAAM,kBAAkB,CAAC;AAI1B,iBAAS,YAAY,CAAC,KAAK,EAAE,kBAAkB,qBA4c9C;AAED,eAAe,YAAY,CAAC"}
@@ -1,2 +1,2 @@
1
- export declare const SDK_VERSION = "4.1.3";
1
+ export declare const SDK_VERSION = "4.2.1";
2
2
  //# sourceMappingURL=sdk-version.d.ts.map
@@ -1,5 +1,22 @@
1
1
  import type { BuilderBlock } from '../types/builder-block';
2
2
  import type { DeepPartial } from '../types/deep-partial';
3
+ import type { Input } from '../types/input';
4
+ export interface Action {
5
+ name: string;
6
+ inputs?: readonly Input[];
7
+ returnType?: Input;
8
+ action: (options: Record<string, any>) => string;
9
+ /**
10
+ * Is an action for expression (e.g. calculating a binding like a formula
11
+ * to fill a value based on locale) or a function (e.g. something to trigger
12
+ * on an event like add to cart) or either (e.g. a custom code block)
13
+ */
14
+ kind: 'expression' | 'function' | 'any';
15
+ /**
16
+ * Globally unique ID for an action, e.g. "@builder.io:setState"
17
+ */
18
+ id: string;
19
+ }
3
20
  export interface InsertMenuItem {
4
21
  name: string;
5
22
  icon?: string;
@@ -14,4 +31,5 @@ export interface InsertMenuConfig {
14
31
  }
15
32
  export declare function register(type: 'insertMenu', info: InsertMenuConfig): void;
16
33
  export declare function register(type: string, info: any): void;
34
+ export declare function registerAction(action: Action): void;
17
35
  //# sourceMappingURL=register.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/functions/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAGzD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;CACjC;AACD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAID,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC"}
1
+ {"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../../../../src/functions/register.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,wBAAwB,CAAC;AAC3D,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,gBAAgB,CAAC;AAG5C,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,CAAC,EAAE,SAAS,KAAK,EAAE,CAAC;IAC1B,UAAU,CAAC,EAAE,KAAK,CAAC;IACnB,MAAM,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,KAAK,MAAM,CAAC;IACjD;;;;OAIG;IACH,IAAI,EAAE,YAAY,GAAG,UAAU,GAAG,KAAK,CAAC;IACxC;;OAEG;IACH,EAAE,EAAE,MAAM,CAAC;CACZ;AACD,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,WAAW,CAAC,YAAY,CAAC,CAAC;CACjC;AACD,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,cAAc,EAAE,CAAC;CACzB;AAID,wBAAgB,QAAQ,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,gBAAgB,GAAG,IAAI,CAAC;AAC3E,wBAAgB,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,IAAI,CAAC;AA4BxD,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,QAW5C"}
@@ -25,7 +25,7 @@ export type { ComponentInfo } from './types/components';
25
25
  export { isEditing } from './functions/is-editing';
26
26
  export { isPreviewing } from './functions/is-previewing';
27
27
  export { createRegisterComponentMessage } from './functions/register-component';
28
- export { register } from './functions/register';
28
+ export { register, registerAction } from './functions/register';
29
29
  export type { InsertMenuConfig, InsertMenuItem } from './functions/register';
30
30
  export { setEditorSettings } from './functions/set-editor-settings';
31
31
  export type { Settings } from './functions/set-editor-settings';
@@ -1 +1 @@
1
- {"version":3,"file":"server-index.d.ts","sourceRoot":"","sources":["../../../src/server-index.ts"],"names":[],"mappings":"AAAA,cAAc,6BAA6B,CAAC;AAE5C;;GAEG;AACH,YAAY,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAChE,YAAY,EAAE,WAAW,EAAE,MAAM,gCAAgC,CAAC;AAClE,YAAY,EAAE,aAAa,EAAE,MAAM,kC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,EAAE,MAAM,sBAAsB,CAAC;AAChE,YAAY,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,YAAY,EAAE,QAAQ,EAAE,MAAM,iCAAiC,CAAC;AAChE,OAAO,EAAE,sBAAsB,EAAE,MAAM,6CAA6C,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,MAAM,yBAAyB,CAAC;AAChD,OAAO,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAC;AAElE;;GAEG;AACH,OAAO,EAAE,iBAAiB,EAAE,MAAM,iCAAiC,CAAC;AACpE,OAAO,EAAE,qBAAqB,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AACnG,YAAY,EAAE,iBAAiB,EAAE,MAAM,+BAA+B,CAAA"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-native",
3
3
  "description": "Builder.io SDK for React Native",
4
- "version": "4.1.3",
4
+ "version": "4.2.1",
5
5
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/react-native",
6
6
  "repository": {
7
7
  "type": "git",
@@ -110,13 +110,19 @@ function FormComponent(props: FormProps) {
110
110
  value: File | boolean | number | string | FileList;
111
111
  }[] = Array.from(el.querySelectorAll("input,select,textarea"))
112
112
  .filter((el) => !!(el as HTMLInputElement).name)
113
+ .filter(
114
+ (el) =>
115
+ !!(el as HTMLInputElement).name &&
116
+ ((el as HTMLInputElement).type !== "radio" ||
117
+ (el as HTMLInputElement).checked)
118
+ )
113
119
  .map((el) => {
114
120
  let value: any;
115
121
  const key = (el as HTMLImageElement).name;
116
122
  if (el instanceof HTMLInputElement) {
117
123
  if (el.type === "radio") {
118
124
  if (el.checked) {
119
- value = el.name;
125
+ value = el.value;
120
126
  return {
121
127
  key,
122
128
  value,
@@ -27,6 +27,27 @@ type BuilderEditorProps = Omit<
27
27
  setBuilderContextSignal?: (signal: any) => any;
28
28
  children?: any;
29
29
  };
30
+ interface BuilderRequest {
31
+ "@type": "@builder.io/core:Request";
32
+ request: {
33
+ url: string;
34
+ query?: {
35
+ [key: string]: string;
36
+ };
37
+ headers?: {
38
+ [key: string]: string;
39
+ };
40
+ method: "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
41
+ body?: any;
42
+ };
43
+ options?: {
44
+ [key: string]: any;
45
+ };
46
+ bindings?: {
47
+ [key: string]: string;
48
+ };
49
+ }
50
+
30
51
  import builderContext from "../../../context/builder.context";
31
52
  import type { BuilderContextInterface } from "../../../context/types";
32
53
  import { evaluate } from "../../../functions/evaluate/index";
@@ -172,44 +193,73 @@ function EnableEditor(props: BuilderEditorProps) {
172
193
 
173
194
  function runHttpRequests() {
174
195
  const requests: {
175
- [key: string]: string;
196
+ [key: string]: string | any;
176
197
  } = props.builderContextSignal.content?.data?.httpRequests ?? {};
177
- Object.entries(requests).forEach(([key, url]) => {
178
- if (!url) return;
198
+ Object.entries(requests).forEach(
199
+ ([key, httpRequest]: [string, BuilderRequest | string]) => {
200
+ if (!httpRequest) return;
201
+ const isCoreRequest =
202
+ typeof httpRequest === "object" &&
203
+ httpRequest["@type"] === "@builder.io/core:Request";
179
204
 
180
- // request already in progress
181
- if (httpReqsPending[key]) return;
205
+ // request already in progress
206
+ if (httpReqsPending[key]) return;
182
207
 
183
- // request already completed, and not in edit mode
184
- if (httpReqsData[key] && !isEditing()) return;
185
- httpReqsPending[key] = true;
186
- const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) =>
187
- String(
188
- evaluate({
189
- code: group,
190
- context: props.context || {},
191
- localState: undefined,
192
- rootState: props.builderContextSignal.rootState,
193
- rootSetState: props.builderContextSignal.rootSetState,
208
+ // request already completed, and not in edit mode
209
+ if (httpReqsData[key] && !isEditing()) return;
210
+ const url = isCoreRequest
211
+ ? httpRequest.request.url
212
+ : (httpRequest as string);
213
+ httpReqsPending[key] = true;
214
+ const evaluatedUrl = url.replace(
215
+ /{{([^}]+)}}/g,
216
+ (_match: string, group: string) =>
217
+ String(
218
+ evaluate({
219
+ code: group,
220
+ context: props.context || {},
221
+ localState: undefined,
222
+ rootState: props.builderContextSignal.rootState,
223
+ rootSetState: props.builderContextSignal.rootSetState,
224
+ })
225
+ )
226
+ );
227
+ const fetchRequestObj = isCoreRequest
228
+ ? {
229
+ url: evaluatedUrl,
230
+ method: httpRequest.request.method,
231
+ headers: httpRequest.request.headers,
232
+ body: httpRequest.request.body,
233
+ }
234
+ : {
235
+ url: evaluatedUrl,
236
+ method: "GET",
237
+ };
238
+ logFetch(JSON.stringify(fetchRequestObj));
239
+ fetch(fetchRequestObj.url, {
240
+ method: fetchRequestObj.method,
241
+ headers: fetchRequestObj.headers,
242
+ body: fetchRequestObj.body,
243
+ })
244
+ .then((response) => response.json())
245
+ .then((json) => {
246
+ mergeNewRootState({
247
+ [key]: json,
248
+ });
249
+ httpReqsData[key] = true;
194
250
  })
195
- )
196
- );
197
- logFetch(evaluatedUrl);
198
- fetch(evaluatedUrl)
199
- .then((response) => response.json())
200
- .then((json) => {
201
- mergeNewRootState({
202
- [key]: json,
251
+ .catch((err) => {
252
+ console.error(
253
+ "error fetching dynamic data",
254
+ JSON.stringify(httpRequest),
255
+ err
256
+ );
257
+ })
258
+ .finally(() => {
259
+ httpReqsPending[key] = false;
203
260
  });
204
- httpReqsData[key] = true;
205
- })
206
- .catch((err) => {
207
- console.error("error fetching dynamic data", url, err);
208
- })
209
- .finally(() => {
210
- httpReqsPending[key] = false;
211
- });
212
- });
261
+ }
262
+ );
213
263
  }
214
264
 
215
265
  function emitStateUpdate() {
@@ -1 +1 @@
1
- export const SDK_VERSION = "4.1.3"
1
+ export const SDK_VERSION = "4.2.1"
@@ -1,7 +1,24 @@
1
1
  import type { BuilderBlock } from '../types/builder-block';
2
2
  import type { DeepPartial } from '../types/deep-partial';
3
+ import type { Input } from '../types/input';
3
4
  import { isBrowser } from './is-browser';
4
5
  import { serializeIncludingFunctions } from './register-component';
6
+ export interface Action {
7
+ name: string;
8
+ inputs?: readonly Input[];
9
+ returnType?: Input;
10
+ action: (options: Record<string, any>) => string;
11
+ /**
12
+ * Is an action for expression (e.g. calculating a binding like a formula
13
+ * to fill a value based on locale) or a function (e.g. something to trigger
14
+ * on an event like add to cart) or either (e.g. a custom code block)
15
+ */
16
+ kind: 'expression' | 'function' | 'any';
17
+ /**
18
+ * Globally unique ID for an action, e.g. "@builder.io:setState"
19
+ */
20
+ id: string;
21
+ }
5
22
  export interface InsertMenuItem {
6
23
  name: string;
7
24
  icon?: string;
@@ -45,4 +62,16 @@ export function register(type: string, info: any) {
45
62
  console.debug('Could not postmessage', err);
46
63
  }
47
64
  }
65
+ }
66
+ export function registerAction(action: Action) {
67
+ if (isBrowser()) {
68
+ const actionClone = JSON.parse(JSON.stringify(action));
69
+ if (action.action) {
70
+ actionClone.action = action.action.toString();
71
+ }
72
+ window.parent?.postMessage({
73
+ type: 'builder.registerAction',
74
+ data: actionClone
75
+ }, '*');
76
+ }
48
77
  }
@@ -28,7 +28,7 @@ export type { ComponentInfo } from './types/components';
28
28
  export { isEditing } from './functions/is-editing';
29
29
  export { isPreviewing } from './functions/is-previewing';
30
30
  export { createRegisterComponentMessage } from './functions/register-component';
31
- export { register } from './functions/register';
31
+ export { register, registerAction } from './functions/register';
32
32
  export type { InsertMenuConfig, InsertMenuItem } from './functions/register';
33
33
  export { setEditorSettings } from './functions/set-editor-settings';
34
34
  export type { Settings } from './functions/set-editor-settings';