@builder.io/sdk-react 0.5.5 → 0.5.7

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.
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import * as React from "react";
3
3
  import { useContext } from "react";
4
- import BuilderContext from "../context/builder.context";
4
+ import BuilderContext from "../context/builder.context.js";
5
5
  function BaseText(props) {
6
6
  const builderContext = useContext(BuilderContext);
7
7
  return (React.createElement("span", { style: builderContext.inheritedStyles }, props.text));
@@ -8,7 +8,7 @@ export interface SymbolInfo {
8
8
  inline?: boolean;
9
9
  dynamic?: boolean;
10
10
  }
11
- export declare const fetchContent: ({ builderContextValue, symbol }: {
11
+ export declare const fetchSymbolContent: ({ builderContextValue, symbol }: {
12
12
  symbol: SymbolInfo | undefined;
13
13
  builderContextValue: BuilderContextInterface;
14
14
  }) => Promise<any>;
@@ -1,6 +1,6 @@
1
- import { getContent } from '../../functions/get-content/index.js';
2
1
  import { logger } from '../../helpers/logger.js';
3
- export const fetchContent = async ({ builderContextValue, symbol }) => {
2
+ import { fetchOneEntry } from '../../index.js';
3
+ export const fetchSymbolContent = async ({ builderContextValue, symbol }) => {
4
4
  /**
5
5
  * If:
6
6
  * - we have a symbol prop
@@ -13,7 +13,7 @@ export const fetchContent = async ({ builderContextValue, symbol }) => {
13
13
  if (symbol?.model &&
14
14
  // This is a hack, we should not need to check for this, but it is needed for Svelte.
15
15
  builderContextValue?.apiKey) {
16
- return getContent({
16
+ return fetchOneEntry({
17
17
  model: symbol.model,
18
18
  apiKey: builderContextValue.apiKey,
19
19
  apiVersion: builderContextValue.apiVersion,
@@ -2,7 +2,7 @@
2
2
  import * as React from "react";
3
3
  import { useState, useEffect } from "react";
4
4
  import ContentVariants from "../../components/content-variants/content-variants";
5
- import { fetchContent } from "./symbol.helpers.js";
5
+ import { fetchSymbolContent } from "./symbol.helpers.js";
6
6
  function Symbol(props) {
7
7
  function className() {
8
8
  return [
@@ -20,7 +20,7 @@ function Symbol(props) {
20
20
  function setContent() {
21
21
  if (contentToUse)
22
22
  return;
23
- fetchContent({
23
+ fetchSymbolContent({
24
24
  symbol: props.symbol,
25
25
  builderContextValue: props.builderContext,
26
26
  }).then((newContent) => {
@@ -1,4 +1,4 @@
1
- import { evaluate } from '../../functions/evaluate';
1
+ import { evaluate } from '../../functions/evaluate/index.js';
2
2
  import { getProcessedBlock } from '../../functions/get-processed-block.js';
3
3
  /**
4
4
  * https://developer.mozilla.org/en-US/docs/Glossary/Empty_element
@@ -1,7 +1,7 @@
1
1
  "use client";
2
2
  import * as React from "react";
3
3
  import { useState } from "react";
4
- import BuilderContext from "../../../context/builder.context";
4
+ import BuilderContext from "../../../context/builder.context.js";
5
5
  import Block from "../block";
6
6
  function RepeatedBlock(props) {
7
7
  const [store, setStore] = useState(() => props.repeatContext);
@@ -28,8 +28,8 @@ function BlocksWrapper(props) {
28
28
  }
29
29
  }
30
30
  return (React.createElement(React.Fragment, null,
31
- React.createElement("div", { className: className() + " div-b2473120", "builder-path": props.path, "builder-parent-id": props.parent, ...{}, style: props.styleProp, onClick: (event) => onClick(), onMouseEnter: (event) => onMouseEnter(), onKeyPress: (event) => onClick() }, props.children),
32
- React.createElement("style", null, `.div-b2473120 {
31
+ React.createElement("div", { className: className() + " div-5285fe33", "builder-path": props.path, "builder-parent-id": props.parent, ...{}, style: props.styleProp, onClick: (event) => onClick(), onMouseEnter: (event) => onMouseEnter(), onKeyPress: (event) => onClick() }, props.children),
32
+ React.createElement("style", null, `.div-5285fe33 {
33
33
  display: flex;
34
34
  flex-direction: column;
35
35
  align-items: stretch;
@@ -4,8 +4,8 @@ import { useContext } from "react";
4
4
  import BlockStyles from "../block/components/block-styles";
5
5
  import Block from "../block/block";
6
6
  import BlocksWrapper from "./blocks-wrapper";
7
- import BuilderContext from "../../context/builder.context";
8
- import ComponentsContext from "../../context/components.context";
7
+ import BuilderContext from "../../context/builder.context.js";
8
+ import ComponentsContext from "../../context/components.context.js";
9
9
  function Blocks(props) {
10
10
  const builderContext = useContext(BuilderContext);
11
11
  const componentsContext = useContext(ComponentsContext);
@@ -1,18 +1,18 @@
1
1
  "use client";
2
2
  import * as React from "react";
3
3
  import { useState, useRef, useEffect } from "react";
4
- import { evaluate } from "../../../functions/evaluate";
4
+ import { evaluate } from "../../../functions/evaluate/index.js";
5
5
  import { fetch } from "../../../functions/get-fetch.js";
6
6
  import { isBrowser } from "../../../functions/is-browser.js";
7
7
  import { isEditing } from "../../../functions/is-editing.js";
8
8
  import { createRegisterComponentMessage } from "../../../functions/register-component.js";
9
9
  import { _track } from "../../../functions/track/index.js";
10
- import builderContext from "../../../context/builder.context";
10
+ import builderContext from "../../../context/builder.context.js";
11
11
  import { registerInsertMenu, setupBrowserForEditing, } from "../../../scripts/init-editing.js";
12
12
  import { checkIsDefined } from "../../../helpers/nullable.js";
13
13
  import { getInteractionPropertiesForEvent } from "../../../functions/track/interaction.js";
14
14
  import { logger } from "../../../helpers/logger.js";
15
- import { getContent } from "../../../functions/get-content/index.js";
15
+ import { fetchOneEntry } from "../../../functions/get-content/index.js";
16
16
  import { isPreviewing } from "../../../functions/is-previewing.js";
17
17
  function EnableEditor(props) {
18
18
  const elementRef = useRef(null);
@@ -217,7 +217,7 @@ function EnableEditor(props) {
217
217
  if (searchParamPreviewModel === props.model &&
218
218
  previewApiKey === props.apiKey &&
219
219
  (!props.content || searchParamPreviewId === props.content.id)) {
220
- getContent({
220
+ fetchOneEntry({
221
221
  model: props.model,
222
222
  apiKey: props.apiKey,
223
223
  apiVersion: props.builderContextSignal.apiVersion,
@@ -10,7 +10,7 @@ import { TARGET } from "../../constants/target.js";
10
10
  import { getRenderContentScriptString } from "../content-variants/helpers.js";
11
11
  import EnableEditor from "./components/enable-editor";
12
12
  import InlinedScript from "../inlined-script";
13
- import ComponentsContext from "../../context/components.context";
13
+ import ComponentsContext from "../../context/components.context.js";
14
14
  function ContentComponent(props) {
15
15
  const [scriptStr, setScriptStr] = useState(() => getRenderContentScriptString({
16
16
  // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "UNKNOWN_VERSION";
1
+ export declare const SDK_VERSION = "0.5.7";
@@ -1 +1 @@
1
- export const SDK_VERSION = 'UNKNOWN_VERSION';
1
+ export const SDK_VERSION = "0.5.7";
@@ -0,0 +1,39 @@
1
+ import type { ContentVariantsProps } from '../components/content-variants/content-variants.types.js';
2
+ import type { Dictionary } from '../types/typescript.js';
3
+ import type { GetContentOptions } from './get-content/types.js';
4
+ type GetBuilderPropsOptions = (Omit<GetContentOptions, 'model'> & {
5
+ model?: string;
6
+ }) & ({
7
+ /**
8
+ * The current URL path. Used to determine the `urlPath` for targeting content.
9
+ *
10
+ * Cannot be used with `url`.
11
+ */
12
+ path: string;
13
+ /**
14
+ * The current URL search params. Used to parse the `searchParams` for targeting content.
15
+ *
16
+ * Cannot be used with `url`.
17
+ */
18
+ searchParams?: URLSearchParams | Dictionary<string | string[]>;
19
+ url?: undefined;
20
+ } | {
21
+ /**
22
+ * The current URL. Used to determine the `urlPath` for targeting content and
23
+ * to parse the `searchParams` for targeting content.
24
+ *
25
+ * Cannot be used with `path` or `searchParams`.
26
+ */
27
+ url: URL;
28
+ path?: undefined;
29
+ searchParams?: undefined;
30
+ } | {
31
+ url?: undefined;
32
+ path?: undefined;
33
+ searchParams?: undefined;
34
+ });
35
+ /**
36
+ * Fetches builder content, and returns it along with sensible defaults for other props that `Content` needs to render.
37
+ */
38
+ export declare const fetchBuilderProps: (_args: GetBuilderPropsOptions) => Promise<ContentVariantsProps>;
39
+ export {};
@@ -0,0 +1,25 @@
1
+ import { getBuilderSearchParams } from './get-builder-search-params/index.js';
2
+ import { fetchOneEntry } from './get-content/index.js';
3
+ /**
4
+ * Fetches builder content, and returns it along with sensible defaults for other props that `Content` needs to render.
5
+ */
6
+ export const fetchBuilderProps = async (_args) => {
7
+ const urlPath = _args.path || _args.url?.pathname || _args.userAttributes?.urlPath;
8
+ const getContentArgs = {
9
+ ..._args,
10
+ apiKey: _args.apiKey,
11
+ model: _args.model || 'page',
12
+ userAttributes: {
13
+ ..._args.userAttributes,
14
+ ...(urlPath ? {
15
+ urlPath
16
+ } : {})
17
+ },
18
+ options: getBuilderSearchParams(_args.searchParams || _args.url?.searchParams || _args.options)
19
+ };
20
+ return {
21
+ apiKey: getContentArgs.apiKey,
22
+ model: getContentArgs.model,
23
+ content: await fetchOneEntry(getContentArgs)
24
+ };
25
+ };
@@ -1,12 +1,29 @@
1
1
  import type { BuilderContent } from '../../types/builder-content.js';
2
2
  import type { GetContentOptions } from './types.js';
3
- export declare function getContent(options: GetContentOptions): Promise<BuilderContent | null>;
3
+ /**
4
+ * Returns a the first entry that matches the given options.
5
+ */
6
+ export declare function fetchOneEntry(options: GetContentOptions): Promise<BuilderContent | null>;
7
+ /**
8
+ * @deprecated
9
+ * Consider using `fetchBuilderProps` instead for easier setup.
10
+ *
11
+ * NOTE: `getContent` was renamed to `fetchOneEntry` and will be removed in a future release.
12
+ */
13
+ export declare const getContent: typeof fetchOneEntry;
4
14
  type ContentResults = {
5
15
  results: BuilderContent[];
6
16
  };
7
17
  /**
8
18
  * Exported only for testing purposes. Should not be used directly.
9
19
  */
10
- export declare const processContentResult: (options: GetContentOptions, content: ContentResults, url?: URL) => Promise<ContentResults>;
11
- export declare function getAllContent(options: GetContentOptions): Promise<ContentResults>;
20
+ export declare const _processContentResult: (options: GetContentOptions, content: ContentResults, url?: URL) => Promise<ContentResults>;
21
+ /**
22
+ * Returns a paginated array of entries that match the given options.
23
+ */
24
+ export declare function fetchEntries(options: GetContentOptions): Promise<ContentResults>;
25
+ /**
26
+ * @deprecated Use `fetchEntries` instead.
27
+ */
28
+ export declare const getAllContent: typeof fetchEntries;
12
29
  export {};
@@ -7,8 +7,11 @@ import { fetch } from '../get-fetch.js';
7
7
  import { isBrowser } from '../is-browser.js';
8
8
  import { generateContentUrl } from './generate-content-url.js';
9
9
  const checkContentHasResults = (content) => 'results' in content;
10
- export async function getContent(options) {
11
- const allContent = await getAllContent({
10
+ /**
11
+ * Returns a the first entry that matches the given options.
12
+ */
13
+ export async function fetchOneEntry(options) {
14
+ const allContent = await fetchEntries({
12
15
  ...options,
13
16
  limit: 1
14
17
  });
@@ -17,7 +20,14 @@ export async function getContent(options) {
17
20
  }
18
21
  return null;
19
22
  }
20
- const fetchContent = async (options) => {
23
+ /**
24
+ * @deprecated
25
+ * Consider using `fetchBuilderProps` instead for easier setup.
26
+ *
27
+ * NOTE: `getContent` was renamed to `fetchOneEntry` and will be removed in a future release.
28
+ */
29
+ export const getContent = fetchOneEntry;
30
+ const _fetchContent = async (options) => {
21
31
  const url = generateContentUrl(options);
22
32
  const res = await fetch(url.href);
23
33
  const content = await res.json();
@@ -26,7 +36,7 @@ const fetchContent = async (options) => {
26
36
  /**
27
37
  * Exported only for testing purposes. Should not be used directly.
28
38
  */
29
- export const processContentResult = async (options, content, url = generateContentUrl(options)) => {
39
+ export const _processContentResult = async (options, content, url = generateContentUrl(options)) => {
30
40
  const canTrack = getDefaultCanTrack(options.canTrack);
31
41
  const isPreviewing = url.search.includes(`preview=`);
32
42
  if (TARGET === 'rsc' && isPreviewing) {
@@ -62,10 +72,13 @@ export const processContentResult = async (options, content, url = generateConte
62
72
  }
63
73
  return content;
64
74
  };
65
- export async function getAllContent(options) {
75
+ /**
76
+ * Returns a paginated array of entries that match the given options.
77
+ */
78
+ export async function fetchEntries(options) {
66
79
  try {
67
80
  const url = generateContentUrl(options);
68
- const content = await fetchContent(options);
81
+ const content = await _fetchContent(options);
69
82
  if (!checkContentHasResults(content)) {
70
83
  logger.error('Error fetching data. ', {
71
84
  url,
@@ -74,10 +87,14 @@ export async function getAllContent(options) {
74
87
  });
75
88
  return null;
76
89
  }
77
- return processContentResult(options, content);
90
+ return _processContentResult(options, content);
78
91
  }
79
92
  catch (error) {
80
93
  logger.error('Error fetching data. ', error);
81
94
  return null;
82
95
  }
83
96
  }
97
+ /**
98
+ * @deprecated Use `fetchEntries` instead.
99
+ */
100
+ export const getAllContent = fetchEntries;
@@ -1,4 +1,4 @@
1
- import { evaluate } from './evaluate';
1
+ import { evaluate } from './evaluate/index.js';
2
2
  import { fastClone } from './fast-clone.js';
3
3
  import { set } from './set.js';
4
4
  import { transformBlock } from './transform-block.js';
@@ -1,4 +1,4 @@
1
- import { isBrowser } from './is-browser';
1
+ import { isBrowser } from './is-browser.js';
2
2
  /**
3
3
  * Identifies non-node server runtimes (edge, workers, serverless, etc.)
4
4
  */
@@ -1,2 +1,2 @@
1
- import type { BuilderContent } from '../../types/builder-content';
1
+ import type { BuilderContent } from '../../types/builder-content.js';
2
2
  export declare function getPreviewContent(_searchParams: URLSearchParams): BuilderContent | undefined;
@@ -1,4 +1,4 @@
1
- import type { BuilderContent } from '../../types/builder-content';
1
+ import type { BuilderContent } from '../../types/builder-content.js';
2
2
  export declare function postPreviewContent({ key, value }: {
3
3
  key: string;
4
4
  value: BuilderContent;
@@ -2,9 +2,18 @@ export { default as Button } from '../blocks/button/button';
2
2
  export { default as Columns } from '../blocks/columns/columns';
3
3
  export { default as Fragment } from '../blocks/fragment/fragment';
4
4
  export { default as Image } from '../blocks/image/image';
5
- export { default as RenderBlocks } from '../components/blocks/blocks';
6
5
  export { default as Section } from '../blocks/section/section';
7
6
  export { default as Symbol } from '../blocks/symbol/symbol';
8
7
  export { default as Text } from '../blocks/text/text';
9
8
  export { default as Video } from '../blocks/video/video';
10
- export { default as RenderContent } from '../components/content-variants/content-variants';
9
+ import { default as Blocks } from '../components/blocks/blocks';
10
+ import { default as Content } from '../components/content-variants/content-variants';
11
+ export { Blocks, Content };
12
+ /**
13
+ * @deprecated Use `Blocks` instead.
14
+ */
15
+ export declare const RenderBlocks: typeof Blocks;
16
+ /**
17
+ * @deprecated Use `Content` instead.
18
+ */
19
+ export declare const RenderContent: typeof Content;
@@ -2,9 +2,18 @@ export { default as Button } from '../blocks/button/button';
2
2
  export { default as Columns } from '../blocks/columns/columns';
3
3
  export { default as Fragment } from '../blocks/fragment/fragment';
4
4
  export { default as Image } from '../blocks/image/image';
5
- export { default as RenderBlocks } from '../components/blocks/blocks';
6
5
  export { default as Section } from '../blocks/section/section';
7
6
  export { default as Symbol } from '../blocks/symbol/symbol';
8
7
  export { default as Text } from '../blocks/text/text';
9
8
  export { default as Video } from '../blocks/video/video';
10
- export { default as RenderContent } from '../components/content-variants/content-variants';
9
+ import { default as Blocks } from '../components/blocks/blocks';
10
+ import { default as Content } from '../components/content-variants/content-variants';
11
+ export { Blocks, Content };
12
+ /**
13
+ * @deprecated Use `Blocks` instead.
14
+ */
15
+ export const RenderBlocks = Blocks;
16
+ /**
17
+ * @deprecated Use `Content` instead.
18
+ */
19
+ export const RenderContent = Content;
package/dist/index.d.ts CHANGED
@@ -7,9 +7,10 @@ export { register } from './functions/register.js';
7
7
  export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
8
8
  export { setEditorSettings } from './functions/set-editor-settings.js';
9
9
  export type { Settings } from './functions/set-editor-settings.js';
10
- export { getAllContent, getContent, processContentResult } from './functions/get-content/index.js';
10
+ export { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from './functions/get-content/index.js';
11
11
  export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
12
12
  export { track } from './functions/track/index.js';
13
- export type { RegisteredComponent } from './context/types';
14
- export type { ComponentInfo } from './types/components';
13
+ export type { RegisteredComponent } from './context/types.js';
14
+ export type { ComponentInfo } from './types/components.js';
15
15
  export type { ContentProps } from './components/content/content.types.js';
16
+ export { fetchBuilderProps } from './functions/fetch-builder-props.js';
package/dist/index.js CHANGED
@@ -5,6 +5,7 @@ export { isPreviewing } from './functions/is-previewing.js';
5
5
  export { createRegisterComponentMessage } from './functions/register-component.js';
6
6
  export { register } from './functions/register.js';
7
7
  export { setEditorSettings } from './functions/set-editor-settings.js';
8
- export { getAllContent, getContent, processContentResult } from './functions/get-content/index.js';
8
+ export { fetchEntries, fetchOneEntry, getAllContent, getContent, _processContentResult } from './functions/get-content/index.js';
9
9
  export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
10
10
  export { track } from './functions/track/index.js';
11
+ export { fetchBuilderProps } from './functions/fetch-builder-props.js';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-react",
3
3
  "description": "Builder.io SDK for React",
4
- "version": "0.5.5",
4
+ "version": "0.5.7",
5
5
  "files": [
6
6
  "dist"
7
7
  ],
@@ -27,6 +27,14 @@
27
27
  "nx": {
28
28
  "implicitDependencies": [
29
29
  "@builder.io/sdks"
30
- ]
30
+ ],
31
+ "targets": {
32
+ "build": {
33
+ "dependsOn": [
34
+ "^build:react",
35
+ "^build"
36
+ ]
37
+ }
38
+ }
31
39
  }
32
40
  }
@@ -1,7 +0,0 @@
1
- type Target = import('../types/targets').Target;
2
- export declare function ifTarget<A, B>({ targets, doThing, elseThing }: {
3
- targets: Target[];
4
- doThing: () => A;
5
- elseThing?: () => B;
6
- }): A | B;
7
- export {};
@@ -1,10 +0,0 @@
1
- import { TARGET } from '../constants/target.js';
2
- // TODO: babel compile to include certain code only if the target matches
3
- export function ifTarget({ targets, doThing, elseThing }) {
4
- if (TARGET && targets.includes(TARGET)) {
5
- return doThing();
6
- }
7
- else {
8
- return elseThing?.();
9
- }
10
- }