@builder.io/sdk-svelte 0.1.15 → 0.2.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 (53) hide show
  1. package/package/--package.json +1 -1
  2. package/package/CHANGELOG.md +22 -0
  3. package/package/blocks/button/button.svelte +2 -1
  4. package/package/blocks/columns/columns.svelte +5 -2
  5. package/package/blocks/columns/columns.svelte.d.ts +1 -1
  6. package/package/blocks/image/image.svelte +3 -4
  7. package/package/blocks/image/image.svelte.d.ts +1 -1
  8. package/package/blocks/symbol/symbol.svelte +2 -0
  9. package/package/blocks/symbol/symbol.svelte.d.ts +2 -2
  10. package/package/components/render-block/block-styles.svelte +2 -0
  11. package/package/components/render-block/block-styles.svelte.d.ts +2 -2
  12. package/package/components/render-block/render-block.svelte +5 -1
  13. package/package/components/render-block/render-block.svelte.d.ts +2 -2
  14. package/package/components/render-block/render-component.svelte +3 -1
  15. package/package/components/render-block/render-component.svelte.d.ts +2 -2
  16. package/package/components/render-block/render-repeated-block.svelte +2 -0
  17. package/package/components/render-block/render-repeated-block.svelte.d.ts +2 -2
  18. package/package/components/render-blocks.svelte +1 -0
  19. package/package/components/render-blocks.svelte.d.ts +1 -1
  20. package/package/components/render-content/components/render-styles.svelte +1 -0
  21. package/package/components/render-content/components/render-styles.svelte.d.ts +1 -1
  22. package/package/components/render-content/render-content.svelte +5 -3
  23. package/package/components/render-content/render-content.svelte.d.ts +1 -1
  24. package/package/context/types.d.ts +1 -1
  25. package/package/functions/get-content/generate-content-url.js +2 -1
  26. package/package/functions/get-content/generate-content-url.test.js +9 -0
  27. package/package/functions/get-content/index.d.ts +5 -5
  28. package/package/functions/get-content/index.js +19 -6
  29. package/package/functions/get-content/types.d.ts +1 -1
  30. package/package/functions/get-global-this.d.ts +4 -2
  31. package/package/types/api-version.d.ts +1 -0
  32. package/package/types/api-version.js +1 -1
  33. package/package.json +1 -1
  34. package/src/blocks/button/button.svelte +2 -1
  35. package/src/blocks/columns/columns.svelte +25 -16
  36. package/src/blocks/form/form.svelte +15 -8
  37. package/src/blocks/image/image.svelte +2 -5
  38. package/src/blocks/symbol/symbol.svelte +2 -4
  39. package/src/components/render-block/block-styles.svelte +3 -5
  40. package/src/components/render-block/render-block.svelte +8 -10
  41. package/src/components/render-block/render-component.svelte +2 -4
  42. package/src/components/render-block/render-repeated-block.svelte +2 -4
  43. package/src/components/render-blocks.svelte +1 -2
  44. package/src/components/render-content/components/render-styles.svelte +1 -2
  45. package/src/components/render-content/render-content.svelte +34 -38
  46. package/src/context/types.ts +1 -1
  47. package/src/functions/get-content/generate-content-url.test.ts +10 -0
  48. package/src/functions/get-content/generate-content-url.ts +2 -1
  49. package/src/functions/get-content/index.ts +30 -14
  50. package/src/functions/get-content/types.ts +1 -1
  51. package/src/functions/get-global-this.ts +3 -1
  52. package/src/functions/on-change.ts +1 -1
  53. package/src/types/api-version.ts +1 -0
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.1.14",
4
+ "version": "0.1.16",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -1,3 +1,25 @@
1
+ ### 0.2.0
2
+ - Sets the default `apiVersion` to `v3`.
3
+
4
+ In case you feel the need to use our older API Version `v2`, reach out to us at support@builder.io first. But you can override the default by setting `apiVersion` explicitly to `v2` as follows:
5
+
6
+ ```jsx
7
+ <RenderContent apiVersion="v2" />
8
+ ```
9
+
10
+ ```js
11
+ getContent({ apiVersion: "v2" })
12
+ ```
13
+ More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
14
+
15
+ ### 0.1.16
16
+
17
+ - No changes.
18
+
19
+ ### 0.1.15
20
+
21
+ - No changes.
22
+
1
23
  ### 0.1.14
2
24
 
3
25
  - No changes.
@@ -45,7 +45,8 @@ export let openLinkInNewTab;
45
45
  </a>
46
46
  {:else}
47
47
  <button
48
- class="button"
48
+ class={/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
49
+ attributes.class + " button"}
49
50
  {...filterAttrs(attributes, isNonEvent)}
50
51
  use:setAttrs={filterAttrs(attributes, isEvent)}
51
52
  >
@@ -2,10 +2,13 @@
2
2
 
3
3
  <script>import { getContext } from "svelte";
4
4
  import RenderBlocks from "../../components/render-blocks.svelte";
5
+ import "../../types/builder-block";
5
6
  import { getSizesForBreakpoints } from "../../constants/device-sizes";
7
+ import "../../constants/device-sizes";
6
8
  import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
7
9
  import { TARGET } from "../../constants/target.js";
8
10
  import BuilderContext from "../../context/builder.context.js";
11
+ import "../../types/typescript";
9
12
  export let space;
10
13
  export let columns;
11
14
  export let stackColumnsAt;
@@ -29,10 +32,10 @@ function getColumnCssWidth(index) {
29
32
  const subtractWidth = (gutterSize * (cols.length - 1)) / cols.length;
30
33
  return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
31
34
  }
32
- function getTabletStyle({ stackedStyle, desktopStyle }) {
35
+ function getTabletStyle({ stackedStyle, desktopStyle, }) {
33
36
  return stackAt === "tablet" ? stackedStyle : desktopStyle;
34
37
  }
35
- function getMobileStyle({ stackedStyle, desktopStyle }) {
38
+ function getMobileStyle({ stackedStyle, desktopStyle, }) {
36
39
  return stackAt === "never" ? desktopStyle : stackedStyle;
37
40
  }
38
41
  function columnCssVars(index) {
@@ -1,5 +1,4 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderBlock } from "../../types/builder-block";
3
2
  type Column = {
4
3
  blocks: BuilderBlock[];
5
4
  width?: number;
@@ -12,6 +11,7 @@ export interface ColumnProps {
12
11
  stackColumnsAt?: StackColumnsAt;
13
12
  reverseColumnsWhenStacked?: boolean;
14
13
  }
14
+ import { BuilderBlock } from "../../types/builder-block";
15
15
  declare const __propDef: {
16
16
  props: {
17
17
  space: ColumnProps["space"];
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { getSrcSet } from "./image.helpers.js";
3
+ <script>import "../../types/builder-block.js";
4
+ import { getSrcSet } from "./image.helpers.js";
4
5
  export let image;
5
6
  export let src;
6
7
  export let srcset;
@@ -87,9 +88,7 @@ $: aspectRatioCss = () => {
87
88
  {#if aspectRatio && !(builderBlock?.children?.length && fitContent)}
88
89
  <div
89
90
  use:mitosis_styling={{
90
- paddingTop:
91
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
92
- aspectRatio * 100 + "%",
91
+ paddingTop: aspectRatio * 100 + "%",
93
92
  }}
94
93
  class="builder-image-sizer div"
95
94
  />
@@ -1,6 +1,5 @@
1
1
  /// <reference types="react" />
2
2
  import { SvelteComponentTyped } from "svelte";
3
- import type { BuilderBlock } from "../../types/builder-block.js";
4
3
  export interface ImageProps {
5
4
  className?: string;
6
5
  image: string;
@@ -19,6 +18,7 @@ export interface ImageProps {
19
18
  noWebp?: boolean;
20
19
  src?: string;
21
20
  }
21
+ import { BuilderBlock } from "../../types/builder-block.js";
22
22
  declare const __propDef: {
23
23
  props: {
24
24
  image: ImageProps["image"];
@@ -4,6 +4,8 @@
4
4
  import RenderContent from "../../components/render-content/render-content.svelte";
5
5
  import BuilderContext from "../../context/builder.context.js";
6
6
  import { getContent } from "../../functions/get-content/index.js";
7
+ import "../../types/builder-content.js";
8
+ import "../../types/builder-block.js";
7
9
  import { TARGET } from "../../constants/target";
8
10
  const isEvent = (attr) => attr.startsWith("on:");
9
11
  const isNonEvent = (attr) => !attr.startsWith("on:");
@@ -1,6 +1,4 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderContent } from "../../types/builder-content.js";
3
- import type { BuilderBlock } from "../../types/builder-block.js";
4
2
  export interface SymbolInfo {
5
3
  model?: string;
6
4
  entry?: string;
@@ -17,6 +15,8 @@ export interface SymbolProps {
17
15
  attributes?: any;
18
16
  inheritState?: boolean;
19
17
  }
18
+ import { BuilderContent } from "../../types/builder-content.js";
19
+ import { BuilderBlock } from "../../types/builder-block.js";
20
20
  declare const __propDef: {
21
21
  props: {
22
22
  attributes: SymbolProps["attributes"];
@@ -2,9 +2,11 @@
2
2
 
3
3
  <script>import { getMaxWidthQueryForSize, getSizesForBreakpoints, } from "../../constants/device-sizes.js";
4
4
  import { TARGET } from "../../constants/target.js";
5
+ import "../../context/types.js";
5
6
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
6
7
  import { createCssClass } from "../../helpers/css.js";
7
8
  import { checkIsDefined } from "../../helpers/nullable.js";
9
+ import "../../types/builder-block.js";
8
10
  import RenderInlinedStyles from "../render-inlined-styles.svelte";
9
11
  export let block;
10
12
  export let context;
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderContextInterface } from "../../context/types.js";
3
- import type { BuilderBlock } from "../../types/builder-block.js";
4
2
  export type BlockStylesProps = {
5
3
  block: BuilderBlock;
6
4
  context: BuilderContextInterface;
7
5
  };
6
+ import { BuilderContextInterface } from "../../context/types.js";
7
+ import { BuilderBlock } from "../../types/builder-block.js";
8
8
  declare const __propDef: {
9
9
  props: {
10
10
  block: BlockStylesProps["block"];
@@ -1,12 +1,15 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import { getBlockActions } from "../../functions/get-block-actions.js";
3
+ <script>import "../../context/types.js";
4
+ import { getBlockActions } from "../../functions/get-block-actions.js";
4
5
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
5
6
  import { getBlockProperties } from "../../functions/get-block-properties.js";
6
7
  import { getBlockTag } from "../../functions/get-block-tag.js";
7
8
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
9
+ import "../../types/builder-block.js";
8
10
  import BlockStyles from "./block-styles.svelte";
9
11
  import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
12
+ import "./render-component.svelte";
10
13
  import RenderRepeatedBlock from "./render-repeated-block.svelte";
11
14
  import { TARGET } from "../../constants/target.js";
12
15
  import { extractTextStyles } from "../../functions/extract-text-styles.js";
@@ -136,6 +139,7 @@ $: childrenContext = () => {
136
139
  };
137
140
  return {
138
141
  apiKey: context.apiKey,
142
+ apiVersion: context.apiVersion,
139
143
  state: context.state,
140
144
  content: context.content,
141
145
  context: context.context,
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderContextInterface } from "../../context/types.js";
3
- import type { BuilderBlock } from "../../types/builder-block.js";
4
2
  export type RenderBlockProps = {
5
3
  block: BuilderBlock;
6
4
  context: BuilderContextInterface;
7
5
  };
6
+ import { BuilderContextInterface } from "../../context/types.js";
7
+ import { BuilderBlock } from "../../types/builder-block.js";
8
8
  declare const __propDef: {
9
9
  props: {
10
10
  block: RenderBlockProps["block"];
@@ -1,7 +1,9 @@
1
1
  <script context="module"></script>
2
2
 
3
- <script>import BlockStyles from "./block-styles.svelte";
3
+ <script>import "../../types/builder-block.js";
4
+ import BlockStyles from "./block-styles.svelte";
4
5
  import RenderBlock from "./render-block.svelte";
6
+ import "../../context/types.js";
5
7
  export let componentRef;
6
8
  export let componentOptions;
7
9
  export let blockChildren;
@@ -1,6 +1,4 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderBlock } from "../../types/builder-block.js";
3
- import type { BuilderContextInterface } from "../../context/types.js";
4
2
  type ComponentOptions = {
5
3
  [index: string]: any;
6
4
  attributes?: {
@@ -13,6 +11,8 @@ export interface RenderComponentProps {
13
11
  blockChildren: BuilderBlock[];
14
12
  context: BuilderContextInterface;
15
13
  }
14
+ import { BuilderBlock } from "../../types/builder-block.js";
15
+ import { BuilderContextInterface } from "../../context/types.js";
16
16
  declare const __propDef: {
17
17
  props: {
18
18
  componentRef: RenderComponentProps["componentRef"];
@@ -11,6 +11,8 @@
11
11
 
12
12
  <script>import { setContext } from "svelte";
13
13
  import BuilderContext from "../../context/builder.context.js";
14
+ import "../../context/types.js";
15
+ import "../../types/builder-block";
14
16
  import RenderBlock from "./render-block.svelte";
15
17
  export let block;
16
18
  export let repeatContext;
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderContextInterface } from "../../context/types.js";
3
- import type { BuilderBlock } from "../../types/builder-block";
4
2
  type Props = {
5
3
  block: BuilderBlock;
6
4
  repeatContext: BuilderContextInterface;
7
5
  };
6
+ import { BuilderContextInterface } from "../../context/types.js";
7
+ import { BuilderBlock } from "../../types/builder-block";
8
8
  declare const __propDef: {
9
9
  props: {
10
10
  block: Props["block"];
@@ -3,6 +3,7 @@
3
3
  <script>import { getContext } from "svelte";
4
4
  import BuilderContext from "../context/builder.context.js";
5
5
  import { isEditing } from "../functions/is-editing.js";
6
+ import "../types/builder-block.js";
6
7
  import BlockStyles from "./render-block/block-styles.svelte";
7
8
  import RenderBlock from "./render-block/render-block.svelte";
8
9
  export let blocks;
@@ -1,11 +1,11 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { BuilderBlock } from "../types/builder-block.js";
3
2
  export type RenderBlockProps = {
4
3
  blocks?: BuilderBlock[];
5
4
  parent?: string;
6
5
  path?: string;
7
6
  styleProp?: Record<string, any>;
8
7
  };
8
+ import { BuilderBlock } from "../types/builder-block.js";
9
9
  declare const __propDef: {
10
10
  props: {
11
11
  blocks: RenderBlockProps["blocks"];
@@ -1,6 +1,7 @@
1
1
  <script context="module"></script>
2
2
 
3
3
  <script>import RenderInlinedStyles from "../../render-inlined-styles.svelte";
4
+ import "./render-styles.helpers";
4
5
  import { getCss } from "./render-styles.helpers";
5
6
  import { getFontCss } from "./render-styles.helpers";
6
7
  export let cssCode;
@@ -1,10 +1,10 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { CustomFont } from "./render-styles.helpers";
3
2
  interface Props {
4
3
  cssCode?: string;
5
4
  customFonts?: CustomFont[];
6
5
  contentId?: string;
7
6
  }
7
+ import { CustomFont } from "./render-styles.helpers";
8
8
  declare const __propDef: {
9
9
  props: {
10
10
  cssCode: Props["cssCode"];
@@ -1,7 +1,6 @@
1
- <script context="module"></script>
2
-
3
1
  <script>import { onDestroy, onMount, setContext } from "svelte";
4
2
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
3
+ import "../../context/types.js";
5
4
  import { evaluate } from "../../functions/evaluate.js";
6
5
  import { getContent } from "../../functions/get-content/index.js";
7
6
  import { fetch } from "../../functions/get-fetch.js";
@@ -10,12 +9,15 @@ import { isEditing } from "../../functions/is-editing.js";
10
9
  import { isPreviewing } from "../../functions/is-previewing.js";
11
10
  import { components, createRegisterComponentMessage, } from "../../functions/register-component.js";
12
11
  import { _track } from "../../functions/track/index.js";
12
+ import "../../types/builder-content.js";
13
+ import "../../types/typescript.js";
13
14
  import RenderBlocks from "../render-blocks.svelte";
14
15
  import RenderContentStyles from "./components/render-styles.svelte";
15
16
  import builderContext from "../../context/builder.context.js";
16
17
  import { registerInsertMenu, setupBrowserForEditing, } from "../../scripts/init-editing.js";
17
18
  import { checkIsDefined } from "../../helpers/nullable.js";
18
19
  import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
20
+ import "./render-content.types.js";
19
21
  import { getContentInitialValue, getContextStateInitialValue, } from "./render-content.helpers.js";
20
22
  import { TARGET } from "../../constants/target.js";
21
23
  export let content;
@@ -138,7 +140,7 @@ function handleRequest({ url, key }) {
138
140
  setContextState(newState);
139
141
  })
140
142
  .catch((err) => {
141
- console.log("error fetching dynamic data", url, err);
143
+ console.error("error fetching dynamic data", url, err);
142
144
  });
143
145
  }
144
146
  function runHttpRequests() {
@@ -1,5 +1,5 @@
1
1
  import { SvelteComponentTyped } from "svelte";
2
- import type { RenderContentProps } from "./render-content.types.js";
2
+ import { RenderContentProps } from "./render-content.types.js";
3
3
  declare const __propDef: {
4
4
  props: {
5
5
  content: RenderContentProps["content"];
@@ -14,7 +14,7 @@ export interface BuilderContextInterface {
14
14
  state: BuilderRenderState;
15
15
  setState?: (state: BuilderRenderState) => void;
16
16
  apiKey: string | null;
17
- apiVersion?: ApiVersion;
17
+ apiVersion: ApiVersion | undefined;
18
18
  registeredComponents: RegisteredComponents;
19
19
  inheritedStyles: Record<string, unknown>;
20
20
  }
@@ -1,7 +1,8 @@
1
1
  import { flatten } from '../../helpers/flatten.js';
2
2
  import { getBuilderSearchParamsFromWindow, normalizeSearchParams, } from '../get-builder-search-params/index.js';
3
+ import { DEFAULT_API_VERSION } from '../../types/api-version';
3
4
  export const generateContentUrl = (options) => {
4
- const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion = 'v2', } = options;
5
+ const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion = DEFAULT_API_VERSION, } = options;
5
6
  if (!apiKey) {
6
7
  throw new Error('Missing API key');
7
8
  }
@@ -28,6 +28,15 @@ describe('Generate Content URL', () => {
28
28
  });
29
29
  expect(output).toMatchSnapshot();
30
30
  });
31
+ test('generate content url with apiVersion as default', () => {
32
+ const output = generateContentUrl({
33
+ apiKey: testKey,
34
+ model: testModel,
35
+ query: { id: testId },
36
+ options,
37
+ });
38
+ expect(output).toMatchSnapshot();
39
+ });
31
40
  test('generate content url with apiVersion as v2', () => {
32
41
  const output = generateContentUrl({
33
42
  apiKey: testKey,
@@ -1,11 +1,11 @@
1
1
  import type { BuilderContent } from '../../types/builder-content.js';
2
2
  import type { GetContentOptions } from './types.js';
3
3
  export declare function getContent(options: GetContentOptions): Promise<BuilderContent | null>;
4
- /**
5
- * TO-DO: Handle error responses.
6
- */
7
- interface ContentResponse {
4
+ type ContentResponse = {
8
5
  results: BuilderContent[];
9
- }
6
+ } | {
7
+ status: number;
8
+ message: string;
9
+ };
10
10
  export declare function getAllContent(options: GetContentOptions): Promise<ContentResponse>;
11
11
  export {};
@@ -2,19 +2,32 @@ import { fetch } from '../get-fetch.js';
2
2
  import { handleABTesting } from './ab-testing.js';
3
3
  import { generateContentUrl } from './generate-content-url.js';
4
4
  export async function getContent(options) {
5
- return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
5
+ const allContent = await getAllContent({ ...options, limit: 1 });
6
+ if ('results' in allContent) {
7
+ return allContent?.results[0] || null;
8
+ }
9
+ return null;
6
10
  }
7
11
  export async function getAllContent(options) {
8
12
  const url = generateContentUrl(options);
9
13
  const res = await fetch(url.href);
10
14
  const content = await res.json();
15
+ if ('status' in content && !('results' in content)) {
16
+ console.error('[Builder.io]: Error fetching data. ', content, options);
17
+ return content;
18
+ }
11
19
  const canTrack = options.canTrack !== false;
12
- if (canTrack &&
13
- // This makes sure we have a non-error response with the results array.
14
- Array.isArray(content.results)) {
15
- for (const item of content.results) {
16
- await handleABTesting({ item, canTrack });
20
+ try {
21
+ if (canTrack &&
22
+ // This makes sure we have a non-error response with the results array.
23
+ Array.isArray(content.results)) {
24
+ for (const item of content.results) {
25
+ await handleABTesting({ item, canTrack });
26
+ }
17
27
  }
18
28
  }
29
+ catch (e) {
30
+ console.error('[Builder.io]: Could not setup A/B testing. ', e);
31
+ }
19
32
  return content;
20
33
  }
@@ -39,7 +39,7 @@ export interface GetContentOptions {
39
39
  /**
40
40
  * If provided, sets the Builder API version used to fetch content.
41
41
  *
42
- * Defaults to `v2`.
42
+ * Defaults to `v3`.
43
43
  */
44
44
  apiVersion?: 'v2' | 'v3';
45
45
  }
@@ -1,2 +1,4 @@
1
- /// <reference types="@types/node" />
2
- export declare function getGlobalThis(): typeof global;
1
+ /// <reference types="node" />
2
+ type Global = typeof global | typeof window | typeof self | typeof globalThis;
3
+ export declare function getGlobalThis(): Global;
4
+ export {};
@@ -1 +1,2 @@
1
1
  export type ApiVersion = 'v2' | 'v3';
2
+ export declare const DEFAULT_API_VERSION: ApiVersion;
@@ -1 +1 @@
1
- export {};
1
+ export const DEFAULT_API_VERSION = 'v3';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.1.15",
4
+ "version": "0.2.0",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "package",
@@ -55,7 +55,8 @@
55
55
  </a>
56
56
  {:else}
57
57
  <button
58
- class="button"
58
+ class={/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
59
+ attributes.class + " button"}
59
60
  {...filterAttrs(attributes, isNonEvent)}
60
61
  use:setAttrs={filterAttrs(attributes, isEvent)}
61
62
  >
@@ -1,10 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderBlock } from "../../types/builder-block";
3
-
4
- import type { SizeName } from "../../constants/device-sizes";
5
-
6
- import type { Dictionary } from "../../types/typescript";
7
-
8
2
  type Column = {
9
3
  blocks: BuilderBlock[];
10
4
  width?: number;
@@ -31,10 +25,13 @@
31
25
  import { getContext } from "svelte";
32
26
 
33
27
  import RenderBlocks from "../../components/render-blocks.svelte";
28
+ import { BuilderBlock } from "../../types/builder-block";
34
29
  import { getSizesForBreakpoints } from "../../constants/device-sizes";
30
+ import { SizeName } from "../../constants/device-sizes";
35
31
  import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
36
32
  import { TARGET } from "../../constants/target.js";
37
33
  import BuilderContext from "../../context/builder.context.js";
34
+ import { Dictionary } from "../../types/typescript";
38
35
 
39
36
  export let space: ColumnProps["space"];
40
37
  export let columns: ColumnProps["columns"];
@@ -54,25 +51,37 @@
54
51
 
55
52
  let builderContext = getContext(BuilderContext.key);
56
53
 
57
- function getWidth(index) {
54
+ function getWidth(index: number) {
58
55
  return cols[index]?.width || 100 / cols.length;
59
56
  }
60
- function getColumnCssWidth(index) {
57
+ function getColumnCssWidth(index: number) {
61
58
  const subtractWidth = (gutterSize * (cols.length - 1)) / cols.length;
62
59
  return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
63
60
  }
64
- function getTabletStyle({ stackedStyle, desktopStyle }) {
61
+ function getTabletStyle({
62
+ stackedStyle,
63
+ desktopStyle,
64
+ }: {
65
+ stackedStyle: CSSVal;
66
+ desktopStyle: CSSVal;
67
+ }) {
65
68
  return stackAt === "tablet" ? stackedStyle : desktopStyle;
66
69
  }
67
- function getMobileStyle({ stackedStyle, desktopStyle }) {
70
+ function getMobileStyle({
71
+ stackedStyle,
72
+ desktopStyle,
73
+ }: {
74
+ stackedStyle: CSSVal;
75
+ desktopStyle: CSSVal;
76
+ }) {
68
77
  return stackAt === "never" ? desktopStyle : stackedStyle;
69
78
  }
70
- function columnCssVars(index) {
79
+ function columnCssVars(index: number) {
71
80
  const gutter = index === 0 ? 0 : gutterSize;
72
81
  if (TARGET === "reactNative") {
73
82
  return {
74
83
  marginLeft: stackColumnsAt === "never" ? gutter : 0,
75
- };
84
+ } as any as Dictionary<string>;
76
85
  }
77
86
  const width = getColumnCssWidth(index);
78
87
  const gutterPixels = `${gutterSize}px`;
@@ -97,9 +106,9 @@
97
106
  stackedStyle: mobileMarginLeft,
98
107
  desktopStyle: gutterPixels,
99
108
  }),
100
- };
109
+ } as any as Dictionary<string>;
101
110
  }
102
- function getWidthForBreakpointSize(size) {
111
+ function getWidthForBreakpointSize(size: SizeName) {
103
112
  const breakpointSizes = getSizesForBreakpoints(
104
113
  builderContext.content?.meta?.breakpoints || {}
105
114
  );
@@ -109,7 +118,7 @@
109
118
  if (TARGET === "reactNative") {
110
119
  return {
111
120
  flexDirection: flexDir,
112
- };
121
+ } as Dictionary<string>;
113
122
  }
114
123
  return {
115
124
  "--flex-dir": flexDir,
@@ -117,7 +126,7 @@
117
126
  stackedStyle: flexDir,
118
127
  desktopStyle: "row",
119
128
  }),
120
- };
129
+ } as Dictionary<string>;
121
130
  };
122
131
  $: columnsStyles = () => {
123
132
  return `
@@ -114,7 +114,11 @@
114
114
 
115
115
  let builderContext = getContext(BuilderContext.key);
116
116
 
117
- function onSubmit(event) {
117
+ function onSubmit(
118
+ event: Event & {
119
+ currentTarget: HTMLFormElement;
120
+ }
121
+ ) {
118
122
  const sendWithJs = sendWithJs || sendSubmissionsTo === "email";
119
123
  if (sendSubmissionsTo === "zapier") {
120
124
  event.preventDefault();
@@ -126,17 +130,20 @@
126
130
  event.preventDefault();
127
131
  const el = event.currentTarget;
128
132
  const headers = customHeaders || {};
129
- let body;
133
+ let body: any;
130
134
  const formData = new FormData(el);
131
135
 
132
136
  // TODO: maybe support null
133
- const formPairs = Array.from(
137
+ const formPairs: {
138
+ key: string;
139
+ value: File | boolean | number | string | FileList;
140
+ }[] = Array.from(
134
141
  event.currentTarget.querySelectorAll("input,select,textarea")
135
142
  )
136
- .filter((el) => !!el.name)
143
+ .filter((el) => !!(el as HTMLInputElement).name)
137
144
  .map((el) => {
138
- let value;
139
- const key = el.name;
145
+ let value: any;
146
+ const key = (el as HTMLImageElement).name;
140
147
  if (el instanceof HTMLInputElement) {
141
148
  if (el.type === "radio") {
142
149
  if (el.checked) {
@@ -160,7 +167,7 @@
160
167
  value = el.value;
161
168
  }
162
169
  } else {
163
- value = el.value;
170
+ value = (el as HTMLInputElement).value;
164
171
  }
165
172
  return {
166
173
  key,
@@ -222,7 +229,7 @@
222
229
  fetch(
223
230
  sendSubmissionsTo === "email"
224
231
  ? formUrl
225
- : action /* TODO: throw error if no action URL */,
232
+ : action! /* TODO: throw error if no action URL */,
226
233
  {
227
234
  body,
228
235
  headers,
@@ -1,6 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderBlock } from "../../types/builder-block.js";
3
-
4
2
  export interface ImageProps {
5
3
  className?: string;
6
4
  image: string;
@@ -22,6 +20,7 @@
22
20
  </script>
23
21
 
24
22
  <script lang="ts">
23
+ import { BuilderBlock } from "../../types/builder-block.js";
25
24
  import { getSrcSet } from "./image.helpers.js";
26
25
 
27
26
  export let image: ImageProps["image"];
@@ -111,9 +110,7 @@
111
110
  {#if aspectRatio && !(builderBlock?.children?.length && fitContent)}
112
111
  <div
113
112
  use:mitosis_styling={{
114
- paddingTop:
115
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
116
- aspectRatio * 100 + "%",
113
+ paddingTop: aspectRatio * 100 + "%",
117
114
  }}
118
115
  class="builder-image-sizer div"
119
116
  />
@@ -1,8 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderContent } from "../../types/builder-content.js";
3
-
4
- import type { BuilderBlock } from "../../types/builder-block.js";
5
-
6
2
  export interface SymbolInfo {
7
3
  model?: string;
8
4
  entry?: string;
@@ -28,6 +24,8 @@
28
24
  import RenderContent from "../../components/render-content/render-content.svelte";
29
25
  import BuilderContext from "../../context/builder.context.js";
30
26
  import { getContent } from "../../functions/get-content/index.js";
27
+ import { BuilderContent } from "../../types/builder-content.js";
28
+ import { BuilderBlock } from "../../types/builder-block.js";
31
29
  import { TARGET } from "../../constants/target";
32
30
 
33
31
  const isEvent = (attr) => attr.startsWith("on:");
@@ -1,8 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderContextInterface } from "../../context/types.js";
3
-
4
- import type { BuilderBlock } from "../../types/builder-block.js";
5
-
6
2
  export type BlockStylesProps = {
7
3
  block: BuilderBlock;
8
4
  context: BuilderContextInterface;
@@ -15,9 +11,11 @@
15
11
  getSizesForBreakpoints,
16
12
  } from "../../constants/device-sizes.js";
17
13
  import { TARGET } from "../../constants/target.js";
14
+ import { BuilderContextInterface } from "../../context/types.js";
18
15
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
19
16
  import { createCssClass } from "../../helpers/css.js";
20
17
  import { checkIsDefined } from "../../helpers/nullable.js";
18
+ import { BuilderBlock } from "../../types/builder-block.js";
21
19
  import RenderInlinedStyles from "../render-inlined-styles.svelte";
22
20
 
23
21
  export let block: BlockStylesProps["block"];
@@ -50,7 +48,7 @@
50
48
  const largeStyles = styles?.large;
51
49
  const mediumStyles = styles?.medium;
52
50
  const smallStyles = styles?.small;
53
- const className = useBlock().id;
51
+ const className = useBlock().id!;
54
52
  const largeStylesClass = largeStyles
55
53
  ? createCssClass({
56
54
  className,
@@ -1,13 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type {
3
- BuilderContextInterface,
4
- BuilderRenderState,
5
- } from "../../context/types.js";
6
-
7
- import type { BuilderBlock } from "../../types/builder-block.js";
8
-
9
- import type { RenderComponentProps } from "./render-component";
10
-
11
2
  export type RenderBlockProps = {
12
3
  block: BuilderBlock;
13
4
  context: BuilderContextInterface;
@@ -15,17 +6,23 @@
15
6
  </script>
16
7
 
17
8
  <script lang="ts">
9
+ import {
10
+ BuilderContextInterface,
11
+ BuilderRenderState,
12
+ } from "../../context/types.js";
18
13
  import { getBlockActions } from "../../functions/get-block-actions.js";
19
14
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
20
15
  import { getBlockProperties } from "../../functions/get-block-properties.js";
21
16
  import { getBlockTag } from "../../functions/get-block-tag.js";
22
17
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
18
+ import { BuilderBlock } from "../../types/builder-block.js";
23
19
  import BlockStyles from "./block-styles.svelte";
24
20
  import {
25
21
  getComponent,
26
22
  getRepeatItemData,
27
23
  isEmptyHtmlElement,
28
24
  } from "./render-block.helpers.js";
25
+ import { RenderComponentProps } from "./render-component.svelte";
29
26
  import RenderRepeatedBlock from "./render-repeated-block.svelte";
30
27
  import { TARGET } from "../../constants/target.js";
31
28
  import { extractTextStyles } from "../../functions/extract-text-styles.js";
@@ -84,7 +81,7 @@
84
81
  return context.state;
85
82
  }
86
83
  const useState = new Proxy(context.state, {
87
- set: (obj, prop, value) => {
84
+ set: (obj, prop: keyof BuilderRenderState, value) => {
88
85
  // set the value on the state object, so that the event handler instantly gets the update.
89
86
  obj[prop] = value;
90
87
 
@@ -165,6 +162,7 @@
165
162
  };
166
163
  return {
167
164
  apiKey: context.apiKey,
165
+ apiVersion: context.apiVersion,
168
166
  state: context.state,
169
167
  content: context.content,
170
168
  context: context.context,
@@ -1,8 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderBlock } from "../../types/builder-block.js";
3
-
4
- import type { BuilderContextInterface } from "../../context/types.js";
5
-
6
2
  type ComponentOptions = {
7
3
  [index: string]: any;
8
4
  attributes?: {
@@ -19,8 +15,10 @@
19
15
  </script>
20
16
 
21
17
  <script lang="ts">
18
+ import { BuilderBlock } from "../../types/builder-block.js";
22
19
  import BlockStyles from "./block-styles.svelte";
23
20
  import RenderBlock from "./render-block.svelte";
21
+ import { BuilderContextInterface } from "../../context/types.js";
24
22
 
25
23
  export let componentRef: RenderComponentProps["componentRef"];
26
24
  export let componentOptions: RenderComponentProps["componentOptions"];
@@ -1,8 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderContextInterface } from "../../context/types.js";
3
-
4
- import type { BuilderBlock } from "../../types/builder-block";
5
-
6
2
  type Props = {
7
3
  block: BuilderBlock;
8
4
  repeatContext: BuilderContextInterface;
@@ -23,6 +19,8 @@
23
19
  import { setContext } from "svelte";
24
20
 
25
21
  import BuilderContext from "../../context/builder.context.js";
22
+ import { BuilderContextInterface } from "../../context/types.js";
23
+ import { BuilderBlock } from "../../types/builder-block";
26
24
  import RenderBlock from "./render-block.svelte";
27
25
 
28
26
  export let block: Props["block"];
@@ -1,6 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { BuilderBlock } from "../types/builder-block.js";
3
-
4
2
  export type RenderBlockProps = {
5
3
  blocks?: BuilderBlock[];
6
4
  parent?: string;
@@ -14,6 +12,7 @@
14
12
 
15
13
  import BuilderContext from "../context/builder.context.js";
16
14
  import { isEditing } from "../functions/is-editing.js";
15
+ import { BuilderBlock } from "../types/builder-block.js";
17
16
  import BlockStyles from "./render-block/block-styles.svelte";
18
17
  import RenderBlock from "./render-block/render-block.svelte";
19
18
 
@@ -1,6 +1,4 @@
1
1
  <script context="module" lang="ts">
2
- import type { CustomFont } from "./render-styles.helpers";
3
-
4
2
  interface Props {
5
3
  cssCode?: string;
6
4
  customFonts?: CustomFont[];
@@ -10,6 +8,7 @@
10
8
 
11
9
  <script lang="ts">
12
10
  import RenderInlinedStyles from "../../render-inlined-styles.svelte";
11
+ import { CustomFont } from "./render-styles.helpers";
13
12
  import { getCss } from "./render-styles.helpers";
14
13
  import { getFontCss } from "./render-styles.helpers";
15
14
 
@@ -1,27 +1,12 @@
1
- <script context="module" lang="ts">
2
- import type {
3
- BuilderRenderState,
4
- RegisteredComponent,
5
- RegisteredComponents,
6
- } from "../../context/types.js";
7
-
8
- import type {
9
- Breakpoints,
10
- BuilderContent,
11
- } from "../../types/builder-content.js";
12
-
13
- import type { Nullable } from "../../types/typescript.js";
14
-
15
- import type {
16
- RenderContentProps,
17
- BuilderComponentStateChange,
18
- } from "./render-content.types.js";
19
- </script>
20
-
21
1
  <script lang="ts">
22
2
  import { onDestroy, onMount, setContext } from "svelte";
23
3
 
24
4
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
5
+ import {
6
+ BuilderRenderState,
7
+ RegisteredComponent,
8
+ RegisteredComponents,
9
+ } from "../../context/types.js";
25
10
  import { evaluate } from "../../functions/evaluate.js";
26
11
  import { getContent } from "../../functions/get-content/index.js";
27
12
  import { fetch } from "../../functions/get-fetch.js";
@@ -33,6 +18,8 @@
33
18
  createRegisterComponentMessage,
34
19
  } from "../../functions/register-component.js";
35
20
  import { _track } from "../../functions/track/index.js";
21
+ import { Breakpoints, BuilderContent } from "../../types/builder-content.js";
22
+ import { Nullable } from "../../types/typescript.js";
36
23
  import RenderBlocks from "../render-blocks.svelte";
37
24
  import RenderContentStyles from "./components/render-styles.svelte";
38
25
  import builderContext from "../../context/builder.context.js";
@@ -42,6 +29,10 @@
42
29
  } from "../../scripts/init-editing.js";
43
30
  import { checkIsDefined } from "../../helpers/nullable.js";
44
31
  import { getInteractionPropertiesForEvent } from "../../functions/track/interaction.js";
32
+ import {
33
+ RenderContentProps,
34
+ BuilderComponentStateChange,
35
+ } from "./render-content.types.js";
45
36
  import {
46
37
  getContentInitialValue,
47
38
  getContextStateInitialValue,
@@ -59,7 +50,7 @@
59
50
  export let includeRefs: RenderContentProps["includeRefs"];
60
51
  export let apiVersion: RenderContentProps["apiVersion"];
61
52
 
62
- function mergeNewContent(newContent) {
53
+ function mergeNewContent(newContent: BuilderContent) {
63
54
  useContent = {
64
55
  ...useContent,
65
56
  ...newContent,
@@ -75,7 +66,7 @@
75
66
  },
76
67
  };
77
68
  }
78
- function setBreakpoints(breakpoints) {
69
+ function setBreakpoints(breakpoints: Breakpoints) {
79
70
  useContent = {
80
71
  ...useContent,
81
72
  meta: {
@@ -84,10 +75,10 @@
84
75
  },
85
76
  };
86
77
  }
87
- function setContextState(newState) {
78
+ function setContextState(newState: BuilderRenderState) {
88
79
  contentState = newState;
89
80
  }
90
- function processMessage(event) {
81
+ function processMessage(event: MessageEvent) {
91
82
  const { data } = event;
92
83
  if (data) {
93
84
  switch (data.type) {
@@ -136,7 +127,7 @@
136
127
  });
137
128
  }
138
129
  }
139
- function onClick(event) {
130
+ function onClick(event: any) {
140
131
  if (useContent) {
141
132
  const variationId = useContent?.testVariationId;
142
133
  const contentId = useContent?.id;
@@ -154,7 +145,7 @@
154
145
  clicked = true;
155
146
  }
156
147
  }
157
- function evalExpression(expression) {
148
+ function evalExpression(expression: string) {
158
149
  return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
159
150
  evaluate({
160
151
  code: group,
@@ -163,7 +154,7 @@
163
154
  })
164
155
  );
165
156
  }
166
- function handleRequest({ url, key }) {
157
+ function handleRequest({ url, key }: { key: string; url: string }) {
167
158
  fetch(url)
168
159
  .then((response) => response.json())
169
160
  .then((json) => {
@@ -174,11 +165,13 @@
174
165
  setContextState(newState);
175
166
  })
176
167
  .catch((err) => {
177
- console.log("error fetching dynamic data", url, err);
168
+ console.error("error fetching dynamic data", url, err);
178
169
  });
179
170
  }
180
171
  function runHttpRequests() {
181
- const requests = useContent?.data?.httpRequests ?? {};
172
+ const requests: {
173
+ [key: string]: string;
174
+ } = useContent?.data?.httpRequests ?? {};
182
175
  Object.entries(requests).forEach(([key, url]) => {
183
176
  if (url && (!httpReqsData[key] || isEditing())) {
184
177
  const evaluatedUrl = evalExpression(url);
@@ -192,14 +185,17 @@
192
185
  function emitStateUpdate() {
193
186
  if (isEditing()) {
194
187
  window.dispatchEvent(
195
- new CustomEvent("builder:component:stateChange", {
196
- detail: {
197
- state: contentState,
198
- ref: {
199
- name: model,
188
+ new CustomEvent<BuilderComponentStateChange>(
189
+ "builder:component:stateChange",
190
+ {
191
+ detail: {
192
+ state: contentState,
193
+ ref: {
194
+ name: model,
195
+ },
200
196
  },
201
- },
202
- })
197
+ }
198
+ )
203
199
  );
204
200
  }
205
201
  }
@@ -233,7 +229,7 @@
233
229
  ...acc,
234
230
  [curr.name]: curr,
235
231
  }),
236
- {}
232
+ {} as RegisteredComponents
237
233
  );
238
234
  let httpReqsData = {};
239
235
  let clicked = false;
@@ -260,7 +256,7 @@
260
256
  }
261
257
  : {}),
262
258
  });
263
- Object.values(allRegisteredComponents).forEach(
259
+ Object.values<RegisteredComponent>(allRegisteredComponents).forEach(
264
260
  (registeredComponent) => {
265
261
  const message = createRegisterComponentMessage(registeredComponent);
266
262
  window.parent?.postMessage(message, "*");
@@ -19,7 +19,7 @@ export interface BuilderContextInterface {
19
19
  state: BuilderRenderState;
20
20
  setState?: (state: BuilderRenderState) => void;
21
21
  apiKey: string | null;
22
- apiVersion?: ApiVersion;
22
+ apiVersion: ApiVersion | undefined;
23
23
  registeredComponents: RegisteredComponents;
24
24
  // Used to recursively store all CSS coming from a parent that would apply to a Text block
25
25
  inheritedStyles: Record<string, unknown>;
@@ -35,6 +35,16 @@ describe('Generate Content URL', () => {
35
35
  expect(output).toMatchSnapshot();
36
36
  });
37
37
 
38
+ test('generate content url with apiVersion as default', () => {
39
+ const output = generateContentUrl({
40
+ apiKey: testKey,
41
+ model: testModel,
42
+ query: { id: testId },
43
+ options,
44
+ });
45
+ expect(output).toMatchSnapshot();
46
+ });
47
+
38
48
  test('generate content url with apiVersion as v2', () => {
39
49
  const output = generateContentUrl({
40
50
  apiKey: testKey,
@@ -4,6 +4,7 @@ import {
4
4
  normalizeSearchParams,
5
5
  } from '../get-builder-search-params/index.js';
6
6
  import type { GetContentOptions } from './types.js';
7
+ import { DEFAULT_API_VERSION } from '../../types/api-version';
7
8
 
8
9
  export const generateContentUrl = (options: GetContentOptions): URL => {
9
10
  const {
@@ -15,7 +16,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
15
16
  apiKey,
16
17
  includeRefs = true,
17
18
  locale,
18
- apiVersion = 'v2',
19
+ apiVersion = DEFAULT_API_VERSION,
19
20
  } = options;
20
21
 
21
22
  if (!apiKey) {
@@ -7,16 +7,23 @@ import type { GetContentOptions } from './types.js';
7
7
  export async function getContent(
8
8
  options: GetContentOptions
9
9
  ): Promise<BuilderContent | null> {
10
- return (await getAllContent({ ...options, limit: 1 })).results[0] || null;
11
- }
10
+ const allContent = await getAllContent({ ...options, limit: 1 });
11
+ if ('results' in allContent) {
12
+ return allContent?.results[0] || null;
13
+ }
12
14
 
13
- /**
14
- * TO-DO: Handle error responses.
15
- */
16
- interface ContentResponse {
17
- results: BuilderContent[];
15
+ return null;
18
16
  }
19
17
 
18
+ type ContentResponse =
19
+ | {
20
+ results: BuilderContent[];
21
+ }
22
+ | {
23
+ status: number;
24
+ message: string;
25
+ };
26
+
20
27
  export async function getAllContent(
21
28
  options: GetContentOptions
22
29
  ): Promise<ContentResponse> {
@@ -25,15 +32,24 @@ export async function getAllContent(
25
32
  const res = await fetch(url.href);
26
33
  const content = await (res.json() as Promise<ContentResponse>);
27
34
 
35
+ if ('status' in content && !('results' in content)) {
36
+ console.error('[Builder.io]: Error fetching data. ', content, options);
37
+ return content;
38
+ }
39
+
28
40
  const canTrack = options.canTrack !== false;
29
- if (
30
- canTrack &&
31
- // This makes sure we have a non-error response with the results array.
32
- Array.isArray(content.results)
33
- ) {
34
- for (const item of content.results) {
35
- await handleABTesting({ item, canTrack });
41
+ try {
42
+ if (
43
+ canTrack &&
44
+ // This makes sure we have a non-error response with the results array.
45
+ Array.isArray(content.results)
46
+ ) {
47
+ for (const item of content.results) {
48
+ await handleABTesting({ item, canTrack });
49
+ }
36
50
  }
51
+ } catch (e) {
52
+ console.error('[Builder.io]: Could not setup A/B testing. ', e);
37
53
  }
38
54
 
39
55
  return content;
@@ -47,7 +47,7 @@ export interface GetContentOptions {
47
47
  /**
48
48
  * If provided, sets the Builder API version used to fetch content.
49
49
  *
50
- * Defaults to `v2`.
50
+ * Defaults to `v3`.
51
51
  */
52
52
  apiVersion?: 'v2' | 'v3';
53
53
  }
@@ -1,4 +1,6 @@
1
- export function getGlobalThis(): typeof global {
1
+ type Global = typeof global | typeof window | typeof self | typeof globalThis;
2
+
3
+ export function getGlobalThis(): Global {
2
4
  if (typeof globalThis !== 'undefined') {
3
5
  return globalThis;
4
6
  }
@@ -13,7 +13,7 @@ export function onChange<T extends object = any>(obj: T, cb: () => void): T {
13
13
  }
14
14
  const value = Reflect.get(target, key);
15
15
  if (value && typeof value === 'object') {
16
- if (value[onChangeProxySymbol]) {
16
+ if ((value as any)[onChangeProxySymbol]) {
17
17
  return value;
18
18
  }
19
19
  return onChange(value, cb);
@@ -1 +1,2 @@
1
1
  export type ApiVersion = 'v2' | 'v3';
2
+ export const DEFAULT_API_VERSION: ApiVersion = 'v3';