@builder.io/sdk-qwik 0.16.24 → 0.17.1

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 (106) hide show
  1. package/lib/browser/blocks/image/component-info.qwik.cjs +2 -7
  2. package/lib/browser/blocks/image/component-info.qwik.mjs +2 -7
  3. package/lib/browser/blocks/image/image.qwik.cjs +1 -1
  4. package/lib/browser/blocks/image/image.qwik.mjs +1 -1
  5. package/lib/browser/blocks/img/component-info.qwik.cjs +2 -8
  6. package/lib/browser/blocks/img/component-info.qwik.mjs +2 -8
  7. package/lib/browser/blocks/video/component-info.qwik.cjs +3 -7
  8. package/lib/browser/blocks/video/component-info.qwik.mjs +3 -7
  9. package/lib/browser/components/block/block.helpers.qwik.cjs +16 -5
  10. package/lib/browser/components/block/block.helpers.qwik.mjs +16 -5
  11. package/lib/browser/components/block/block.qwik.cjs +3 -2
  12. package/lib/browser/components/block/block.qwik.mjs +3 -2
  13. package/lib/browser/components/content/components/enable-editor.helpers.qwik.cjs +15 -0
  14. package/lib/browser/components/content/components/enable-editor.helpers.qwik.mjs +15 -0
  15. package/lib/browser/components/content/components/enable-editor.qwik.cjs +10 -4
  16. package/lib/browser/components/content/components/enable-editor.qwik.mjs +10 -4
  17. package/lib/browser/components/content/content.qwik.cjs +7 -18
  18. package/lib/browser/components/content/content.qwik.mjs +7 -18
  19. package/lib/browser/constants/file-types.qwik.cjs +72 -0
  20. package/lib/browser/constants/file-types.qwik.mjs +72 -0
  21. package/lib/browser/constants/sdk-version.qwik.cjs +1 -1
  22. package/lib/browser/constants/sdk-version.qwik.mjs +1 -1
  23. package/lib/browser/functions/extract-localized-values.qwik.cjs +37 -0
  24. package/lib/browser/functions/extract-localized-values.qwik.mjs +37 -0
  25. package/lib/browser/functions/get-content/index.qwik.cjs +10 -15
  26. package/lib/browser/functions/get-content/index.qwik.mjs +10 -15
  27. package/lib/browser/functions/get-processed-block.qwik.cjs +3 -1
  28. package/lib/browser/functions/get-processed-block.qwik.mjs +3 -1
  29. package/lib/browser/functions/register-component.qwik.cjs +1 -1
  30. package/lib/browser/functions/register-component.qwik.mjs +1 -1
  31. package/lib/browser/functions/traverse.qwik.cjs +31 -0
  32. package/lib/browser/functions/traverse.qwik.mjs +31 -0
  33. package/lib/edge/blocks/image/component-info.qwik.cjs +2 -7
  34. package/lib/edge/blocks/image/component-info.qwik.mjs +2 -7
  35. package/lib/edge/blocks/image/image.qwik.cjs +1 -1
  36. package/lib/edge/blocks/image/image.qwik.mjs +1 -1
  37. package/lib/edge/blocks/img/component-info.qwik.cjs +2 -8
  38. package/lib/edge/blocks/img/component-info.qwik.mjs +2 -8
  39. package/lib/edge/blocks/video/component-info.qwik.cjs +3 -7
  40. package/lib/edge/blocks/video/component-info.qwik.mjs +3 -7
  41. package/lib/edge/components/block/block.helpers.qwik.cjs +16 -5
  42. package/lib/edge/components/block/block.helpers.qwik.mjs +16 -5
  43. package/lib/edge/components/block/block.qwik.cjs +3 -2
  44. package/lib/edge/components/block/block.qwik.mjs +3 -2
  45. package/lib/edge/components/content/components/enable-editor.helpers.qwik.cjs +15 -0
  46. package/lib/edge/components/content/components/enable-editor.helpers.qwik.mjs +15 -0
  47. package/lib/edge/components/content/components/enable-editor.qwik.cjs +10 -4
  48. package/lib/edge/components/content/components/enable-editor.qwik.mjs +10 -4
  49. package/lib/edge/components/content/content.qwik.cjs +7 -18
  50. package/lib/edge/components/content/content.qwik.mjs +7 -18
  51. package/lib/edge/constants/file-types.qwik.cjs +72 -0
  52. package/lib/edge/constants/file-types.qwik.mjs +72 -0
  53. package/lib/edge/constants/sdk-version.qwik.cjs +1 -1
  54. package/lib/edge/constants/sdk-version.qwik.mjs +1 -1
  55. package/lib/edge/functions/extract-localized-values.qwik.cjs +37 -0
  56. package/lib/edge/functions/extract-localized-values.qwik.mjs +37 -0
  57. package/lib/edge/functions/get-content/index.qwik.cjs +10 -15
  58. package/lib/edge/functions/get-content/index.qwik.mjs +10 -15
  59. package/lib/edge/functions/get-processed-block.qwik.cjs +3 -1
  60. package/lib/edge/functions/get-processed-block.qwik.mjs +3 -1
  61. package/lib/edge/functions/register-component.qwik.cjs +1 -1
  62. package/lib/edge/functions/register-component.qwik.mjs +1 -1
  63. package/lib/edge/functions/traverse.qwik.cjs +31 -0
  64. package/lib/edge/functions/traverse.qwik.mjs +31 -0
  65. package/lib/node/blocks/image/component-info.qwik.cjs +2 -7
  66. package/lib/node/blocks/image/component-info.qwik.mjs +2 -7
  67. package/lib/node/blocks/image/image.qwik.cjs +1 -1
  68. package/lib/node/blocks/image/image.qwik.mjs +1 -1
  69. package/lib/node/blocks/img/component-info.qwik.cjs +2 -8
  70. package/lib/node/blocks/img/component-info.qwik.mjs +2 -8
  71. package/lib/node/blocks/video/component-info.qwik.cjs +3 -7
  72. package/lib/node/blocks/video/component-info.qwik.mjs +3 -7
  73. package/lib/node/components/block/block.helpers.qwik.cjs +16 -5
  74. package/lib/node/components/block/block.helpers.qwik.mjs +16 -5
  75. package/lib/node/components/block/block.qwik.cjs +3 -2
  76. package/lib/node/components/block/block.qwik.mjs +3 -2
  77. package/lib/node/components/content/components/enable-editor.helpers.qwik.cjs +15 -0
  78. package/lib/node/components/content/components/enable-editor.helpers.qwik.mjs +15 -0
  79. package/lib/node/components/content/components/enable-editor.qwik.cjs +10 -4
  80. package/lib/node/components/content/components/enable-editor.qwik.mjs +10 -4
  81. package/lib/node/components/content/content.qwik.cjs +7 -18
  82. package/lib/node/components/content/content.qwik.mjs +7 -18
  83. package/lib/node/constants/file-types.qwik.cjs +72 -0
  84. package/lib/node/constants/file-types.qwik.mjs +72 -0
  85. package/lib/node/constants/sdk-version.qwik.cjs +1 -1
  86. package/lib/node/constants/sdk-version.qwik.mjs +1 -1
  87. package/lib/node/functions/extract-localized-values.qwik.cjs +37 -0
  88. package/lib/node/functions/extract-localized-values.qwik.mjs +37 -0
  89. package/lib/node/functions/get-content/index.qwik.cjs +10 -15
  90. package/lib/node/functions/get-content/index.qwik.mjs +10 -15
  91. package/lib/node/functions/get-processed-block.qwik.cjs +3 -1
  92. package/lib/node/functions/get-processed-block.qwik.mjs +3 -1
  93. package/lib/node/functions/register-component.qwik.cjs +1 -1
  94. package/lib/node/functions/register-component.qwik.mjs +1 -1
  95. package/lib/node/functions/traverse.qwik.cjs +31 -0
  96. package/lib/node/functions/traverse.qwik.mjs +31 -0
  97. package/package.json +1 -1
  98. package/types/src/components/block/block.helpers.d.ts +6 -3
  99. package/types/src/components/content/components/enable-editor.helpers.d.ts +11 -0
  100. package/types/src/constants/file-types.d.ts +2 -0
  101. package/types/src/constants/sdk-version.d.ts +1 -1
  102. package/types/src/context/types.d.ts +1 -0
  103. package/types/src/functions/extract-localized-values.d.ts +2 -0
  104. package/types/src/functions/get-content/index.d.ts +1 -1
  105. package/types/src/functions/traverse.d.ts +34 -0
  106. package/types/src/types/components.d.ts +3 -0
@@ -0,0 +1,37 @@
1
+ import { traverse } from "./traverse.qwik.mjs";
2
+ function isLocalizedField(value) {
3
+ return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
4
+ }
5
+ function containsLocalizedValues(data) {
6
+ if (!data || !Object.getOwnPropertyNames(data).length)
7
+ return false;
8
+ let hasLocalizedValues = false;
9
+ traverse(data, (value) => {
10
+ if (isLocalizedField(value)) {
11
+ hasLocalizedValues = true;
12
+ return;
13
+ }
14
+ });
15
+ return hasLocalizedValues;
16
+ }
17
+ function extractLocalizedValues(data, locale) {
18
+ if (!data || !Object.getOwnPropertyNames(data).length)
19
+ return {};
20
+ traverse(data, (value, update) => {
21
+ if (isLocalizedField(value))
22
+ update(value[locale] ?? void 0);
23
+ });
24
+ return data;
25
+ }
26
+ function resolveLocalizedValues(block, locale) {
27
+ var _a, _b;
28
+ if (((_a = block.component) == null ? void 0 : _a.options) && containsLocalizedValues((_b = block.component) == null ? void 0 : _b.options)) {
29
+ if (!locale)
30
+ console.warn("[Builder.io] In order to use localized fields in Builder, you must pass a locale prop to the BuilderComponent or to options object while fetching the content to resolve localized fields. Learn more: https://www.builder.io/c/docs/localization-inline#targeting-and-inline-localization");
31
+ block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
32
+ }
33
+ return block;
34
+ }
35
+ export {
36
+ resolveLocalizedValues
37
+ };
@@ -54,22 +54,17 @@ const _processContentResult = async (options, content, url = generateContentUrl.
54
54
  return content.results;
55
55
  };
56
56
  async function fetchEntries(options) {
57
- try {
58
- const url = generateContentUrl.generateContentUrl(options);
59
- const content = await _fetchContent(options);
60
- if (!checkContentHasResults(content)) {
61
- logger.logger.error("Error fetching data. ", {
62
- url,
63
- content,
64
- options
65
- });
66
- return null;
67
- }
68
- return _processContentResult(options, content);
69
- } catch (error) {
70
- logger.logger.error("Error fetching data. ", error);
71
- return null;
57
+ const url = generateContentUrl.generateContentUrl(options);
58
+ const content = await _fetchContent(options);
59
+ if (!checkContentHasResults(content)) {
60
+ logger.logger.error("Error fetching data. ", {
61
+ url,
62
+ content,
63
+ options
64
+ });
65
+ throw content;
72
66
  }
67
+ return _processContentResult(options, content);
73
68
  }
74
69
  exports._processContentResult = _processContentResult;
75
70
  exports.fetchEntries = fetchEntries;
@@ -52,22 +52,17 @@ const _processContentResult = async (options, content, url = generateContentUrl(
52
52
  return content.results;
53
53
  };
54
54
  async function fetchEntries(options) {
55
- try {
56
- const url = generateContentUrl(options);
57
- const content = await _fetchContent(options);
58
- if (!checkContentHasResults(content)) {
59
- logger.error("Error fetching data. ", {
60
- url,
61
- content,
62
- options
63
- });
64
- return null;
65
- }
66
- return _processContentResult(options, content);
67
- } catch (error) {
68
- logger.error("Error fetching data. ", error);
69
- return null;
55
+ const url = generateContentUrl(options);
56
+ const content = await _fetchContent(options);
57
+ if (!checkContentHasResults(content)) {
58
+ logger.error("Error fetching data. ", {
59
+ url,
60
+ content,
61
+ options
62
+ });
63
+ throw content;
70
64
  }
65
+ return _processContentResult(options, content);
71
66
  }
72
67
  export {
73
68
  _processContentResult,
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const target = require("../constants/target.qwik.cjs");
4
4
  const omit = require("../helpers/omit.qwik.cjs");
5
5
  const evaluate = require("./evaluate/evaluate.qwik.cjs");
6
+ const extractLocalizedValues = require("./extract-localized-values.qwik.cjs");
6
7
  const fastClone = require("./fast-clone.qwik.cjs");
7
8
  const set = require("./set.qwik.cjs");
8
9
  const transformBlock = require("./transform-block.qwik.cjs");
@@ -72,7 +73,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
72
73
  return copied;
73
74
  };
74
75
  function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
75
- const transformedBlock = transformBlock.transformBlock(block);
76
+ let transformedBlock = extractLocalizedValues.resolveLocalizedValues(block, rootState.locale);
77
+ transformedBlock = transformBlock.transformBlock(transformedBlock);
76
78
  if (shouldEvaluateBindings)
77
79
  return evaluateBindings({
78
80
  block: transformedBlock,
@@ -1,6 +1,7 @@
1
1
  import { TARGET } from "../constants/target.qwik.mjs";
2
2
  import { omit } from "../helpers/omit.qwik.mjs";
3
3
  import { evaluate } from "./evaluate/evaluate.qwik.mjs";
4
+ import { resolveLocalizedValues } from "./extract-localized-values.qwik.mjs";
4
5
  import { fastClone } from "./fast-clone.qwik.mjs";
5
6
  import { set } from "./set.qwik.mjs";
6
7
  import { transformBlock } from "./transform-block.qwik.mjs";
@@ -70,7 +71,8 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
70
71
  return copied;
71
72
  };
72
73
  function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
73
- const transformedBlock = transformBlock(block);
74
+ let transformedBlock = resolveLocalizedValues(block, rootState.locale);
75
+ transformedBlock = transformBlock(transformedBlock);
74
76
  if (shouldEvaluateBindings)
75
77
  return evaluateBindings({
76
78
  block: transformedBlock,
@@ -7,7 +7,7 @@ const createRegisterComponentMessage = (info) => ({
7
7
  const serializeFn = (fnValue) => {
8
8
  const fnStr = fnValue.toString().trim();
9
9
  const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
10
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
10
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
11
11
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
12
12
  };
13
13
  function serializeIncludingFunctions(info) {
@@ -5,7 +5,7 @@ const createRegisterComponentMessage = (info) => ({
5
5
  const serializeFn = (fnValue) => {
6
6
  const fnStr = fnValue.toString().trim();
7
7
  const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
8
- const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
8
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
9
9
  return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
10
10
  };
11
11
  function serializeIncludingFunctions(info) {
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ function traverse(obj, callback, parent = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
4
+ if (obj == null || typeof obj !== "object") {
5
+ callback(obj, (newValue) => {
6
+ if (parent !== null && key !== null)
7
+ parent[key] = newValue;
8
+ });
9
+ return;
10
+ }
11
+ if (visited.has(obj))
12
+ return;
13
+ visited.add(obj);
14
+ if (Array.isArray(obj))
15
+ obj.forEach((item, index) => {
16
+ const update = (newValue) => {
17
+ obj[index] = newValue;
18
+ };
19
+ callback(item, update);
20
+ traverse(item, callback, obj, index, visited);
21
+ });
22
+ else
23
+ Object.entries(obj).forEach(([key2, value]) => {
24
+ const update = (newValue) => {
25
+ obj[key2] = newValue;
26
+ };
27
+ callback(value, update);
28
+ traverse(value, callback, obj, key2, visited);
29
+ });
30
+ }
31
+ exports.traverse = traverse;
@@ -0,0 +1,31 @@
1
+ function traverse(obj, callback, parent = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
2
+ if (obj == null || typeof obj !== "object") {
3
+ callback(obj, (newValue) => {
4
+ if (parent !== null && key !== null)
5
+ parent[key] = newValue;
6
+ });
7
+ return;
8
+ }
9
+ if (visited.has(obj))
10
+ return;
11
+ visited.add(obj);
12
+ if (Array.isArray(obj))
13
+ obj.forEach((item, index) => {
14
+ const update = (newValue) => {
15
+ obj[index] = newValue;
16
+ };
17
+ callback(item, update);
18
+ traverse(item, callback, obj, index, visited);
19
+ });
20
+ else
21
+ Object.entries(obj).forEach(([key2, value]) => {
22
+ const update = (newValue) => {
23
+ obj[key2] = newValue;
24
+ };
25
+ callback(value, update);
26
+ traverse(value, callback, obj, key2, visited);
27
+ });
28
+ }
29
+ export {
30
+ traverse
31
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-qwik",
3
- "version": "0.16.24",
3
+ "version": "0.17.1",
4
4
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/qwik",
5
5
  "repository": {
6
6
  "type": "git",
@@ -1,9 +1,10 @@
1
1
  import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
2
2
  import type { BuilderBlock } from '../../types/builder-block';
3
3
  import type { RepeatData } from './types';
4
- export declare const getComponent: ({ block, registeredComponents }: {
4
+ export declare const getComponent: ({ block, registeredComponents, model }: {
5
5
  block: BuilderBlock;
6
6
  registeredComponents: RegisteredComponents;
7
+ model: string;
7
8
  }) => RegisteredComponent | null | undefined;
8
9
  export declare const getRepeatItemData: ({ block, context }: {
9
10
  block: BuilderBlock;
@@ -18,8 +19,10 @@ export declare const provideLinkComponent: (block: RegisteredComponent | null |
18
19
  } | {
19
20
  builderLinkComponent?: undefined;
20
21
  };
21
- export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents) => {
22
- builderComponents: RegisteredComponents;
22
+ export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents, model: string) => {
23
+ builderComponents: {
24
+ [k: string]: RegisteredComponent;
25
+ };
23
26
  } | {
24
27
  builderComponents?: undefined;
25
28
  };
@@ -0,0 +1,11 @@
1
+ import type { Target } from '../../../types/targets';
2
+ /**
3
+ * SDKS that use the elementRef approach to enable visual editing.
4
+ * We don't need to render the div for other SDKs as they attach event listeners to the window.
5
+ */
6
+ export declare const SDKS_USING_ELEMENT_REF_APPROACH: Target[];
7
+ /**
8
+ * We need to attach this div only when content exists or isPreviewing/isEditing even when content is null,
9
+ * as we need to set the elementRef and allow previewing and visual editing
10
+ */
11
+ export declare const needsElementRefDivForEditing: () => boolean;
@@ -0,0 +1,2 @@
1
+ export declare const IMAGE_FILE_TYPES: string[];
2
+ export declare const VIDEO_FILE_TYPES: string[];
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.16.24";
1
+ export declare const SDK_VERSION = "0.17.1";
@@ -36,5 +36,6 @@ export interface BuilderContextInterface extends Pick<BlocksWrapperProps, 'Block
36
36
  componentInfos: Dictionary<ComponentInfo>;
37
37
  inheritedStyles: Record<string, unknown>;
38
38
  nonce: string;
39
+ model: string;
39
40
  canTrack?: boolean;
40
41
  }
@@ -0,0 +1,2 @@
1
+ import type { BuilderBlock } from '../types/builder-block';
2
+ export declare function resolveLocalizedValues(block: BuilderBlock, locale: string | undefined): BuilderBlock;
@@ -14,5 +14,5 @@ export declare const _processContentResult: (options: GetContentOptions, content
14
14
  /**
15
15
  * Returns a paginated array of entries that match the given options.
16
16
  */
17
- export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[] | null>;
17
+ export declare function fetchEntries(options: GetContentOptions): Promise<BuilderContent[]>;
18
18
  export {};
@@ -0,0 +1,34 @@
1
+ type TraverseCallback = (value: any, update: (newValue: any) => void) => void;
2
+ /**
3
+ * Recursively traverses an object or array, invoking a callback on each value.
4
+ *
5
+ * @param {any} obj - The object or array to traverse. Can also handle primitives, null, or undefined.
6
+ * @param {TraverseCallback} callback - The function to invoke on each value. Receives the current value
7
+ * and an `update` function to modify the value in its parent container.
8
+ * @param {any} [parent=null] - The parent object or array of the current value. Used internally.
9
+ * @param {any} [key=null] - The key or index of the current value in its parent. Used internally.
10
+ * @param {WeakSet} [visited=new WeakSet()] - Tracks visited objects to handle circular references. Used internally.
11
+ *
12
+ * @example
13
+ * // Example: Doubling all numbers in an object
14
+ * const obj = { a: 1, b: [2, 3, { c: 4 }] };
15
+ * traverse(obj, (value, update) => {
16
+ * if (typeof value === 'number') {
17
+ * update(value * 2);
18
+ * }
19
+ * });
20
+ * console.log(obj); // { a: 2, b: [4, 6, { c: 8 }] }
21
+ *
22
+ * @example
23
+ * // Example: Handling circular references
24
+ * const obj = { a: 1 };
25
+ * obj.self = obj;
26
+ * traverse(obj, (value, update) => {
27
+ * if (typeof value === 'number') {
28
+ * update(value * 2);
29
+ * }
30
+ * });
31
+ * console.log(obj.a); // 2
32
+ */
33
+ export declare function traverse(obj: any, callback: TraverseCallback, parent?: any, key?: any, visited?: WeakSet<object>): void;
34
+ export {};
@@ -146,6 +146,9 @@ export interface ComponentInfo {
146
146
  */
147
147
  builderLinkComponent?: boolean;
148
148
  };
149
+ meta?: {
150
+ [key: string]: any;
151
+ };
149
152
  }
150
153
  type Permission = 'read' | 'publish' | 'editCode' | 'editDesigns' | 'admin' | 'create';
151
154
  export {};