@builder.io/sdk-react 0.0.1 → 0.0.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 (141) hide show
  1. package/package.json +5 -1
  2. package/packages/_rsc/src/blocks/BaseText.js +27 -0
  3. package/packages/_rsc/src/blocks/button/button.js +35 -0
  4. package/packages/_rsc/src/blocks/button/component-info.js +41 -0
  5. package/packages/_rsc/src/blocks/columns/columns.js +96 -0
  6. package/packages/_rsc/src/blocks/columns/component-info.js +242 -0
  7. package/packages/_rsc/src/blocks/custom-code/component-info.js +31 -0
  8. package/packages/_rsc/src/blocks/custom-code/custom-code.js +63 -0
  9. package/packages/_rsc/src/blocks/embed/component-info.js +44 -0
  10. package/packages/_rsc/src/blocks/embed/embed.js +55 -0
  11. package/packages/_rsc/src/blocks/embed/helpers.js +9 -0
  12. package/packages/_rsc/src/blocks/form/component-info.js +262 -0
  13. package/packages/_rsc/src/blocks/form/form.js +222 -0
  14. package/packages/_rsc/src/blocks/fragment/component-info.js +11 -0
  15. package/packages/_rsc/src/blocks/fragment/fragment.js +24 -0
  16. package/packages/_rsc/src/blocks/image/component-info.js +151 -0
  17. package/packages/_rsc/src/blocks/image/image.helpers.js +48 -0
  18. package/packages/_rsc/src/blocks/image/image.js +95 -0
  19. package/packages/_rsc/src/blocks/img/component-info.js +20 -0
  20. package/packages/_rsc/src/blocks/img/img.js +33 -0
  21. package/packages/_rsc/src/blocks/input/component-info.js +74 -0
  22. package/packages/_rsc/src/blocks/input/input.js +36 -0
  23. package/packages/_rsc/src/blocks/raw-text/component-info.js +16 -0
  24. package/packages/_rsc/src/blocks/raw-text/raw-text.js +28 -0
  25. package/packages/_rsc/src/blocks/section/component-info.js +49 -0
  26. package/packages/_rsc/src/blocks/section/section.js +31 -0
  27. package/packages/_rsc/src/blocks/select/component-info.js +59 -0
  28. package/packages/_rsc/src/blocks/select/select.js +36 -0
  29. package/packages/_rsc/src/blocks/submit-button/component-info.js +28 -0
  30. package/packages/_rsc/src/blocks/submit-button/submit-button.js +26 -0
  31. package/packages/_rsc/src/blocks/symbol/component-info.js +43 -0
  32. package/packages/_rsc/src/blocks/symbol/symbol.js +51 -0
  33. package/packages/_rsc/src/blocks/text/component-info.js +24 -0
  34. package/packages/_rsc/src/blocks/text/text.js +27 -0
  35. package/packages/_rsc/src/blocks/textarea/component-info.js +47 -0
  36. package/packages/_rsc/src/blocks/textarea/textarea.js +32 -0
  37. package/packages/_rsc/src/blocks/util.js +8 -0
  38. package/packages/_rsc/src/blocks/video/component-info.js +106 -0
  39. package/packages/_rsc/src/blocks/video/video.js +57 -0
  40. package/packages/_rsc/src/components/render-block/block-styles.js +70 -0
  41. package/packages/_rsc/src/components/render-block/render-block.helpers.js +23 -0
  42. package/packages/_rsc/src/components/render-block/render-block.js +203 -0
  43. package/packages/_rsc/src/components/render-block/render-component-with-context.js +51 -0
  44. package/packages/_rsc/src/components/render-block/render-component.js +43 -0
  45. package/packages/_rsc/src/components/render-block/render-repeated-block.js +49 -0
  46. package/packages/_rsc/src/components/render-block/types.js +0 -0
  47. package/packages/_rsc/src/components/render-blocks.js +80 -0
  48. package/packages/_rsc/src/components/render-content/builder-editing.js +35 -0
  49. package/packages/_rsc/src/components/render-content/components/render-styles.js +78 -0
  50. package/packages/_rsc/src/components/render-content/index.js +4 -0
  51. package/packages/_rsc/src/components/render-content/render-content.js +198 -0
  52. package/packages/_rsc/src/components/render-inlined-styles.js +36 -0
  53. package/packages/_rsc/src/constants/builder-registered-components.js +54 -0
  54. package/packages/_rsc/src/constants/device-sizes.js +48 -0
  55. package/packages/_rsc/src/constants/target.js +4 -0
  56. package/packages/_rsc/src/context/builder.context.js +11 -0
  57. package/packages/_rsc/src/context/types.js +0 -0
  58. package/packages/_rsc/src/functions/camel-to-kebab-case.js +4 -0
  59. package/packages/_rsc/src/functions/evaluate.js +6 -0
  60. package/packages/_rsc/src/functions/event-handler-name.js +7 -0
  61. package/packages/_rsc/src/functions/extract-text-styles.js +22 -0
  62. package/packages/_rsc/src/functions/fast-clone.js +4 -0
  63. package/packages/_rsc/src/functions/get-block-actions-handler.js +12 -0
  64. package/packages/_rsc/src/functions/get-block-actions.js +18 -0
  65. package/packages/_rsc/src/functions/get-block-component-options.js +28 -0
  66. package/packages/_rsc/src/functions/get-block-properties.js +29 -0
  67. package/packages/_rsc/src/functions/get-block-tag.js +6 -0
  68. package/packages/_rsc/src/functions/get-builder-search-params/fn.test.js +13 -0
  69. package/packages/_rsc/src/functions/get-builder-search-params/index.js +37 -0
  70. package/packages/_rsc/src/functions/get-content/ab-testing.js +99 -0
  71. package/packages/_rsc/src/functions/get-content/fn.test.js +31 -0
  72. package/packages/_rsc/src/functions/get-content/index.js +100 -0
  73. package/packages/_rsc/src/functions/get-content/types.js +0 -0
  74. package/packages/_rsc/src/functions/get-fetch.js +34 -0
  75. package/packages/_rsc/src/functions/get-global-this.js +18 -0
  76. package/packages/_rsc/src/functions/get-processed-block.js +59 -0
  77. package/packages/_rsc/src/functions/get-processed-block.test.js +32 -0
  78. package/packages/_rsc/src/functions/get-react-native-block-styles.js +32 -0
  79. package/packages/_rsc/src/functions/if-target.js +15 -0
  80. package/packages/_rsc/src/functions/is-browser.js +6 -0
  81. package/packages/_rsc/src/functions/is-editing.js +7 -0
  82. package/packages/_rsc/src/functions/is-iframe.js +7 -0
  83. package/packages/_rsc/src/functions/is-previewing.js +14 -0
  84. package/packages/_rsc/src/functions/mark-mutable.js +10 -0
  85. package/packages/_rsc/src/functions/on-change.js +27 -0
  86. package/packages/_rsc/src/functions/on-change.test.js +19 -0
  87. package/packages/_rsc/src/functions/register-component.js +68 -0
  88. package/packages/_rsc/src/functions/register.js +29 -0
  89. package/packages/_rsc/src/functions/sanitize-react-native-block-styles.js +66 -0
  90. package/packages/_rsc/src/functions/set-editor-settings.js +15 -0
  91. package/packages/_rsc/src/functions/set.js +11 -0
  92. package/packages/_rsc/src/functions/set.test.js +16 -0
  93. package/packages/_rsc/src/functions/track.js +120 -0
  94. package/packages/_rsc/src/functions/transform-block.js +6 -0
  95. package/packages/_rsc/src/helpers/ab-tests.js +16 -0
  96. package/packages/_rsc/src/helpers/cookie.js +79 -0
  97. package/packages/_rsc/src/helpers/css.js +28 -0
  98. package/packages/_rsc/src/helpers/flatten.js +34 -0
  99. package/packages/_rsc/src/helpers/localStorage.js +34 -0
  100. package/packages/_rsc/src/helpers/nullable.js +4 -0
  101. package/packages/_rsc/src/helpers/sessionId.js +49 -0
  102. package/packages/_rsc/src/helpers/time.js +5 -0
  103. package/packages/_rsc/src/helpers/url.js +10 -0
  104. package/packages/_rsc/src/helpers/url.test.js +15 -0
  105. package/packages/_rsc/src/helpers/uuid.js +13 -0
  106. package/packages/_rsc/src/helpers/visitorId.js +33 -0
  107. package/packages/_rsc/src/index-helpers/blocks-exports.js +22 -0
  108. package/packages/_rsc/src/index-helpers/top-of-file.js +2 -0
  109. package/packages/_rsc/src/index.js +14 -0
  110. package/packages/_rsc/src/scripts/init-editing.js +87 -0
  111. package/packages/_rsc/src/types/builder-block.js +0 -0
  112. package/packages/_rsc/src/types/builder-content.js +0 -0
  113. package/packages/_rsc/src/types/can-track.js +0 -0
  114. package/packages/_rsc/src/types/components.js +0 -0
  115. package/packages/_rsc/src/types/deep-partial.js +0 -0
  116. package/packages/_rsc/src/types/element.js +0 -0
  117. package/packages/_rsc/src/types/targets.js +0 -0
  118. package/packages/_rsc/src/types/typescript.js +0 -0
  119. package/src/blocks/button/button.jsx +6 -5
  120. package/src/blocks/columns/columns.jsx +9 -10
  121. package/src/blocks/columns/component-info.js +2 -2
  122. package/src/blocks/embed/component-info.js +2 -2
  123. package/src/blocks/form/form.jsx +4 -7
  124. package/src/blocks/image/component-info.js +2 -2
  125. package/src/blocks/img/img.jsx +2 -5
  126. package/src/blocks/submit-button/submit-button.jsx +2 -5
  127. package/src/blocks/symbol/symbol.jsx +3 -4
  128. package/src/blocks/util.js +6 -5
  129. package/src/components/render-block/block-styles.jsx +9 -3
  130. package/src/components/render-block/render-block.jsx +7 -7
  131. package/src/components/render-block/render-component.jsx +1 -2
  132. package/src/components/render-content/builder-editing.jsx +7 -0
  133. package/src/components/render-content/render-content.jsx +16 -11
  134. package/src/components/render-inlined-styles.jsx +4 -4
  135. package/src/constants/device-sizes.js +29 -2
  136. package/src/constants/target.js +1 -1
  137. package/src/functions/get-content/index.js +6 -2
  138. package/src/functions/register-component.js +1 -5
  139. package/src/functions/track.js +11 -8
  140. package/src/index.js +5 -1
  141. package/src/scripts/init-editing.js +7 -1
@@ -32,14 +32,13 @@ import {
32
32
  components,
33
33
  createRegisterComponentMessage
34
34
  } from "../../functions/register-component.js";
35
- import { track } from "../../functions/track.js";
35
+ import { _track } from "../../functions/track.js";
36
36
  import RenderBlocks from "../render-blocks.jsx";
37
37
  import RenderContentStyles from "./components/render-styles.jsx";
38
38
  import {
39
39
  registerInsertMenu,
40
40
  setupBrowserForEditing
41
41
  } from "../../scripts/init-editing.js";
42
- import { markMutable } from "../../functions/mark-mutable.js";
43
42
  function RenderContent(props) {
44
43
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
45
44
  const elementRef = useRef(null);
@@ -113,13 +112,16 @@ function RenderContent(props) {
113
112
  return {};
114
113
  }
115
114
  function onClick(_event) {
116
- var _a2;
115
+ var _a2, _b2;
117
116
  if (useContent()) {
118
- track({
117
+ const variationId = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.testVariationId;
118
+ const contentId = (_b2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _b2.id;
119
+ _track({
119
120
  type: "click",
120
121
  canTrack: canTrackToUse(),
121
- contentId: (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.id,
122
- orgId: props.apiKey
122
+ contentId,
123
+ apiKey: props.apiKey,
124
+ variationId: variationId !== contentId ? variationId : void 0
123
125
  });
124
126
  }
125
127
  }
@@ -170,7 +172,7 @@ function RenderContent(props) {
170
172
  return Boolean((((_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.cssCode) || ((_e2 = (_d2 = (_c2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _c2.data) == null ? void 0 : _d2.customFonts) == null ? void 0 : _e2.length)) && TARGET !== "reactNative");
171
173
  }
172
174
  useEffect(() => {
173
- var _a2;
175
+ var _a2, _b2;
174
176
  if (isBrowser()) {
175
177
  if (isEditing()) {
176
178
  setForceReRenderCount(forceReRenderCount + 1);
@@ -185,11 +187,14 @@ function RenderContent(props) {
185
187
  window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
186
188
  }
187
189
  if (useContent()) {
188
- track({
190
+ const variationId = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.testVariationId;
191
+ const contentId = (_b2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _b2.id;
192
+ _track({
189
193
  type: "impression",
190
194
  canTrack: canTrackToUse(),
191
- contentId: (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.id,
192
- orgId: props.apiKey
195
+ contentId,
196
+ apiKey: props.apiKey,
197
+ variationId: variationId !== contentId ? variationId : void 0
193
198
  });
194
199
  }
195
200
  if (isPreviewing()) {
@@ -257,7 +262,7 @@ function RenderContent(props) {
257
262
  cssCode: (_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode,
258
263
  customFonts: (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts
259
264
  }) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
260
- blocks: markMutable((_k = (_j = useContent == null ? void 0 : useContent()) == null ? void 0 : _j.data) == null ? void 0 : _k.blocks),
265
+ blocks: (_k = (_j = useContent == null ? void 0 : useContent()) == null ? void 0 : _j.data) == null ? void 0 : _k.blocks,
261
266
  key: forceReRenderCount
262
267
  }))) : null);
263
268
  }
@@ -2,15 +2,15 @@ import * as React from "react";
2
2
  import { TARGET } from "../constants/target.js";
3
3
  function RenderInlinedStyles(props) {
4
4
  function injectedStyleScript() {
5
- return `<${tagName()}>${props.styles}</${tagName()}>`;
5
+ return `<${tag()}>${props.styles}</${tag()}>`;
6
6
  }
7
- function tagName() {
7
+ function tag() {
8
8
  return "style";
9
9
  }
10
- const TagNameRef = tagName();
10
+ const TagRef = tag();
11
11
  return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
12
12
  dangerouslySetInnerHTML: { __html: injectedStyleScript() }
13
- })) : /* @__PURE__ */ React.createElement(TagNameRef, null, props.styles));
13
+ })) : /* @__PURE__ */ React.createElement(TagRef, null, props.styles));
14
14
  }
15
15
  export {
16
16
  RenderInlinedStyles as default
@@ -1,3 +1,4 @@
1
+ import { fastClone } from "../functions/fast-clone";
1
2
  const SIZES = {
2
3
  small: {
3
4
  min: 320,
@@ -15,7 +16,33 @@ const SIZES = {
15
16
  max: 1200
16
17
  }
17
18
  };
18
- const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
19
+ const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
20
+ const getSizesForBreakpoints = ({ small, medium }) => {
21
+ const newSizes = fastClone(SIZES);
22
+ if (!small || !medium) {
23
+ return newSizes;
24
+ }
25
+ const smallMin = Math.floor(small / 2);
26
+ newSizes.small = {
27
+ max: small,
28
+ min: smallMin,
29
+ default: smallMin + 1
30
+ };
31
+ const mediumMin = newSizes.small.max + 1;
32
+ newSizes.medium = {
33
+ max: medium,
34
+ min: mediumMin,
35
+ default: mediumMin + 1
36
+ };
37
+ const largeMin = newSizes.medium.max + 1;
38
+ newSizes.large = {
39
+ max: 2e3,
40
+ min: largeMin,
41
+ default: largeMin + 1
42
+ };
43
+ return newSizes;
44
+ };
19
45
  export {
20
- getMaxWidthQueryForSize
46
+ getMaxWidthQueryForSize,
47
+ getSizesForBreakpoints
21
48
  };
@@ -1,4 +1,4 @@
1
- const TARGET = "reactNative";
1
+ const TARGET = "react";
2
2
  export {
3
3
  TARGET
4
4
  };
@@ -56,9 +56,13 @@ const generateContentUrl = (options) => {
56
56
  query,
57
57
  noTraverse = false,
58
58
  model,
59
- apiKey
59
+ apiKey,
60
+ includeRefs = true
60
61
  } = options;
61
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
62
+ if (!apiKey) {
63
+ throw new Error("Missing API key");
64
+ }
65
+ const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
62
66
  const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
63
67
  const flattened = flatten(queryOptions);
64
68
  for (const key in flattened) {
@@ -29,6 +29,7 @@ var __objRest = (source, exclude) => {
29
29
  }
30
30
  return target;
31
31
  };
32
+ import { serializeFn } from "../blocks/util.js";
32
33
  import { fastClone } from "./fast-clone.js";
33
34
  const components = [];
34
35
  function registerComponent(component, info) {
@@ -48,11 +49,6 @@ const createRegisterComponentMessage = (_a) => {
48
49
  };
49
50
  };
50
51
  const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
51
- const serializeFn = (fnValue) => {
52
- const fnStr = fnValue.toString().trim();
53
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
54
- return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
55
- };
56
52
  const prepareComponentInfoToSend = (_c) => {
57
53
  var _d = _c, {
58
54
  inputs
@@ -71,23 +71,24 @@ const createEvent = (_a) => __async(void 0, null, function* () {
71
71
  var _b = _a, {
72
72
  type: eventType,
73
73
  canTrack,
74
- orgId,
75
- contentId
74
+ apiKey,
75
+ metadata
76
76
  } = _b, properties = __objRest(_b, [
77
77
  "type",
78
78
  "canTrack",
79
- "orgId",
80
- "contentId"
79
+ "apiKey",
80
+ "metadata"
81
81
  ]);
82
82
  return {
83
83
  type: eventType,
84
- data: __spreadProps(__spreadValues(__spreadValues({}, properties), yield getTrackingEventData({ canTrack })), {
85
- ownerId: orgId,
86
- contentId
84
+ data: __spreadProps(__spreadValues(__spreadProps(__spreadValues({}, properties), {
85
+ metadata: JSON.stringify(metadata)
86
+ }), yield getTrackingEventData({ canTrack })), {
87
+ ownerId: apiKey
87
88
  })
88
89
  };
89
90
  });
90
- function track(eventProps) {
91
+ function _track(eventProps) {
91
92
  return __async(this, null, function* () {
92
93
  if (!eventProps.canTrack) {
93
94
  return;
@@ -112,6 +113,8 @@ function track(eventProps) {
112
113
  });
113
114
  });
114
115
  }
116
+ const track = (args) => _track(__spreadProps(__spreadValues({}, args), { canTrack: true }));
115
117
  export {
118
+ _track,
116
119
  track
117
120
  };
package/src/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import "./index-helpers/top-of-file.js";
1
+ export * from "./index-helpers/top-of-file.js";
2
2
  import "./scripts/init-editing.js";
3
3
  export * from "./index-helpers/blocks-exports.js";
4
4
  export * from "./functions/is-editing.js";
@@ -8,3 +8,7 @@ export * from "./functions/register.js";
8
8
  export * from "./functions/set-editor-settings.js";
9
9
  export * from "./functions/get-content/index.js";
10
10
  export * from "./functions/get-builder-search-params/index.js";
11
+ import { track } from "./functions/track";
12
+ export {
13
+ track
14
+ };
@@ -19,15 +19,21 @@ const registerInsertMenu = () => {
19
19
  ]
20
20
  });
21
21
  };
22
+ let isSetupForEditing = false;
22
23
  const setupBrowserForEditing = () => {
23
24
  var _a;
25
+ if (isSetupForEditing) {
26
+ return;
27
+ }
28
+ isSetupForEditing = true;
24
29
  if (isBrowser()) {
25
30
  (_a = window.parent) == null ? void 0 : _a.postMessage({
26
31
  type: "builder.sdkInfo",
27
32
  data: {
28
33
  target: TARGET,
29
34
  supportsPatchUpdates: false,
30
- supportsAddBlockScoping: true
35
+ supportsAddBlockScoping: true,
36
+ supportsCustomBreakpoints: true
31
37
  }
32
38
  }, "*");
33
39
  window.addEventListener("message", ({ data }) => {