@builder.io/react 1.1.52-9 → 2.0.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.
Files changed (143) hide show
  1. package/=16.8 +15 -0
  2. package/README.md +153 -64
  3. package/dist/builder-react-lite.cjs.js +12 -12
  4. package/dist/builder-react-lite.cjs.js.map +1 -1
  5. package/dist/builder-react-lite.esm.js +12 -12
  6. package/dist/builder-react-lite.esm.js.map +1 -1
  7. package/dist/builder-react.browser.js +13 -13
  8. package/dist/builder-react.browser.js.map +1 -1
  9. package/dist/builder-react.cjs.js +12 -12
  10. package/dist/builder-react.cjs.js.map +1 -1
  11. package/dist/builder-react.es5.js +12 -12
  12. package/dist/builder-react.es5.js.map +1 -1
  13. package/dist/builder-react.unpkg.js +13 -13
  14. package/dist/builder-react.unpkg.js.map +1 -1
  15. package/dist/lib/package.json +11 -9
  16. package/dist/lib/rollup.config.js +15 -13
  17. package/dist/lib/rollup.config.js.map +1 -1
  18. package/dist/lib/src/blocks/Button.js +5 -2
  19. package/dist/lib/src/blocks/Button.js.map +1 -1
  20. package/dist/lib/src/blocks/Columns.js +16 -13
  21. package/dist/lib/src/blocks/Columns.js.map +1 -1
  22. package/dist/lib/src/blocks/CustomCode.js +11 -7
  23. package/dist/lib/src/blocks/CustomCode.js.map +1 -1
  24. package/dist/lib/src/blocks/Embed.js +7 -4
  25. package/dist/lib/src/blocks/Embed.js.map +1 -1
  26. package/dist/lib/src/blocks/Fragment.js +5 -2
  27. package/dist/lib/src/blocks/Fragment.js.map +1 -1
  28. package/dist/lib/src/blocks/Image.js +37 -24
  29. package/dist/lib/src/blocks/Image.js.map +1 -1
  30. package/dist/lib/src/blocks/Mutation.js +3 -2
  31. package/dist/lib/src/blocks/Mutation.js.map +1 -1
  32. package/dist/lib/src/blocks/Router.js +16 -11
  33. package/dist/lib/src/blocks/Router.js.map +1 -1
  34. package/dist/lib/src/blocks/Section.js +9 -6
  35. package/dist/lib/src/blocks/Section.js.map +1 -1
  36. package/dist/lib/src/blocks/Slot.js +4 -3
  37. package/dist/lib/src/blocks/Slot.js.map +1 -1
  38. package/dist/lib/src/blocks/StateProvider.js +5 -2
  39. package/dist/lib/src/blocks/StateProvider.js.map +1 -1
  40. package/dist/lib/src/blocks/Symbol.js +13 -10
  41. package/dist/lib/src/blocks/Symbol.js.map +1 -1
  42. package/dist/lib/src/blocks/Text.js +9 -6
  43. package/dist/lib/src/blocks/Text.js.map +1 -1
  44. package/dist/lib/src/blocks/Video.js +12 -9
  45. package/dist/lib/src/blocks/Video.js.map +1 -1
  46. package/dist/lib/src/blocks/forms/Button.js +9 -2
  47. package/dist/lib/src/blocks/forms/Button.js.map +1 -1
  48. package/dist/lib/src/blocks/forms/Form.js +20 -13
  49. package/dist/lib/src/blocks/forms/Form.js.map +1 -1
  50. package/dist/lib/src/blocks/forms/Input.js +5 -2
  51. package/dist/lib/src/blocks/forms/Input.js.map +1 -1
  52. package/dist/lib/src/blocks/forms/Label.js +10 -2
  53. package/dist/lib/src/blocks/forms/Label.js.map +1 -1
  54. package/dist/lib/src/blocks/forms/Select.js +5 -2
  55. package/dist/lib/src/blocks/forms/Select.js.map +1 -1
  56. package/dist/lib/src/blocks/forms/TextArea.js +5 -2
  57. package/dist/lib/src/blocks/forms/TextArea.js.map +1 -1
  58. package/dist/lib/src/blocks/raw/Img.js +5 -2
  59. package/dist/lib/src/blocks/raw/Img.js.map +1 -1
  60. package/dist/lib/src/blocks/raw/RawText.js +21 -3
  61. package/dist/lib/src/blocks/raw/RawText.js.map +1 -1
  62. package/dist/lib/src/builder-react-lite.js +15 -12
  63. package/dist/lib/src/builder-react-lite.js.map +1 -1
  64. package/dist/lib/src/builder-react.js +58 -44
  65. package/dist/lib/src/builder-react.js.map +1 -1
  66. package/dist/lib/src/components/Link.js +3 -1
  67. package/dist/lib/src/components/Link.js.map +1 -1
  68. package/dist/lib/src/components/builder-block.component.js +37 -34
  69. package/dist/lib/src/components/builder-block.component.js.map +1 -1
  70. package/dist/lib/src/components/builder-blocks.component.js +12 -9
  71. package/dist/lib/src/components/builder-blocks.component.js.map +1 -1
  72. package/dist/lib/src/components/builder-component.component.js +53 -44
  73. package/dist/lib/src/components/builder-component.component.js.map +1 -1
  74. package/dist/lib/src/components/builder-content.component.js +17 -13
  75. package/dist/lib/src/components/builder-content.component.js.map +1 -1
  76. package/dist/lib/src/components/insert-spacer.component.js +11 -4
  77. package/dist/lib/src/components/insert-spacer.component.js.map +1 -1
  78. package/dist/lib/src/components/no-wrap.js +3 -1
  79. package/dist/lib/src/components/no-wrap.js.map +1 -1
  80. package/dist/lib/src/components/variants-provider.component.js +33 -13
  81. package/dist/lib/src/components/variants-provider.component.js.map +1 -1
  82. package/dist/lib/src/constants/device-sizes.constant.js +1 -0
  83. package/dist/lib/src/constants/device-sizes.constant.js.map +1 -1
  84. package/dist/lib/src/decorators/builder-block.decorator.js +1 -0
  85. package/dist/lib/src/decorators/builder-block.decorator.js.map +1 -1
  86. package/dist/lib/src/functions/apply-patch-with-mutation.js +12 -8
  87. package/dist/lib/src/functions/apply-patch-with-mutation.js.map +1 -1
  88. package/dist/lib/src/functions/block-to-html-string.js +10 -7
  89. package/dist/lib/src/functions/block-to-html-string.js.map +1 -1
  90. package/dist/lib/src/functions/debonce-next-tick.js +1 -0
  91. package/dist/lib/src/functions/debonce-next-tick.js.map +1 -1
  92. package/dist/lib/src/functions/get.js +3 -1
  93. package/dist/lib/src/functions/get.js.map +1 -1
  94. package/dist/lib/src/functions/no-wrap.js +3 -1
  95. package/dist/lib/src/functions/no-wrap.js.map +1 -1
  96. package/dist/lib/src/functions/safe-dynamic-require.js +1 -0
  97. package/dist/lib/src/functions/safe-dynamic-require.js.map +1 -1
  98. package/dist/lib/src/functions/set.js +3 -1
  99. package/dist/lib/src/functions/set.js.map +1 -1
  100. package/dist/lib/src/functions/string-to-function.js +6 -4
  101. package/dist/lib/src/functions/string-to-function.js.map +1 -1
  102. package/dist/lib/src/functions/throttle.js +1 -0
  103. package/dist/lib/src/functions/throttle.js.map +1 -1
  104. package/dist/lib/src/functions/update-metadata.js +1 -0
  105. package/dist/lib/src/functions/update-metadata.js.map +1 -1
  106. package/dist/lib/src/functions/with-builder.js +2 -1
  107. package/dist/lib/src/functions/with-builder.js.map +1 -1
  108. package/dist/lib/src/functions/with-children.js +3 -1
  109. package/dist/lib/src/functions/with-children.js.map +1 -1
  110. package/dist/lib/src/hooks/isPreviewing.js +16 -0
  111. package/dist/lib/src/hooks/isPreviewing.js.map +1 -0
  112. package/dist/lib/src/scripts/init-editing.js.map +1 -1
  113. package/dist/lib/src/store/builder-async-requests.js +5 -2
  114. package/dist/lib/src/store/builder-async-requests.js.map +1 -1
  115. package/dist/lib/src/store/builder-meta.js +1 -0
  116. package/dist/lib/src/store/builder-meta.js.map +1 -1
  117. package/dist/lib/src/store/builder-store.js +1 -0
  118. package/dist/lib/src/store/builder-store.js.map +1 -1
  119. package/dist/lib/test/basic.test.js +47 -31
  120. package/dist/lib/test/basic.test.js.map +1 -1
  121. package/dist/lib/test/functions/render-block.js +6 -3
  122. package/dist/lib/test/functions/render-block.js.map +1 -1
  123. package/dist/lib/test/image.test.js +20 -4
  124. package/dist/lib/test/image.test.js.map +1 -1
  125. package/dist/types/src/builder-react-lite.d.ts +1 -0
  126. package/dist/types/src/builder-react.d.ts +1 -0
  127. package/dist/types/src/components/builder-block.component.d.ts +1 -1
  128. package/dist/types/src/components/builder-component.component.d.ts +16 -2
  129. package/dist/types/src/components/builder-content.component.d.ts +1 -1
  130. package/dist/types/src/components/no-wrap.d.ts +2 -1
  131. package/dist/types/src/functions/apply-patch-with-mutation.d.ts +1 -1
  132. package/dist/types/src/hooks/isPreviewing.d.ts +1 -0
  133. package/lite.js +1 -1
  134. package/package.json +11 -9
  135. package/rollup.config.ts +2 -0
  136. package/src/blocks/Router.tsx +1 -1
  137. package/src/builder-react-lite.ts +1 -0
  138. package/src/builder-react.ts +1 -0
  139. package/src/components/builder-component.component.tsx +24 -6
  140. package/src/components/builder-content.component.tsx +1 -1
  141. package/src/functions/string-to-function.ts +2 -2
  142. package/src/hooks/isPreviewing.ts +14 -0
  143. package/typedoc.js +8 -0
package/=16.8 ADDED
@@ -0,0 +1,15 @@
1
+
2
+ up to date, audited 1914 packages in 4s
3
+
4
+ 46 packages are looking for funding
5
+ run `npm fund` for details
6
+
7
+ 39 vulnerabilities (15 moderate, 21 high, 3 critical)
8
+
9
+ To address issues that do not require attention, run:
10
+ npm audit fix
11
+
12
+ To address all issues (including breaking changes), run:
13
+ npm audit fix --force
14
+
15
+ Run `npm audit` for details.
package/README.md CHANGED
@@ -1,38 +1,127 @@
1
1
  # Builder.io React SDK
2
2
 
3
- See our [main readme](/README.md) for info on getting started with the React SDK
3
+ ## Integration
4
+
5
+ See our full [getting started docs](https://www.builder.io/c/docs/developers), or jump right into integration. We generally recommend to start with page buliding as your initial integration:
6
+
7
+ <table>
8
+ <tr>
9
+ <td align="center">Integrate Page Building</td>
10
+ <td align="center">Integrate Section Building</td>
11
+ </tr>
12
+ <tr>
13
+ <td align="center">
14
+ <a href="https://www.builder.io/c/docs/integrating-builder-pages">
15
+ <img alt="CTA to integrate page buliding" src="https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F48bbb0ef5efb4d19a95a3f09f83c98f0" />
16
+ </a>
17
+ </td>
18
+ <td align="center">
19
+ <a href="https://www.builder.io/c/docs/integrate-section-building">
20
+ <img alt="CTA to integrate section buliding" src="https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F9db93cd1a29443fca7b67c1f9f458356" />
21
+ </a>
22
+ </td>
23
+ </tr>
24
+ </table>
4
25
 
5
- Also see our examples of using React with a [design system](/examples/react-design-system) or a [simple example](/examples/react) and how to use your [React components](https://github.com/BuilderIO/builder#using-your-components) in the visual editor!
26
+ ## React API
6
27
 
7
- Also see our docs for [Next.js](/examples/next-js) and [Gatsby](/examples/gatsby)
28
+ ### Simple example
8
29
 
9
- ## React API
30
+ The gist of using Builder, is fetching content (using queries on [custom fields](https://www.builder.io/c/docs/custom-fields) and [targeting](https://www.builder.io/c/docs/targeting-with-builder). Builder is structured like a traditional headless CMS where you can have different content types, called [models](https://www.builder.io/c/docs/guides/getting-started-with-models). By default, every Builder space has a `"page"` model.
10
31
 
11
- ### BuilderComponent
32
+ ```tsx
33
+ import { builder } from '@builder.io/react'
34
+
35
+ const API_KEY = '...' // Your Builder public API key
36
+ const MODEL_NAME = 'page';
37
+
38
+ const content = await builder
39
+ .get(MODEL_NAME, {
40
+ // Optional custom query
41
+ query: {
42
+ 'data.customField.$gt': 100,
43
+ },
44
+ // Optional custom targeting
45
+ userAttributes: {
46
+ urlPath: '/' // Most Builder content is targeted at least by the URL path
47
+ }
48
+ })
49
+ .promise()
50
+
51
+ // Later, pass the fetched content to the BuilderComponent
52
+ <BuilderComponent model={MODEL_NAME} content={content} />
53
+ ```
54
+
55
+ The builder content is simply json that you pass to a `<BuilderComponent />` to render. [Learn more about it here](https://www.builder.io/c/docs/how-builder-works-technical)
56
+
57
+ You can view all of the options for `builder.get` for fetching content [in our full reference here](../core/docs/interfaces/GetContentOptions.md)
12
58
 
13
- #### Simple example
59
+ For example, with Next.js, to render Builder as your homepage:
14
60
 
15
61
  ```tsx
16
- // Render a matching Builder page for the given URl
17
- <BuilderComponent model="page">
62
+ export const getStaticProps = async () => {
63
+ return {
64
+ props: {
65
+ builderContent: await builder
66
+ .get('page', {
67
+ userAttributes: {
68
+ urlPath: '/', // Fetch content targeted to the homepage ("/" url)
69
+ },
70
+ })
71
+ .promise(),
72
+ },
73
+ };
74
+ };
75
+
76
+ export default function MyHomePage({ builderContent }) {
77
+ return (
78
+ <>
79
+ <YourHeader />
80
+ <BuilderComponent model="page" content={builderContent} />
81
+ <YourFooter />
82
+ </>
83
+ );
84
+ }
18
85
  ```
19
86
 
20
- See our guides for [Gatsby](https://github.com/BuilderIO/builder/tree/master/examples/gatsby) and [Next.js](https://github.com/BuilderIO/builder/tree/master/examples/next-js) for guides on using with those frameworks
87
+ You can also allow dynamic page building (the ability to create new pages on new URLs dynamically). E.g. see [this guide](https://www.builder.io/c/docs/integrating-builder-pages) on how to do that
21
88
 
22
- #### Passing content manually
89
+ ### Registering Components
23
90
 
24
- This is useful for doing server side rendering, e.g. with [Gatsby](https://github.com/BuilderIO/builder/tree/master/examples/gatsby) and [Next.js](https://github.com/BuilderIO/builder/tree/master/examples/next-js) or via
25
- loading data from other sources than our default APIs, such as data in your own database saved via [webhooks](https://www.builder.io/c/docs/webhooks)
91
+ One of Builder's most powerful features is registering your own components for use in the drag and drop editor.
92
+ You can choose to have these compliment the built-in components, or to be the only components allowed to be used
93
+ (e.g. via [components-only mode](https://www.builder.io/c/docs/guides/components-only-mode))
26
94
 
27
- ```ts
28
- const content = await builder.get('page', { ...options });
29
- if (content) {
30
- document.title = content.data.title; // You can use custom fields from the response
31
- return <BuilderComponent model="page" content={content} >
95
+ ```tsx
96
+ import { Builder } from '@builder.io/sdk-react';
97
+
98
+ function MyHero(props) {
99
+ /* Your own hero component in your codebase */
32
100
  }
33
101
 
102
+ Builder.registerComponent(MyHero, {
103
+ name: 'Hero',
104
+ inputs: [
105
+ { name: 'title', type: 'string' }, // Gets passed as the `title` prop to the Hero
106
+ ],
107
+ });
108
+ ```
109
+
110
+ Learn more about [registering components in Builder](https://www.builder.io/c/docs/custom-react-components)
111
+
112
+ ### BuilderComponent
113
+
114
+ You can find the full [reference docs for the BuilderComponent props here](docs/interfaces/builder_component_component.BuilderComponentProps.md)
115
+
116
+ ```tsx
117
+ const MODEL_NAME = 'page';
118
+
119
+ // Render
120
+ <BuilderComponent model={MODEL_NAME} content={builderJson} />;
34
121
  ```
35
122
 
123
+ See our guides for [Gatsby](https://github.com/BuilderIO/builder/tree/master/examples/gatsby) and [Next.js](https://github.com/BuilderIO/builder/tree/master/examples/next-js) for guides on using with those frameworks
124
+
36
125
  #### Passing data and functions down
37
126
 
38
127
  You can also pass [data](https://www.builder.io/c/docs/guides/connecting-api-data) and [functions](https://www.builder.io/c/docs/react/custom-actions) down to the Builder component to use in the UIs (e.g. bind
@@ -45,8 +134,10 @@ All data passed down is available in Builder [actions and bindings](https://www.
45
134
  model="page"
46
135
  data={{
47
136
  products: productsList,
48
- foo: 'bar'
49
- }} >
137
+ foo: 'bar',
138
+ }}
139
+ content={builderJson}
140
+ />
50
141
  ```
51
142
 
52
143
  You can also pass down functions, complex data like custom objects and libraries you can use `context`. Similar to React context, context passes all the way down (e.g. through symbols, etc). This data is not observed for changes and mutations
@@ -57,48 +148,19 @@ You can also pass down functions, complex data like custom objects and libraries
57
148
  context={{
58
149
  addToCart: () => myService.addToCart(currentProduct),
59
150
  lodash: lodash,
60
- }} >
151
+ }}
152
+ content={builderJson}
153
+ />
61
154
  ```
62
155
 
63
156
  Context is available in [actions and bindings](https://www.builder.io/c/docs/guides/custom-code) as `context.*`, such as `context.lodash` or `context.myFunction()` in the example above
64
157
 
65
- #### Passing complex
158
+ #### Passing complex data
66
159
 
67
160
  Everything passed down is available on the `state` object in data and actions - e.g. `state.products[0].name`
68
161
 
69
162
  See more about using data passed down [here](https://www.builder.io/c/docs/react/custom-actions)
70
163
 
71
- #### Advanced querying
72
-
73
- When using custom [models](https://www.builder.io/c/docs/guides/getting-started-with-models) and [fields](https://www.builder.io/c/docs/custom-fields) you can do more advanced filtering of your content with [queries](<(https://www.builder.io/c/docs/custom-fields)>)
74
- and [targeting](https://www.builder.io/c/docs/guides/targeting-and-scheduling)
75
-
76
- ```tsx
77
- import { BuilderComponent, builder } from '@builder.io/react';
78
-
79
- builder.setUserAttributes({ isLoggedIn: false })
80
-
81
- export default () => <div>
82
- <BuilderComponent
83
- model="section"
84
- options={{ query: { 'data.something.$in': ['value a', 'value b'] } }} />
85
- <!-- some other content -->
86
- </div>
87
- ```
88
-
89
- #### contentLoaded
90
-
91
- The contentLoaded callback can be useful for when you add [custom fields](https://www.builder.io/c/docs/custom-fields)
92
-
93
- ```tsx
94
- <BuilderComponent
95
- model="page"
96
- contentLoaded={data => {
97
- document.title = data.title; // E.g. if your custom field is called `title`
98
- }}
99
- />
100
- ```
101
-
102
164
  ### Builder
103
165
 
104
166
  The global `Builder` singleton has a number of uses. Most important is registering custom components.
@@ -131,7 +193,9 @@ Builder.registerComponent(CodeBlockComponent, {
131
193
  });
132
194
  ```
133
195
 
134
- See our full guide on [registering custom components here](https://www.builder.io/c/docs/custom-react-components)
196
+ See our full guide on [registering custom components here](https://www.builder.io/c/docs/custom-react-components).
197
+
198
+ See the [full reference docs for registerComponent options here](../core/docs/interfaces/Component.md).
135
199
 
136
200
  ### BuilderContent
137
201
 
@@ -140,14 +204,15 @@ See our full guide on [registering custom components here](https://www.builder.i
140
204
  Although you can already fetch data models from our Content API directly and use it as you would any other API resource, with a BuilderContent component you are able to use live Editing / Previewing / [A/B testing](https://forum.builder.io/t/a-b-testing-data-models/158) of your Data Models within the Builder Visual Editor.
141
205
 
142
206
  ##### Example, setting up an editable theme:
207
+
143
208
  ```tsx
144
209
  <BuilderContent model="site-settings"> { (data, loading) => {
145
210
  If (loading) {
146
211
  return <Spinner />
147
212
  }
148
213
  return <>
149
- /*pass values down to an example ThemeProvider, used as a wrapper in your application*/
150
- <ThemeProvider theme={data.theme} >
214
+ /*pass values down to an example ThemeProvider, used as a wrapper in your application*/
215
+ <ThemeProvider theme={data.theme} >
151
216
  {props.children}
152
217
  </ThemeProvider>
153
218
  </>
@@ -155,20 +220,43 @@ Although you can already fetch data models from our Content API directly and use
155
220
  </BuilderContent>
156
221
  ```
157
222
 
223
+ Or an example fetching server side and passing the content using the `content` prop, e.g. in Next.js
224
+
225
+ ```tsx
226
+ export const getStaticProps = async () => {
227
+ return {
228
+ props: {
229
+ builderDataContent: await builder.get('site-settings', /* other options like queries and targeting */).promise()
230
+ }
231
+ }
232
+ }
233
+
234
+ export default function MyPage({ builderDataContent }) {
235
+ return <BuilderContent content={builderDataContent}>{data =>
236
+ <ThemeProvider theme={data.theme}>
237
+ {/* ... more content ... */}
238
+ </ThemeProvider>
239
+ </BuilderContent>
240
+ }
241
+ ```
158
242
 
159
243
  #### Usage with Page/Section Custom Fields
160
244
 
161
- Page and section models in builder can be extended with [custom fields](https://www.builder.io/c/docs/custom-fields). To enable live editing / previewing on components that uses those custom fields, you can use BuilderContent to pass input data from the model to your components that are outside the rendered content
245
+ Page and section models in builder can be extended with [custom fields](https://www.builder.io/c/docs/custom-fields). To enable live editing / previewing on components that uses those custom fields, you can use BuilderContent to pass input data from the model to your components that are outside the rendered content
246
+
247
+ ##### Example, passing Custom Field input:
162
248
 
163
- ##### Example, passing Custom Field input:
164
249
  ```tsx
165
- <BuilderContent model="landing-page">{ (data) => {
166
- /*use your data here within your custom component*/
167
- return <>
168
- <FeaturedImage image={data.featuredImage} />
169
- <BuilderComponent content={content} model="landing-page" />
170
- </>
171
- }}
250
+ <BuilderContent model="landing-page">
251
+ {data => {
252
+ /*use your data here within your custom component*/
253
+ return (
254
+ <>
255
+ <FeaturedImage image={data.featuredImage} />
256
+ <BuilderComponent content={content} model="landing-page" />
257
+ </>
258
+ );
259
+ }}
172
260
  </BuilderContent>
173
261
  ```
174
262
 
@@ -186,6 +274,7 @@ if (content) {
186
274
  ```
187
275
 
188
276
  #### Advanced querying
277
+
189
278
  When using custom [models](https://www.builder.io/c/docs/guides/getting-started-with-models) and [fields](https://www.builder.io/c/docs/custom-fields) you can do more advanced filtering of your content with [queries](<(https://www.builder.io/c/docs/custom-fields)>)
190
279
  and [targeting](https://www.builder.io/c/docs/guides/targeting-and-scheduling)
191
280