@builder.io/sdk-qwik 0.2.1 → 0.2.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.
@@ -302,8 +302,14 @@ function getBlockComponentOptions(block) {
302
302
  function transformBlockProperties(properties) {
303
303
  return properties;
304
304
  }
305
+ const extractRelevantRootBlockProperties = (block) => {
306
+ return {
307
+ href: block.href
308
+ };
309
+ };
305
310
  function getBlockProperties(block) {
306
311
  const properties = {
312
+ ...extractRelevantRootBlockProperties(block),
307
313
  ...block.properties,
308
314
  "builder-id": block.id,
309
315
  style: getStyleAttribute(block.style),
@@ -449,7 +455,8 @@ const RenderRepeatedBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qw
449
455
  context: props.repeatContext.context,
450
456
  apiKey: props.repeatContext.apiKey,
451
457
  registeredComponents: props.repeatContext.registeredComponents,
452
- inheritedStyles: props.repeatContext.inheritedStyles
458
+ inheritedStyles: props.repeatContext.inheritedStyles,
459
+ apiVersion: props.repeatContext.apiVersion
453
460
  }));
454
461
  return /* @__PURE__ */ qwik._jsxC(RenderBlock, {
455
462
  get block() {
@@ -506,9 +513,9 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
506
513
  ]));
507
514
  const canShowBlock = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
508
515
  const [useBlock2] = qwik.useLexicalScope();
509
- if (checkIsDefined(useBlock2.value.hide))
516
+ if ("hide" in useBlock2.value)
510
517
  return !useBlock2.value.hide;
511
- if (checkIsDefined(useBlock2.value.show))
518
+ if ("show" in useBlock2.value)
512
519
  return useBlock2.value.show;
513
520
  return true;
514
521
  }, "RenderBlock_component_canShowBlock_useComputed_82dAQcDBUzY", [
@@ -1605,6 +1612,11 @@ const componentInfo$5 = {
1605
1612
  }
1606
1613
  ]
1607
1614
  };
1615
+ const logger = {
1616
+ log: (...message) => console.log("[Builder.io]: ", ...message),
1617
+ error: (...message) => console.error("[Builder.io]: ", ...message),
1618
+ warn: (...message) => console.warn("[Builder.io]: ", ...message)
1619
+ };
1608
1620
  function getGlobalThis() {
1609
1621
  if (typeof globalThis !== "undefined")
1610
1622
  return globalThis;
@@ -1857,30 +1869,39 @@ async function getContent(options) {
1857
1869
  ...options,
1858
1870
  limit: 1
1859
1871
  });
1860
- if ("results" in allContent)
1872
+ if (allContent && "results" in allContent)
1861
1873
  return allContent?.results[0] || null;
1862
1874
  return null;
1863
1875
  }
1864
1876
  async function getAllContent(options) {
1865
- const url = generateContentUrl(options);
1866
- const res = await fetch$1(url.href);
1867
- const content = await res.json();
1868
- if ("status" in content && !("results" in content)) {
1869
- console.error("[Builder.io]: Error fetching data. ", content, options);
1870
- return content;
1871
- }
1872
- const canTrack = options.canTrack !== false;
1873
1877
  try {
1874
- if (canTrack && Array.isArray(content.results))
1875
- for (const item of content.results)
1876
- await handleABTesting({
1877
- item,
1878
- canTrack
1879
- });
1880
- } catch (e) {
1881
- console.error("[Builder.io]: Could not setup A/B testing. ", e);
1878
+ const url = generateContentUrl(options);
1879
+ const res = await fetch$1(url.href);
1880
+ const content = await res.json();
1881
+ if ("status" in content && !("results" in content)) {
1882
+ logger.error("Error fetching data. ", {
1883
+ url,
1884
+ content,
1885
+ options
1886
+ });
1887
+ return content;
1888
+ }
1889
+ const canTrack = options.canTrack !== false;
1890
+ try {
1891
+ if (canTrack && Array.isArray(content.results))
1892
+ for (const item of content.results)
1893
+ await handleABTesting({
1894
+ item,
1895
+ canTrack
1896
+ });
1897
+ } catch (e) {
1898
+ logger.error("Could not setup A/B testing. ", e);
1899
+ }
1900
+ return content;
1901
+ } catch (error) {
1902
+ logger.error("Error fetching data. ", error);
1903
+ return null;
1882
1904
  }
1883
- return content;
1884
1905
  }
1885
1906
  const fetchContent = function fetchContent2(props, state, builderContext2) {
1886
1907
  if (!state.contentToUse && props.symbol?.model && builderContext2?.apiKey)
@@ -1895,7 +1916,7 @@ const fetchContent = function fetchContent2(props, state, builderContext2) {
1895
1916
  if (response)
1896
1917
  state.contentToUse = response;
1897
1918
  }).catch((err) => {
1898
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
1919
+ logger.error("Could not fetch symbol content: ", err);
1899
1920
  });
1900
1921
  };
1901
1922
  const Symbol$1 = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
@@ -2631,7 +2652,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
2631
2652
  });
2632
2653
  async function _track(eventProps) {
2633
2654
  if (!eventProps.apiKey) {
2634
- console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
2655
+ logger.error("Missing API key for track call. Please provide your API key.");
2635
2656
  return;
2636
2657
  }
2637
2658
  if (!eventProps.canTrack)
@@ -3097,12 +3118,13 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3097
3118
  context: props.context || {},
3098
3119
  apiKey: props.apiKey,
3099
3120
  apiVersion: props.apiVersion,
3100
- registeredComponents: state.allRegisteredComponents
3121
+ registeredComponents: state.allRegisteredComponents,
3122
+ inheritedStyles: {}
3101
3123
  }));
3102
3124
  qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
3103
3125
  const [elementRef2, props2, state2] = qwik.useLexicalScope();
3104
3126
  if (!props2.apiKey)
3105
- console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
3127
+ logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
3106
3128
  if (isBrowser()) {
3107
3129
  if (isEditing()) {
3108
3130
  state2.forceReRenderCount = state2.forceReRenderCount + 1;
@@ -3135,9 +3157,10 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3135
3157
  }
3136
3158
  if (isPreviewing()) {
3137
3159
  const searchParams = new URL(location.href).searchParams;
3138
- const searchParamPreview = searchParams.get("builder.preview");
3160
+ const searchParamPreviewModel = searchParams.get("builder.preview");
3161
+ const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
3139
3162
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
3140
- if (searchParamPreview === props2.model && previewApiKey === props2.apiKey)
3163
+ if (searchParamPreviewModel === props2.model && previewApiKey === props2.apiKey && (!props2.content || searchParamPreviewId === props2.content.id))
3141
3164
  getContent({
3142
3165
  model: props2.model,
3143
3166
  apiKey: props2.apiKey,
@@ -300,8 +300,14 @@ function getBlockComponentOptions(block) {
300
300
  function transformBlockProperties(properties) {
301
301
  return properties;
302
302
  }
303
+ const extractRelevantRootBlockProperties = (block) => {
304
+ return {
305
+ href: block.href
306
+ };
307
+ };
303
308
  function getBlockProperties(block) {
304
309
  const properties = {
310
+ ...extractRelevantRootBlockProperties(block),
305
311
  ...block.properties,
306
312
  "builder-id": block.id,
307
313
  style: getStyleAttribute(block.style),
@@ -447,7 +453,8 @@ const RenderRepeatedBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlined
447
453
  context: props.repeatContext.context,
448
454
  apiKey: props.repeatContext.apiKey,
449
455
  registeredComponents: props.repeatContext.registeredComponents,
450
- inheritedStyles: props.repeatContext.inheritedStyles
456
+ inheritedStyles: props.repeatContext.inheritedStyles,
457
+ apiVersion: props.repeatContext.apiVersion
451
458
  }));
452
459
  return /* @__PURE__ */ _jsxC(RenderBlock, {
453
460
  get block() {
@@ -504,9 +511,9 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
504
511
  ]));
505
512
  const canShowBlock = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
506
513
  const [useBlock2] = useLexicalScope();
507
- if (checkIsDefined(useBlock2.value.hide))
514
+ if ("hide" in useBlock2.value)
508
515
  return !useBlock2.value.hide;
509
- if (checkIsDefined(useBlock2.value.show))
516
+ if ("show" in useBlock2.value)
510
517
  return useBlock2.value.show;
511
518
  return true;
512
519
  }, "RenderBlock_component_canShowBlock_useComputed_82dAQcDBUzY", [
@@ -1603,6 +1610,11 @@ const componentInfo$5 = {
1603
1610
  }
1604
1611
  ]
1605
1612
  };
1613
+ const logger = {
1614
+ log: (...message) => console.log("[Builder.io]: ", ...message),
1615
+ error: (...message) => console.error("[Builder.io]: ", ...message),
1616
+ warn: (...message) => console.warn("[Builder.io]: ", ...message)
1617
+ };
1606
1618
  function getGlobalThis() {
1607
1619
  if (typeof globalThis !== "undefined")
1608
1620
  return globalThis;
@@ -1855,30 +1867,39 @@ async function getContent(options) {
1855
1867
  ...options,
1856
1868
  limit: 1
1857
1869
  });
1858
- if ("results" in allContent)
1870
+ if (allContent && "results" in allContent)
1859
1871
  return allContent?.results[0] || null;
1860
1872
  return null;
1861
1873
  }
1862
1874
  async function getAllContent(options) {
1863
- const url = generateContentUrl(options);
1864
- const res = await fetch$1(url.href);
1865
- const content = await res.json();
1866
- if ("status" in content && !("results" in content)) {
1867
- console.error("[Builder.io]: Error fetching data. ", content, options);
1868
- return content;
1869
- }
1870
- const canTrack = options.canTrack !== false;
1871
1875
  try {
1872
- if (canTrack && Array.isArray(content.results))
1873
- for (const item of content.results)
1874
- await handleABTesting({
1875
- item,
1876
- canTrack
1877
- });
1878
- } catch (e) {
1879
- console.error("[Builder.io]: Could not setup A/B testing. ", e);
1876
+ const url = generateContentUrl(options);
1877
+ const res = await fetch$1(url.href);
1878
+ const content = await res.json();
1879
+ if ("status" in content && !("results" in content)) {
1880
+ logger.error("Error fetching data. ", {
1881
+ url,
1882
+ content,
1883
+ options
1884
+ });
1885
+ return content;
1886
+ }
1887
+ const canTrack = options.canTrack !== false;
1888
+ try {
1889
+ if (canTrack && Array.isArray(content.results))
1890
+ for (const item of content.results)
1891
+ await handleABTesting({
1892
+ item,
1893
+ canTrack
1894
+ });
1895
+ } catch (e) {
1896
+ logger.error("Could not setup A/B testing. ", e);
1897
+ }
1898
+ return content;
1899
+ } catch (error) {
1900
+ logger.error("Error fetching data. ", error);
1901
+ return null;
1880
1902
  }
1881
- return content;
1882
1903
  }
1883
1904
  const fetchContent = function fetchContent2(props, state, builderContext2) {
1884
1905
  if (!state.contentToUse && props.symbol?.model && builderContext2?.apiKey)
@@ -1893,7 +1914,7 @@ const fetchContent = function fetchContent2(props, state, builderContext2) {
1893
1914
  if (response)
1894
1915
  state.contentToUse = response;
1895
1916
  }).catch((err) => {
1896
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
1917
+ logger.error("Could not fetch symbol content: ", err);
1897
1918
  });
1898
1919
  };
1899
1920
  const Symbol$1 = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
@@ -2629,7 +2650,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
2629
2650
  });
2630
2651
  async function _track(eventProps) {
2631
2652
  if (!eventProps.apiKey) {
2632
- console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
2653
+ logger.error("Missing API key for track call. Please provide your API key.");
2633
2654
  return;
2634
2655
  }
2635
2656
  if (!eventProps.canTrack)
@@ -3095,12 +3116,13 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3095
3116
  context: props.context || {},
3096
3117
  apiKey: props.apiKey,
3097
3118
  apiVersion: props.apiVersion,
3098
- registeredComponents: state.allRegisteredComponents
3119
+ registeredComponents: state.allRegisteredComponents,
3120
+ inheritedStyles: {}
3099
3121
  }));
3100
3122
  useVisibleTaskQrl(/* @__PURE__ */ inlinedQrl(() => {
3101
3123
  const [elementRef2, props2, state2] = useLexicalScope();
3102
3124
  if (!props2.apiKey)
3103
- console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
3125
+ logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
3104
3126
  if (isBrowser()) {
3105
3127
  if (isEditing()) {
3106
3128
  state2.forceReRenderCount = state2.forceReRenderCount + 1;
@@ -3133,9 +3155,10 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3133
3155
  }
3134
3156
  if (isPreviewing()) {
3135
3157
  const searchParams = new URL(location.href).searchParams;
3136
- const searchParamPreview = searchParams.get("builder.preview");
3158
+ const searchParamPreviewModel = searchParams.get("builder.preview");
3159
+ const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
3137
3160
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
3138
- if (searchParamPreview === props2.model && previewApiKey === props2.apiKey)
3161
+ if (searchParamPreviewModel === props2.model && previewApiKey === props2.apiKey && (!props2.content || searchParamPreviewId === props2.content.id))
3139
3162
  getContent({
3140
3163
  model: props2.model,
3141
3164
  apiKey: props2.apiKey,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.2.1",
3
+ "version": "0.2.3",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -8,7 +8,7 @@ export interface ImageProps {
8
8
  height?: number;
9
9
  width?: number;
10
10
  altText?: string;
11
- backgroundSize?: string;
11
+ backgroundSize?: "cover" | "contain";
12
12
  backgroundPosition?: string;
13
13
  srcset?: string;
14
14
  aspectRatio?: number;
@@ -0,0 +1,6 @@
1
+ type VariantData = {
2
+ id: string;
3
+ testRatio?: number;
4
+ };
5
+ export declare const getVariantsScriptString: (variants: VariantData[], contentId: string) => string;
6
+ export {};
@@ -0,0 +1,3 @@
1
+ import { RenderContentProps } from "../render-content/render-content.types";
2
+ export declare const RenderContentVariants: import("@builder.io/qwik").Component<RenderContentProps>;
3
+ export default RenderContentVariants;
@@ -3,4 +3,5 @@ export declare function getBlockProperties(block: BuilderBlock): {
3
3
  'builder-id': string | undefined;
4
4
  style: string | Partial<CSSStyleDeclaration> | undefined;
5
5
  class: string;
6
+ href: any;
6
7
  };
@@ -7,5 +7,5 @@ type ContentResponse = {
7
7
  status: number;
8
8
  message: string;
9
9
  };
10
- export declare function getAllContent(options: GetContentOptions): Promise<ContentResponse>;
10
+ export declare function getAllContent(options: GetContentOptions): Promise<ContentResponse | null>;
11
11
  export {};
@@ -0,0 +1,5 @@
1
+ export declare const logger: {
2
+ log: (...message: any[]) => void;
3
+ error: (...message: any[]) => void;
4
+ warn: (...message: any[]) => void;
5
+ };
package/types/index.d.ts CHANGED
@@ -10,3 +10,4 @@ export * from './functions/get-builder-search-params/index.js';
10
10
  export { track } from './functions/track/index.js';
11
11
  export type { RegisteredComponent } from './context/types';
12
12
  export type { ComponentInfo } from './types/components';
13
+ export type { RenderContentProps } from './components/render-content/render-content.types.js';
@@ -1,5 +1,5 @@
1
1
  import type { BuilderBlock } from './builder-block.js';
2
- import type { Input } from './components.js';
2
+ import type { Input } from './input.js';
3
3
  import type { Nullable } from './typescript.js';
4
4
  export interface Breakpoints {
5
5
  small: number;
@@ -1,76 +1,5 @@
1
1
  import type { BuilderElement } from './element';
2
- export interface Input {
3
- name: string;
4
- friendlyName?: string;
5
- description?: string;
6
- defaultValue?: any;
7
- type: string;
8
- valueType?: {
9
- type?: string;
10
- };
11
- required?: boolean;
12
- autoFocus?: boolean;
13
- subFields?: Input[];
14
- helperText?: string;
15
- allowedFileTypes?: string[];
16
- imageHeight?: number;
17
- imageWidth?: number;
18
- mediaHeight?: number;
19
- mediaWidth?: number;
20
- hideFromUI?: boolean;
21
- modelId?: string;
22
- /**
23
- * Number field type validation maximum accepted input
24
- */
25
- max?: number;
26
- /**
27
- * Number field type validation minimum accepted input
28
- */
29
- min?: number;
30
- /**
31
- * Number field type step size when using arrows
32
- */
33
- step?: number;
34
- /**
35
- * Set this to `true` to show the editor for this input when
36
- * children of this component are selected. This is useful for things
37
- * like Tabs, such that users may not always select the Tabs component
38
- * directly but will still be looking for how to add additional tabs
39
- */
40
- broadcast?: boolean;
41
- /**
42
- * Set this to `true` to show the editor for this input when
43
- * group locked parents of this component are selected. This is useful
44
- * to bubble up important inputs for locked groups, like text and images
45
- */
46
- bubble?: boolean;
47
- options?: {
48
- [key: string]: any;
49
- };
50
- enum?: string[] | {
51
- label: string;
52
- value: any;
53
- helperText?: string;
54
- }[];
55
- /** Regex field validation for all string types (text, longText, html, url, etc) */
56
- regex?: {
57
- /** pattern to test, like "^\/[a-z]$" */
58
- pattern: string;
59
- /** flags for the RegExp constructor, e.g. "gi" */
60
- options?: string;
61
- /**
62
- * Friendly message to display to end-users if the regex fails, e.g.
63
- * "You must use a relative url starting with '/...' "
64
- */
65
- message: string;
66
- };
67
- advanced?: boolean;
68
- onChange?: ((options: Map<string, any>) => void | Promise<void>) | string;
69
- code?: boolean;
70
- richText?: boolean;
71
- showIf?: ((options: Map<string, any>) => boolean) | string;
72
- copyOnAdd?: boolean;
73
- }
2
+ import type { Input } from './input';
74
3
  export interface ComponentInfo {
75
4
  /**
76
5
  * Name your component something unique, e.g. 'MyButton'. You can override built-in components
@@ -114,4 +114,8 @@ export interface Input {
114
114
  * Use optionally with inputs of type `reference`. Restricts the content entry picker to a specific model by name.
115
115
  */
116
116
  model?: string;
117
+ valueType?: {
118
+ type?: string;
119
+ };
120
+ onChange?: ((options: Map<string, any>) => void | Promise<void>) | string;
117
121
  }