@builder.io/sdk-qwik 0.2.1 → 0.2.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.
@@ -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),
@@ -506,9 +512,9 @@ const RenderBlock = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlin
506
512
  ]));
507
513
  const canShowBlock = qwik.useComputedQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
508
514
  const [useBlock2] = qwik.useLexicalScope();
509
- if (checkIsDefined(useBlock2.value.hide))
515
+ if ("hide" in useBlock2.value)
510
516
  return !useBlock2.value.hide;
511
- if (checkIsDefined(useBlock2.value.show))
517
+ if ("show" in useBlock2.value)
512
518
  return useBlock2.value.show;
513
519
  return true;
514
520
  }, "RenderBlock_component_canShowBlock_useComputed_82dAQcDBUzY", [
@@ -1605,6 +1611,11 @@ const componentInfo$5 = {
1605
1611
  }
1606
1612
  ]
1607
1613
  };
1614
+ const logger = {
1615
+ log: (...message) => console.log("[Builder.io]: ", ...message),
1616
+ error: (...message) => console.error("[Builder.io]: ", ...message),
1617
+ warn: (...message) => console.warn("[Builder.io]: ", ...message)
1618
+ };
1608
1619
  function getGlobalThis() {
1609
1620
  if (typeof globalThis !== "undefined")
1610
1621
  return globalThis;
@@ -1857,30 +1868,35 @@ async function getContent(options) {
1857
1868
  ...options,
1858
1869
  limit: 1
1859
1870
  });
1860
- if ("results" in allContent)
1871
+ if (allContent && "results" in allContent)
1861
1872
  return allContent?.results[0] || null;
1862
1873
  return null;
1863
1874
  }
1864
1875
  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
1876
  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);
1877
+ const url = generateContentUrl(options);
1878
+ const res = await fetch$1(url.href);
1879
+ const content = await res.json();
1880
+ if ("status" in content && !("results" in content)) {
1881
+ logger.error("Error fetching data. ", content, options);
1882
+ return content;
1883
+ }
1884
+ const canTrack = options.canTrack !== false;
1885
+ try {
1886
+ if (canTrack && Array.isArray(content.results))
1887
+ for (const item of content.results)
1888
+ await handleABTesting({
1889
+ item,
1890
+ canTrack
1891
+ });
1892
+ } catch (e) {
1893
+ logger.error("Could not setup A/B testing. ", e);
1894
+ }
1895
+ return content;
1896
+ } catch (error) {
1897
+ logger.error("Error fetching data. ", error);
1898
+ return null;
1882
1899
  }
1883
- return content;
1884
1900
  }
1885
1901
  const fetchContent = function fetchContent2(props, state, builderContext2) {
1886
1902
  if (!state.contentToUse && props.symbol?.model && builderContext2?.apiKey)
@@ -1895,7 +1911,7 @@ const fetchContent = function fetchContent2(props, state, builderContext2) {
1895
1911
  if (response)
1896
1912
  state.contentToUse = response;
1897
1913
  }).catch((err) => {
1898
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
1914
+ logger.error("Could not fetch symbol content: ", err);
1899
1915
  });
1900
1916
  };
1901
1917
  const Symbol$1 = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inlinedQrl((props) => {
@@ -2631,7 +2647,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
2631
2647
  });
2632
2648
  async function _track(eventProps) {
2633
2649
  if (!eventProps.apiKey) {
2634
- console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
2650
+ logger.error("Missing API key for track call. Please provide your API key.");
2635
2651
  return;
2636
2652
  }
2637
2653
  if (!eventProps.canTrack)
@@ -3102,7 +3118,7 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3102
3118
  qwik.useVisibleTaskQrl(/* @__PURE__ */ qwik.inlinedQrl(() => {
3103
3119
  const [elementRef2, props2, state2] = qwik.useLexicalScope();
3104
3120
  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.");
3121
+ logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
3106
3122
  if (isBrowser()) {
3107
3123
  if (isEditing()) {
3108
3124
  state2.forceReRenderCount = state2.forceReRenderCount + 1;
@@ -3135,9 +3151,10 @@ const RenderContent = /* @__PURE__ */ qwik.componentQrl(/* @__PURE__ */ qwik.inl
3135
3151
  }
3136
3152
  if (isPreviewing()) {
3137
3153
  const searchParams = new URL(location.href).searchParams;
3138
- const searchParamPreview = searchParams.get("builder.preview");
3154
+ const searchParamPreviewModel = searchParams.get("builder.preview");
3155
+ const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
3139
3156
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
3140
- if (searchParamPreview === props2.model && previewApiKey === props2.apiKey)
3157
+ if (searchParamPreviewModel === props2.model && previewApiKey === props2.apiKey && (!props2.content || searchParamPreviewId === props2.content.id))
3141
3158
  getContent({
3142
3159
  model: props2.model,
3143
3160
  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),
@@ -504,9 +510,9 @@ const RenderBlock = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((pro
504
510
  ]));
505
511
  const canShowBlock = useComputedQrl(/* @__PURE__ */ inlinedQrl(() => {
506
512
  const [useBlock2] = useLexicalScope();
507
- if (checkIsDefined(useBlock2.value.hide))
513
+ if ("hide" in useBlock2.value)
508
514
  return !useBlock2.value.hide;
509
- if (checkIsDefined(useBlock2.value.show))
515
+ if ("show" in useBlock2.value)
510
516
  return useBlock2.value.show;
511
517
  return true;
512
518
  }, "RenderBlock_component_canShowBlock_useComputed_82dAQcDBUzY", [
@@ -1603,6 +1609,11 @@ const componentInfo$5 = {
1603
1609
  }
1604
1610
  ]
1605
1611
  };
1612
+ const logger = {
1613
+ log: (...message) => console.log("[Builder.io]: ", ...message),
1614
+ error: (...message) => console.error("[Builder.io]: ", ...message),
1615
+ warn: (...message) => console.warn("[Builder.io]: ", ...message)
1616
+ };
1606
1617
  function getGlobalThis() {
1607
1618
  if (typeof globalThis !== "undefined")
1608
1619
  return globalThis;
@@ -1855,30 +1866,35 @@ async function getContent(options) {
1855
1866
  ...options,
1856
1867
  limit: 1
1857
1868
  });
1858
- if ("results" in allContent)
1869
+ if (allContent && "results" in allContent)
1859
1870
  return allContent?.results[0] || null;
1860
1871
  return null;
1861
1872
  }
1862
1873
  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
1874
  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);
1875
+ const url = generateContentUrl(options);
1876
+ const res = await fetch$1(url.href);
1877
+ const content = await res.json();
1878
+ if ("status" in content && !("results" in content)) {
1879
+ logger.error("Error fetching data. ", content, options);
1880
+ return content;
1881
+ }
1882
+ const canTrack = options.canTrack !== false;
1883
+ try {
1884
+ if (canTrack && Array.isArray(content.results))
1885
+ for (const item of content.results)
1886
+ await handleABTesting({
1887
+ item,
1888
+ canTrack
1889
+ });
1890
+ } catch (e) {
1891
+ logger.error("Could not setup A/B testing. ", e);
1892
+ }
1893
+ return content;
1894
+ } catch (error) {
1895
+ logger.error("Error fetching data. ", error);
1896
+ return null;
1880
1897
  }
1881
- return content;
1882
1898
  }
1883
1899
  const fetchContent = function fetchContent2(props, state, builderContext2) {
1884
1900
  if (!state.contentToUse && props.symbol?.model && builderContext2?.apiKey)
@@ -1893,7 +1909,7 @@ const fetchContent = function fetchContent2(props, state, builderContext2) {
1893
1909
  if (response)
1894
1910
  state.contentToUse = response;
1895
1911
  }).catch((err) => {
1896
- console.error("[Builder.io]: Could not fetch symbol content: ", err);
1912
+ logger.error("Could not fetch symbol content: ", err);
1897
1913
  });
1898
1914
  };
1899
1915
  const Symbol$1 = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((props) => {
@@ -2629,7 +2645,7 @@ const createEvent = async ({ type: eventType, canTrack, apiKey, metadata, ...pro
2629
2645
  });
2630
2646
  async function _track(eventProps) {
2631
2647
  if (!eventProps.apiKey) {
2632
- console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
2648
+ logger.error("Missing API key for track call. Please provide your API key.");
2633
2649
  return;
2634
2650
  }
2635
2651
  if (!eventProps.canTrack)
@@ -3100,7 +3116,7 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3100
3116
  useVisibleTaskQrl(/* @__PURE__ */ inlinedQrl(() => {
3101
3117
  const [elementRef2, props2, state2] = useLexicalScope();
3102
3118
  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.");
3119
+ logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
3104
3120
  if (isBrowser()) {
3105
3121
  if (isEditing()) {
3106
3122
  state2.forceReRenderCount = state2.forceReRenderCount + 1;
@@ -3133,9 +3149,10 @@ const RenderContent = /* @__PURE__ */ componentQrl(/* @__PURE__ */ inlinedQrl((p
3133
3149
  }
3134
3150
  if (isPreviewing()) {
3135
3151
  const searchParams = new URL(location.href).searchParams;
3136
- const searchParamPreview = searchParams.get("builder.preview");
3152
+ const searchParamPreviewModel = searchParams.get("builder.preview");
3153
+ const searchParamPreviewId = searchParams.get(`builder.preview.${searchParamPreviewModel}`);
3137
3154
  const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
3138
- if (searchParamPreview === props2.model && previewApiKey === props2.apiKey)
3155
+ if (searchParamPreviewModel === props2.model && previewApiKey === props2.apiKey && (!props2.content || searchParamPreviewId === props2.content.id))
3139
3156
  getContent({
3140
3157
  model: props2.model,
3141
3158
  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.2",
4
4
  "description": "Builder.io Qwik SDK",
5
5
  "type": "module",
6
6
  "main": "./lib/index.qwik.cjs",
@@ -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
+ };
@@ -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
  }