@builder.io/sdk-react-nextjs 0.22.0 → 0.22.2

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 (45) hide show
  1. package/lib/browser/blocks/img/component-info.cjs +1 -1
  2. package/lib/browser/blocks/img/component-info.mjs +33 -3
  3. package/lib/browser/blocks/img/img.cjs +1 -1
  4. package/lib/browser/blocks/img/img.mjs +22 -17
  5. package/lib/browser/constants/sdk-version.cjs +1 -1
  6. package/lib/browser/constants/sdk-version.mjs +1 -1
  7. package/lib/browser/functions/get-content/generate-content-url.cjs +1 -1
  8. package/lib/browser/functions/get-content/generate-content-url.mjs +38 -42
  9. package/lib/browser/functions/get-content/index.cjs +1 -1
  10. package/lib/browser/functions/get-content/index.mjs +42 -36
  11. package/lib/browser/functions/is-previewing.cjs +1 -1
  12. package/lib/browser/functions/is-previewing.mjs +4 -4
  13. package/lib/edge/blocks/img/component-info.cjs +1 -1
  14. package/lib/edge/blocks/img/component-info.mjs +33 -3
  15. package/lib/edge/blocks/img/img.cjs +1 -1
  16. package/lib/edge/blocks/img/img.mjs +22 -17
  17. package/lib/edge/constants/sdk-version.cjs +1 -1
  18. package/lib/edge/constants/sdk-version.mjs +1 -1
  19. package/lib/edge/functions/get-content/generate-content-url.cjs +1 -1
  20. package/lib/edge/functions/get-content/generate-content-url.mjs +38 -42
  21. package/lib/edge/functions/get-content/index.cjs +1 -1
  22. package/lib/edge/functions/get-content/index.mjs +42 -36
  23. package/lib/edge/functions/is-previewing.cjs +1 -1
  24. package/lib/edge/functions/is-previewing.mjs +4 -4
  25. package/lib/node/blocks/img/component-info.cjs +1 -1
  26. package/lib/node/blocks/img/component-info.mjs +33 -3
  27. package/lib/node/blocks/img/img.cjs +1 -1
  28. package/lib/node/blocks/img/img.mjs +22 -17
  29. package/lib/node/constants/sdk-version.cjs +1 -1
  30. package/lib/node/constants/sdk-version.mjs +1 -1
  31. package/lib/node/functions/get-content/generate-content-url.cjs +1 -1
  32. package/lib/node/functions/get-content/generate-content-url.mjs +38 -42
  33. package/lib/node/functions/get-content/index.cjs +1 -1
  34. package/lib/node/functions/get-content/index.mjs +42 -36
  35. package/lib/node/functions/is-previewing.cjs +1 -1
  36. package/lib/node/functions/is-previewing.mjs +4 -4
  37. package/package.json +1 -1
  38. package/types/cjs/blocks/img/img.d.ts +2 -0
  39. package/types/cjs/constants/sdk-version.d.ts +1 -1
  40. package/types/cjs/functions/get-builder-search-params/index.d.ts +8 -2
  41. package/types/cjs/functions/is-previewing.d.ts +11 -1
  42. package/types/esm/blocks/img/img.d.ts +2 -0
  43. package/types/esm/constants/sdk-version.d.ts +1 -1
  44. package/types/esm/functions/get-builder-search-params/index.d.ts +8 -2
  45. package/types/esm/functions/is-previewing.d.ts +11 -1
@@ -1,67 +1,73 @@
1
1
  import { TARGET as u } from "../../constants/target.mjs";
2
- import { handleABTesting as l } from "../../helpers/ab-tests.mjs";
2
+ import { handleABTesting as f } from "../../helpers/ab-tests.mjs";
3
3
  import { getDefaultCanTrack as m } from "../../helpers/canTrack.mjs";
4
4
  import { logger as i } from "../../helpers/logger.mjs";
5
5
  import { getPreviewContent as h } from "../../helpers/preview-lru-cache/get.mjs";
6
6
  import { getSdkHeaders as w } from "../../helpers/sdk-headers.mjs";
7
- import { fetch as p } from "../get-fetch.mjs";
8
- import { isBrowser as g } from "../is-browser.mjs";
9
- import { generateContentUrl as a } from "./generate-content-url.mjs";
10
- const C = (t) => "results" in t;
11
- async function H(t) {
12
- const e = await y({
13
- ...t,
7
+ import { fetch as g } from "../get-fetch.mjs";
8
+ import { isBrowser as C } from "../is-browser.mjs";
9
+ import { generateContentUrl as o } from "./generate-content-url.mjs";
10
+ const d = (e) => "results" in e;
11
+ async function _(e) {
12
+ var n;
13
+ const t = e.locale || ((n = e.userAttributes) == null ? void 0 : n.locale);
14
+ t && (e.locale = t, e.userAttributes = {
15
+ locale: t,
16
+ ...e.userAttributes
17
+ });
18
+ const r = await y({
19
+ ...e,
14
20
  limit: 1
15
21
  });
16
- return e && e[0] || null;
22
+ return r && r[0] || null;
17
23
  }
18
- const d = async (t) => {
19
- var n, c;
20
- const e = a(t), r = (n = t.fetch) != null ? n : p, o = {
21
- ...t.fetchOptions,
24
+ const p = async (e) => {
25
+ var c, a;
26
+ const t = o(e), r = (c = e.fetch) != null ? c : g, n = {
27
+ ...e.fetchOptions,
22
28
  headers: {
23
- ...(c = t.fetchOptions) == null ? void 0 : c.headers,
29
+ ...(a = e.fetchOptions) == null ? void 0 : a.headers,
24
30
  ...w()
25
31
  }
26
32
  };
27
- return await (await r(e.href, o)).json();
28
- }, v = async (t, e, r = a(t)) => {
29
- const o = m(t.canTrack);
33
+ return await (await r(t.href, n)).json();
34
+ }, v = async (e, t, r = o(e)) => {
35
+ const n = m(e.canTrack);
30
36
  if (r.search.includes("preview=")) {
31
37
  const s = [];
32
- for (const n of e.results) {
33
- const c = h(r.searchParams);
34
- s.push(c || n);
38
+ for (const c of t.results) {
39
+ const a = h(r.searchParams);
40
+ s.push(a || c);
35
41
  }
36
- e.results = s;
42
+ t.results = s;
37
43
  }
38
- if (!o || !(g() || u === "reactNative"))
39
- return e.results;
44
+ if (!n || !(C() || u === "reactNative"))
45
+ return t.results;
40
46
  try {
41
47
  const s = [];
42
- for (const n of e.results)
43
- s.push(await l({
44
- item: n,
45
- canTrack: o
48
+ for (const c of t.results)
49
+ s.push(await f({
50
+ item: c,
51
+ canTrack: n
46
52
  }));
47
- e.results = s;
53
+ t.results = s;
48
54
  } catch (s) {
49
55
  i.error("Could not process A/B tests. ", s);
50
56
  }
51
- return e.results;
57
+ return t.results;
52
58
  };
53
- async function y(t) {
54
- const e = a(t), r = await d(t);
55
- if (!C(r))
59
+ async function y(e) {
60
+ const t = o(e), r = await p(e);
61
+ if (!d(r))
56
62
  throw i.error("Error fetching data. ", {
57
- url: e,
63
+ url: t,
58
64
  content: r,
59
- options: t
65
+ options: e
60
66
  }), r;
61
- return v(t, r);
67
+ return v(e, r);
62
68
  }
63
69
  export {
64
70
  v as _processContentResult,
65
71
  y as fetchEntries,
66
- H as fetchOneEntry
72
+ _ as fetchOneEntry
67
73
  };
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../helpers/search/search.cjs"),n=require("./is-browser.cjs");function o(r){const e=r||(n.isBrowser()?window.location.search:void 0);return e?i.getSearchString(e).indexOf("builder.preview=")!==-1:!1}exports.isPreviewing=o;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const i=require("../helpers/search/search.cjs"),o=require("./is-browser.cjs");function n(r){const e=r||(o.isBrowser()?window.location.search:void 0);return e?i.getSearchString(e).indexOf("builder.preview=")!==-1:!1}exports.isPreviewing=n;
@@ -1,8 +1,8 @@
1
- import { getSearchString as i } from "../helpers/search/search.mjs";
2
- import { isBrowser as o } from "./is-browser.mjs";
1
+ import { getSearchString as o } from "../helpers/search/search.mjs";
2
+ import { isBrowser as i } from "./is-browser.mjs";
3
3
  function c(e) {
4
- const r = e || (o() ? window.location.search : void 0);
5
- return r ? i(r).indexOf("builder.preview=") !== -1 : !1;
4
+ const r = e || (i() ? window.location.search : void 0);
5
+ return r ? o(r).indexOf("builder.preview=") !== -1 : !1;
6
6
  }
7
7
  export {
8
8
  c as isPreviewing
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react-nextjs",
3
3
  "description": "Builder.io RSC SDK for NextJS App Directory",
4
- "version": "0.22.0",
4
+ "version": "0.22.2",
5
5
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/nextjs",
6
6
  "repository": {
7
7
  "type": "git",
@@ -9,6 +9,8 @@ export interface ImgProps {
9
9
  altText?: string;
10
10
  backgroundSize?: "cover" | "contain";
11
11
  backgroundPosition?: "center" | "top" | "left" | "right" | "bottom" | "top left" | "top right" | "bottom left" | "bottom right";
12
+ aspectRatio?: number;
13
+ title?: string;
12
14
  }
13
15
  declare function ImgComponent(props: ImgProps): React.JSX.Element;
14
16
  export default ImgComponent;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.22.0";
1
+ export declare const SDK_VERSION = "0.22.2";
@@ -1,7 +1,13 @@
1
1
  import type { QueryObject } from '../../helpers/search/search.js';
2
2
  /**
3
- * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
4
- * relevant to the Builder SDK.
3
+ * Receives a `URLSearchParams` object or a regular query object, and returns
4
+ * the subset of query params that are relevant to the Builder SDK.
5
+ *
6
+ * Outputs a key-value object to be passed to `fetchOneEntry` or `fetchEntries`
7
+ * functions as the `options` argument.
8
+ *
9
+ * NOTE: This function is generally not needed. Instead, it is recommended to use `isPreviewing()`
10
+ * to check if the current page requires previewed content.
5
11
  *
6
12
  * @returns
7
13
  */
@@ -1,2 +1,12 @@
1
1
  import type { Search } from '../helpers/search/search.js';
2
- export declare function isPreviewing(_search?: Search): boolean;
2
+ /**
3
+ * Checks the current URL's search parameters to see if it is attempting to
4
+ * preview Builder Content.
5
+ *
6
+ * When called on the client, it uses `window.location.search`.
7
+ * When called on the server (SSR), it requires a `search` argument.
8
+ *
9
+ * @param search - The search parameters to check. Can be a URL string (containing the search parameters), `URLSearchParams`, or a key-value object containing the search parameters.
10
+ * @returns `true` if the current page is being previewed, `false` otherwise.
11
+ */
12
+ export declare function isPreviewing(search?: Search): boolean;
@@ -9,6 +9,8 @@ export interface ImgProps {
9
9
  altText?: string;
10
10
  backgroundSize?: "cover" | "contain";
11
11
  backgroundPosition?: "center" | "top" | "left" | "right" | "bottom" | "top left" | "top right" | "bottom left" | "bottom right";
12
+ aspectRatio?: number;
13
+ title?: string;
12
14
  }
13
15
  declare function ImgComponent(props: ImgProps): React.JSX.Element;
14
16
  export default ImgComponent;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.22.0";
1
+ export declare const SDK_VERSION = "0.22.2";
@@ -1,7 +1,13 @@
1
1
  import type { QueryObject } from '../../helpers/search/search.js';
2
2
  /**
3
- * Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
4
- * relevant to the Builder SDK.
3
+ * Receives a `URLSearchParams` object or a regular query object, and returns
4
+ * the subset of query params that are relevant to the Builder SDK.
5
+ *
6
+ * Outputs a key-value object to be passed to `fetchOneEntry` or `fetchEntries`
7
+ * functions as the `options` argument.
8
+ *
9
+ * NOTE: This function is generally not needed. Instead, it is recommended to use `isPreviewing()`
10
+ * to check if the current page requires previewed content.
5
11
  *
6
12
  * @returns
7
13
  */
@@ -1,2 +1,12 @@
1
1
  import type { Search } from '../helpers/search/search.js';
2
- export declare function isPreviewing(_search?: Search): boolean;
2
+ /**
3
+ * Checks the current URL's search parameters to see if it is attempting to
4
+ * preview Builder Content.
5
+ *
6
+ * When called on the client, it uses `window.location.search`.
7
+ * When called on the server (SSR), it requires a `search` argument.
8
+ *
9
+ * @param search - The search parameters to check. Can be a URL string (containing the search parameters), `URLSearchParams`, or a key-value object containing the search parameters.
10
+ * @returns `true` if the current page is being previewed, `false` otherwise.
11
+ */
12
+ export declare function isPreviewing(search?: Search): boolean;