@builder.io/react 1.1.46 → 1.1.47-3

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 (35) hide show
  1. package/dist/builder-react-lite.cjs.js +2 -2
  2. package/dist/builder-react-lite.cjs.js.map +1 -1
  3. package/dist/builder-react-lite.esm.js +2 -2
  4. package/dist/builder-react-lite.esm.js.map +1 -1
  5. package/dist/builder-react.browser.js +2 -2
  6. package/dist/builder-react.browser.js.map +1 -1
  7. package/dist/builder-react.cjs.js +2 -2
  8. package/dist/builder-react.cjs.js.map +1 -1
  9. package/dist/builder-react.es5.js +2 -2
  10. package/dist/builder-react.es5.js.map +1 -1
  11. package/dist/builder-react.unpkg.js +2 -2
  12. package/dist/builder-react.unpkg.js.map +1 -1
  13. package/dist/lib/lib/on-change.js.map +1 -1
  14. package/dist/lib/package.json +2 -3
  15. package/dist/lib/src/blocks/Columns.js.map +1 -1
  16. package/dist/lib/src/blocks/CustomCode.js +4 -9
  17. package/dist/lib/src/blocks/CustomCode.js.map +1 -1
  18. package/dist/lib/src/blocks/Video.js +13 -50
  19. package/dist/lib/src/blocks/Video.js.map +1 -1
  20. package/dist/lib/src/components/builder-block.component.js +9 -5
  21. package/dist/lib/src/components/builder-block.component.js.map +1 -1
  22. package/dist/lib/src/functions/block-to-html-string.js +1 -5
  23. package/dist/lib/src/functions/block-to-html-string.js.map +1 -1
  24. package/dist/lib/test/functions/render-block.js +1 -5
  25. package/dist/lib/test/functions/render-block.js.map +1 -1
  26. package/lib/on-change.js +21 -21
  27. package/package.json +2 -3
  28. package/src/blocks/Columns.tsx +0 -1
  29. package/src/blocks/CustomCode.tsx +7 -6
  30. package/src/blocks/Video.tsx +13 -54
  31. package/src/components/builder-block.component.tsx +13 -7
  32. package/src/components/builder-component.component.tsx +3 -3
  33. package/src/functions/block-to-html-string.ts +1 -5
  34. package/src/functions/throttle.ts +2 -2
  35. package/test/functions/render-block.ts +1 -7
@@ -10,7 +10,7 @@ interface Props {
10
10
  }
11
11
 
12
12
  // TODO: settings context to pass this down. do in shopify-specific generated code
13
- const globalReplaceNodes = ({} as { [key: string]: Element[] }) || null;
13
+ const globalReplaceNodes = ({} as { [key: string]: Node[] }) || null;
14
14
 
15
15
  const isShopify = Builder.isBrowser && 'Shopify' in window;
16
16
 
@@ -40,7 +40,7 @@ if (Builder.isBrowser && globalReplaceNodes) {
40
40
  const id = parent && parent.getAttribute('builder-id');
41
41
  if (id) {
42
42
  globalReplaceNodes[id] = globalReplaceNodes[id] || [];
43
- globalReplaceNodes[id].push(el);
43
+ globalReplaceNodes[id].push(isShopify ? el : el.cloneNode(true));
44
44
  }
45
45
  });
46
46
  } catch (err) {
@@ -50,7 +50,7 @@ if (Builder.isBrowser && globalReplaceNodes) {
50
50
 
51
51
  class CustomCodeComponent extends React.Component<Props> {
52
52
  elementRef: Element | null = null;
53
- originalRef: Element | null = null;
53
+ originalRef: Node | Element | null = null;
54
54
 
55
55
  scriptsInserted = new Set();
56
56
  scriptsRun = new Set();
@@ -80,7 +80,7 @@ class CustomCodeComponent extends React.Component<Props> {
80
80
  if (existing.length === 1) {
81
81
  const node = existing[0];
82
82
  this.originalRef = node as HTMLElement;
83
- this.originalRef.remove();
83
+ (this.originalRef as Element).remove();
84
84
  }
85
85
  }
86
86
  }
@@ -192,11 +192,12 @@ export const CustomCode = withBuilder(CustomCodeComponent, {
192
192
  {
193
193
  name: 'scriptsClientOnly',
194
194
  type: 'boolean',
195
- defaultValue: false,
196
- // TODO: default true?
197
195
  helperText:
198
196
  'Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads',
199
197
  advanced: true,
198
+ ...(!isShopify && {
199
+ defaultValue: true,
200
+ }),
200
201
  },
201
202
  ],
202
203
  } as any);
@@ -40,17 +40,21 @@ class VideoComponent extends React.Component<{
40
40
  };
41
41
 
42
42
  updateVideo() {
43
- if (this.video) {
44
- const attributes: Array<'muted' | 'playsInline' | 'autoPlay'> = [
43
+ const video = this.video;
44
+ if (video) {
45
+ // There are some issues with boolean attributes and media elements
46
+ // see: https://github.com/facebook/react/issues/10389
47
+ const boolProps: Array<'muted' | 'playsInline' | 'autoPlay'> = [
45
48
  'muted',
46
49
  'playsInline',
47
50
  'autoPlay',
48
51
  ];
49
- attributes.forEach(attr => {
50
- if (this.props[attr]) {
51
- this.video?.setAttribute(attr.toLowerCase(), 'true');
52
+ boolProps.forEach(prop => {
53
+ const attr = prop.toLowerCase();
54
+ if (this.props[prop]) {
55
+ video.setAttribute(attr, attr);
52
56
  } else {
53
- this.video?.removeAttribute(attr.toLowerCase());
57
+ video.removeAttribute(attr);
54
58
  }
55
59
  });
56
60
  }
@@ -151,9 +155,10 @@ class VideoComponent extends React.Component<{
151
155
  <div css={{ display: 'flex', flexDirection: 'column', alignItems: 'stretch' }}>
152
156
  {children}
153
157
  </div>
154
- ) : (
158
+ ) : children ? (
155
159
  <div
156
160
  css={{
161
+ pointerEvents: 'none',
157
162
  display: 'flex',
158
163
  flexDirection: 'column',
159
164
  alignItems: 'stretch',
@@ -166,7 +171,7 @@ class VideoComponent extends React.Component<{
166
171
  >
167
172
  {children}
168
173
  </div>
169
- )}
174
+ ) : null}
170
175
  </div>
171
176
  );
172
177
  }
@@ -190,52 +195,6 @@ export const Video = Builder.registerComponent(withChildren(VideoComponent), {
190
195
  defaultValue:
191
196
  'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/assets%2FKQlEmWDxA0coC3PK6UvkrjwkIGI2%2F28cb070609f546cdbe5efa20e931aa4b?alt=media&token=912e9551-7a7c-4dfb-86b6-3da1537d1a7f',
192
197
  required: true,
193
- onChange: (options: Map<string, any>) => {
194
- const DEFAULT_ASPECT_RATIO = 0.7004048582995948;
195
- function loadImage(url: string, timeout = 60000): Promise<HTMLImageElement> {
196
- return new Promise((resolve, reject) => {
197
- const img = document.createElement('img');
198
- let loaded = false;
199
- img.onload = () => {
200
- loaded = true;
201
- resolve(img);
202
- };
203
-
204
- img.addEventListener('error', event => {
205
- console.warn('Image load failed', event.error);
206
- reject(event.error);
207
- });
208
-
209
- img.src = url;
210
- setTimeout(() => {
211
- if (!loaded) {
212
- reject(new Error('Image load timed out'));
213
- }
214
- }, timeout);
215
- });
216
- }
217
-
218
- function round(num: number) {
219
- return Math.round(num * 1000) / 1000;
220
- }
221
-
222
- // // TODO
223
- const value = options.get('image');
224
- const aspectRatio = options.get('aspectRatio');
225
- if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO)) {
226
- return loadImage(value).then(img => {
227
- const possiblyUpdatedAspectRatio = options.get('aspectRatio');
228
- if (
229
- options.get('image') === value &&
230
- (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)
231
- ) {
232
- if (img.width && img.height) {
233
- options.set('aspectRatio', round(img.height / img.width));
234
- }
235
- }
236
- });
237
- }
238
- },
239
198
  },
240
199
  {
241
200
  name: 'posterImage',
@@ -361,6 +361,18 @@ export class BuilderBlock extends React.Component<
361
361
  InnerComponent = componentInfo.class;
362
362
  } else if (componentInfo && componentInfo.tag) {
363
363
  InnerComponent = componentInfo.tag;
364
+ } else {
365
+ if (componentName.startsWith('Builder:')) {
366
+ console.warn(
367
+ `Missing @builder.io/widgets installation, please install and import @builder.io/widgets to use ${
368
+ componentName.split(':')[1]
369
+ } in your content, more info here: https://github.com/BuilderIO/builder/tree/main/packages/widgets`
370
+ );
371
+ } else {
372
+ console.warn(
373
+ `Missing registration for ${componentName}, have you included the registration in your bundle?`
374
+ );
375
+ }
364
376
  }
365
377
  }
366
378
  }
@@ -630,13 +642,7 @@ export class BuilderBlock extends React.Component<
630
642
 
631
643
  if (block.repeat && block.repeat.collection) {
632
644
  const collectionPath = block.repeat.collection;
633
- const collectionName = last(
634
- (collectionPath || '')
635
- .trim()
636
- .split('(')[0]
637
- .trim()
638
- .split('.')
639
- );
645
+ const collectionName = last((collectionPath || '').trim().split('(')[0].trim().split('.'));
640
646
  const itemName = block.repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
641
647
  const array = this.stringToFunction(collectionPath)(
642
648
  state.state,
@@ -73,11 +73,11 @@ const size = (thing: object) => Object.keys(thing).length;
73
73
 
74
74
  function debounce(func: Function, wait: number, immediate = false) {
75
75
  let timeout: any;
76
- return function(this: any) {
76
+ return function (this: any) {
77
77
  const context = this;
78
78
  const args = arguments;
79
79
  clearTimeout(timeout);
80
- timeout = setTimeout(function() {
80
+ timeout = setTimeout(function () {
81
81
  timeout = null;
82
82
  if (!immediate) func.apply(context, args);
83
83
  }, wait);
@@ -1091,7 +1091,7 @@ export class BuilderComponent extends React.Component<
1091
1091
  const useBuilderState = (initialState: any) => {
1092
1092
  const [, setTick] = React.useState(0);
1093
1093
  const [state] = React.useState(() =>
1094
- onChange(initialState, function() {
1094
+ onChange(initialState, function () {
1095
1095
  setTick(tick => tick + 1);
1096
1096
  })
1097
1097
  );
@@ -1,11 +1,7 @@
1
1
  import { BuilderElement } from '@builder.io/sdk';
2
2
 
3
3
  export const htmlEscape = (str: string) =>
4
- str
5
- .replace(/&/g, '&amp;')
6
- .replace(/</g, '&lt;')
7
- .replace(/>/g, '&gt;')
8
- .replace(/"/g, '&quot;');
4
+ str.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;');
9
5
 
10
6
  // TODO: handle self closing tags
11
7
  // TODO: how allow components (e.g. react components) in templates?
@@ -4,13 +4,13 @@ export function throttle(func: Function, wait: number, options: any = {}) {
4
4
  let result: any;
5
5
  let timeout = null as any;
6
6
  let previous = 0;
7
- const later = function() {
7
+ const later = function () {
8
8
  previous = options.leading === false ? 0 : Date.now();
9
9
  timeout = null;
10
10
  result = func.apply(context, args);
11
11
  if (!timeout) context = args = null;
12
12
  };
13
- return function(this: any) {
13
+ return function (this: any) {
14
14
  const now = Date.now();
15
15
  if (!previous && options.leading === false) previous = now;
16
16
  const remaining = wait - (now - previous);
@@ -2,13 +2,7 @@ import { BuilderElement } from '@builder.io/sdk';
2
2
 
3
3
  export const el = (options?: Partial<BuilderElement>, useId?: number): BuilderElement => ({
4
4
  '@type': '@builder.io/sdk:Element',
5
- id: `builder-${
6
- useId
7
- ? useId
8
- : Math.random()
9
- .toString()
10
- .split('.')[1]
11
- }`,
5
+ id: `builder-${useId ? useId : Math.random().toString().split('.')[1]}`,
12
6
  ...options,
13
7
  });
14
8