@builder.io/sdk-qwik 0.0.5 → 0.0.8

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 (108) hide show
  1. package/README.md +2 -65
  2. package/lib/index.97024df8.js +80165 -0
  3. package/lib/index.d8c1e37f.cjs +80165 -0
  4. package/lib/index.qwik.cjs +2424 -0
  5. package/lib/index.qwik.mjs +2424 -0
  6. package/package.json +3 -4
  7. package/tsconfig.json +1 -1
  8. package/types.d.ts +12 -7
  9. package/src/blocks/button/button.jsx +0 -211
  10. package/src/blocks/button/component-info.js +0 -41
  11. package/src/blocks/columns/columns.jsx +0 -267
  12. package/src/blocks/columns/component-info.js +0 -242
  13. package/src/blocks/custom-code/component-info.js +0 -31
  14. package/src/blocks/custom-code/custom-code.jsx +0 -130
  15. package/src/blocks/embed/component-info.js +0 -44
  16. package/src/blocks/embed/embed.jsx +0 -130
  17. package/src/blocks/embed/helpers.js +0 -9
  18. package/src/blocks/form/builder-blocks.jsx +0 -100
  19. package/src/blocks/form/component-info.js +0 -262
  20. package/src/blocks/form/form.jsx +0 -789
  21. package/src/blocks/fragment/component-info.js +0 -11
  22. package/src/blocks/fragment/fragment.jsx +0 -59
  23. package/src/blocks/image/component-info.js +0 -151
  24. package/src/blocks/image/image.helpers.js +0 -48
  25. package/src/blocks/image/image.jsx +0 -554
  26. package/src/blocks/img/component-info.js +0 -20
  27. package/src/blocks/img/img.jsx +0 -76
  28. package/src/blocks/input/component-info.js +0 -74
  29. package/src/blocks/input/input.jsx +0 -87
  30. package/src/blocks/raw-text/component-info.js +0 -16
  31. package/src/blocks/raw-text/raw-text.jsx +0 -53
  32. package/src/blocks/section/component-info.js +0 -49
  33. package/src/blocks/section/section.jsx +0 -97
  34. package/src/blocks/select/component-info.js +0 -59
  35. package/src/blocks/select/select.jsx +0 -149
  36. package/src/blocks/submit-button/component-info.js +0 -28
  37. package/src/blocks/submit-button/submit-button.jsx +0 -87
  38. package/src/blocks/symbol/component-info.js +0 -43
  39. package/src/blocks/symbol/symbol.jsx +0 -230
  40. package/src/blocks/text/component-info.js +0 -24
  41. package/src/blocks/text/text.jsx +0 -46
  42. package/src/blocks/textarea/component-info.js +0 -47
  43. package/src/blocks/textarea/textarea.jsx +0 -65
  44. package/src/blocks/util.js +0 -12
  45. package/src/blocks/video/component-info.js +0 -106
  46. package/src/blocks/video/video.jsx +0 -103
  47. package/src/components/render-block/block-styles.jsx +0 -186
  48. package/src/components/render-block/render-block.helpers.js +0 -23
  49. package/src/components/render-block/render-block.jsx +0 -749
  50. package/src/components/render-block/render-component.jsx +0 -257
  51. package/src/components/render-block/render-repeated-block.jsx +0 -119
  52. package/src/components/render-block/types.js +0 -0
  53. package/src/components/render-blocks.jsx +0 -387
  54. package/src/components/render-content/components/render-styles.jsx +0 -140
  55. package/src/components/render-content/index.js +0 -4
  56. package/src/components/render-content/render-content.jsx +0 -636
  57. package/src/components/render-inlined-styles.jsx +0 -153
  58. package/src/constants/builder-registered-components.js +0 -48
  59. package/src/constants/device-sizes.js +0 -21
  60. package/src/constants/target.js +0 -4
  61. package/src/context/builder.context.js +0 -5
  62. package/src/functions/camel-to-kebab-case.js +0 -4
  63. package/src/functions/convert-style-object.js +0 -6
  64. package/src/functions/evaluate.js +0 -28
  65. package/src/functions/event-handler-name.js +0 -7
  66. package/src/functions/get-block-actions.js +0 -23
  67. package/src/functions/get-block-component-options.js +0 -28
  68. package/src/functions/get-block-properties.js +0 -29
  69. package/src/functions/get-block-styles.js +0 -34
  70. package/src/functions/get-block-tag.js +0 -6
  71. package/src/functions/get-builder-search-params/fn.test.js +0 -13
  72. package/src/functions/get-builder-search-params/index.js +0 -33
  73. package/src/functions/get-content/ab-testing.js +0 -38
  74. package/src/functions/get-content/fn.test.js +0 -31
  75. package/src/functions/get-content/index.js +0 -99
  76. package/src/functions/get-content/types.js +0 -0
  77. package/src/functions/get-fetch.js +0 -33
  78. package/src/functions/get-global-this.js +0 -18
  79. package/src/functions/get-processed-block.js +0 -53
  80. package/src/functions/get-processed-block.test.js +0 -32
  81. package/src/functions/if-target.js +0 -15
  82. package/src/functions/is-browser.js +0 -6
  83. package/src/functions/is-editing.js +0 -7
  84. package/src/functions/is-iframe.js +0 -7
  85. package/src/functions/is-previewing.js +0 -14
  86. package/src/functions/on-change.js +0 -27
  87. package/src/functions/on-change.test.js +0 -19
  88. package/src/functions/register-component.js +0 -72
  89. package/src/functions/register.js +0 -29
  90. package/src/functions/sanitize-styles.js +0 -5
  91. package/src/functions/set-editor-settings.js +0 -15
  92. package/src/functions/set.js +0 -11
  93. package/src/functions/set.test.js +0 -16
  94. package/src/functions/track.js +0 -22
  95. package/src/functions/transform-block.js +0 -6
  96. package/src/helpers/css.js +0 -12
  97. package/src/helpers/flatten.js +0 -34
  98. package/src/index-helpers/blocks-exports.js +0 -22
  99. package/src/index-helpers/top-of-file.js +0 -4
  100. package/src/index.js +0 -10
  101. package/src/scripts/init-editing.js +0 -79
  102. package/src/types/builder-block.js +0 -0
  103. package/src/types/builder-content.js +0 -0
  104. package/src/types/components.js +0 -0
  105. package/src/types/deep-partial.js +0 -0
  106. package/src/types/element.js +0 -0
  107. package/src/types/targets.js +0 -0
  108. package/src/types/typescript.js +0 -0
@@ -1,153 +0,0 @@
1
- // GENERATED BY MITOSIS
2
-
3
- import { TARGET } from "../constants/target.js";
4
- import { Fragment, Host, component$, h } from "@builder.io/qwik";
5
- export const injectedStyleScript = function injectedStyleScript(props, state) {
6
- return `<${tagName(props, state)}>${props.styles}</${tagName(props, state)}>`;
7
- };
8
- export const tagName = function tagName(props, state) {
9
- // NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
10
- // https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
11
- return "sty" + "le";
12
- };
13
- export const RenderInlinedStyles = component$((props) => {
14
- const state = {};
15
- return (
16
- <Host q:host-pseudo="">
17
- {TARGET === "svelte" ? (
18
- <div dangerouslySetInnerHTML={injectedStyleScript(props, state)}></div>
19
- ) : (
20
- <state.tagName>{props.styles}</state.tagName>
21
- )}
22
- </Host>
23
- );
24
- });
25
- export default RenderInlinedStyles;
26
- export const COMPONENT = {
27
- "@type": "@builder.io/mitosis/component",
28
- imports: [
29
- {
30
- imports: {
31
- TARGET: "TARGET",
32
- },
33
- path: "../constants/target.js",
34
- },
35
- ],
36
- exports: {},
37
- inputs: [],
38
- meta: {},
39
- refs: {},
40
- state: {
41
- injectedStyleScript:
42
- "@builder.io/mitosis/method:get injectedStyleScript() {\n return `<${tagName(props,state)}>${props.styles}</${tagName(props,state)}>`;\n}",
43
- tagName:
44
- "@builder.io/mitosis/method:get tagName() {\n // NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.\n // https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027\n return 'sty' + 'le';\n}",
45
- },
46
- children: [
47
- {
48
- "@type": "@builder.io/mitosis/node",
49
- name: "Host",
50
- meta: {},
51
- scope: {},
52
- properties: {
53
- "q:host-pseudo": "",
54
- },
55
- bindings: {},
56
- children: [
57
- {
58
- "@type": "@builder.io/mitosis/node",
59
- name: "Show",
60
- meta: {
61
- else: {
62
- "@type": "@builder.io/mitosis/node",
63
- name: "state.tagName",
64
- meta: {},
65
- scope: {},
66
- properties: {},
67
- bindings: {},
68
- children: [
69
- {
70
- "@type": "@builder.io/mitosis/node",
71
- name: "div",
72
- meta: {},
73
- scope: {},
74
- properties: {},
75
- bindings: {
76
- _text: {
77
- code: "props.styles",
78
- },
79
- },
80
- children: [],
81
- },
82
- ],
83
- },
84
- },
85
- scope: {},
86
- properties: {},
87
- bindings: {
88
- when: {
89
- code: "TARGET === 'svelte'",
90
- },
91
- },
92
- children: [
93
- {
94
- "@type": "@builder.io/mitosis/node",
95
- name: "div",
96
- meta: {},
97
- scope: {},
98
- properties: {
99
- _text: "\n ",
100
- },
101
- bindings: {},
102
- children: [],
103
- },
104
- {
105
- "@type": "@builder.io/mitosis/node",
106
- name: "div",
107
- meta: {},
108
- scope: {},
109
- properties: {
110
- _text: "\n ",
111
- },
112
- bindings: {},
113
- children: [],
114
- },
115
- {
116
- "@type": "@builder.io/mitosis/node",
117
- name: "div",
118
- meta: {},
119
- scope: {},
120
- properties: {},
121
- bindings: {
122
- innerHTML: {
123
- code: "injectedStyleScript(props,state)",
124
- },
125
- },
126
- children: [],
127
- },
128
- {
129
- "@type": "@builder.io/mitosis/node",
130
- name: "div",
131
- meta: {},
132
- scope: {},
133
- properties: {
134
- _text: "\n ",
135
- },
136
- bindings: {},
137
- children: [],
138
- },
139
- ],
140
- },
141
- ],
142
- },
143
- ],
144
- hooks: {},
145
- context: {
146
- get: {},
147
- set: {},
148
- },
149
- name: "RenderInlinedStyles",
150
- subComponents: [],
151
- interfaces: ["interface Props {\n styles: string;\n}"],
152
- propsTypeRef: "Props",
153
- };
@@ -1,48 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- import { default as Button } from "../blocks/button/button.jsx";
18
- import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
19
- import { default as Columns } from "../blocks/columns/columns.jsx";
20
- import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
21
- import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
22
- import { default as Fragment } from "../blocks/fragment/fragment.jsx";
23
- import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
24
- import { default as Image } from "../blocks/image/image.jsx";
25
- import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
26
- import { default as Section } from "../blocks/section/section.jsx";
27
- import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
28
- import { default as Symbol } from "../blocks/symbol/symbol.jsx";
29
- import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
30
- import { default as Text } from "../blocks/text/text.jsx";
31
- import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
32
- import { default as Video } from "../blocks/video/video.jsx";
33
- import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info";
34
- import { default as embed } from "../blocks/embed/embed.jsx";
35
- const getDefaultRegisteredComponents = () => [
36
- __spreadValues({ component: Columns }, columnsComponentInfo),
37
- __spreadValues({ component: Image }, imageComponentInfo),
38
- __spreadValues({ component: Text }, textComponentInfo),
39
- __spreadValues({ component: Video }, videoComponentInfo),
40
- __spreadValues({ component: Symbol }, symbolComponentInfo),
41
- __spreadValues({ component: Button }, buttonComponentInfo),
42
- __spreadValues({ component: Section }, sectionComponentInfo),
43
- __spreadValues({ component: Fragment }, fragmentComponentInfo),
44
- __spreadValues({ component: embed }, embedComponentInfo)
45
- ];
46
- export {
47
- getDefaultRegisteredComponents
48
- };
@@ -1,21 +0,0 @@
1
- const SIZES = {
2
- small: {
3
- min: 320,
4
- default: 321,
5
- max: 640
6
- },
7
- medium: {
8
- min: 641,
9
- default: 642,
10
- max: 991
11
- },
12
- large: {
13
- min: 990,
14
- default: 991,
15
- max: 1200
16
- }
17
- };
18
- const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
19
- export {
20
- getMaxWidthQueryForSize
21
- };
@@ -1,4 +0,0 @@
1
- const TARGET = "qwik";
2
- export {
3
- TARGET
4
- };
@@ -1,5 +0,0 @@
1
- import { createContext } from "@builder.io/qwik";
2
- var stdin_default = createContext("Builder");
3
- export {
4
- stdin_default as default
5
- };
@@ -1,4 +0,0 @@
1
- const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
2
- export {
3
- camelToKebabCase
4
- };
@@ -1,6 +0,0 @@
1
- const convertStyleObject = (obj) => {
2
- return obj;
3
- };
4
- export {
5
- convertStyleObject
6
- };
@@ -1,28 +0,0 @@
1
- import { isBrowser } from "./is-browser.js";
2
- import { isEditing } from "./is-editing.js";
3
- function evaluate({
4
- code,
5
- context,
6
- state,
7
- event
8
- }) {
9
- if (code === "") {
10
- console.warn("Skipping evaluation of empty code block.");
11
- return;
12
- }
13
- const builder = {
14
- isEditing: isEditing(),
15
- isBrowser: isBrowser(),
16
- isServer: !isBrowser()
17
- };
18
- const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
19
- const useCode = useReturn ? `return (${code});` : code;
20
- try {
21
- return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
22
- } catch (e) {
23
- console.warn("Builder custom code error: ", e);
24
- }
25
- }
26
- export {
27
- evaluate
28
- };
@@ -1,7 +0,0 @@
1
- function capitalizeFirstLetter(string) {
2
- return string.charAt(0).toUpperCase() + string.slice(1);
3
- }
4
- const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
5
- export {
6
- getEventHandlerName
7
- };
@@ -1,23 +0,0 @@
1
- import { evaluate } from "./evaluate.js";
2
- import { getEventHandlerName } from "./event-handler-name.js";
3
- function getBlockActions(options) {
4
- var _a;
5
- const obj = {};
6
- const optionActions = (_a = options.block.actions) != null ? _a : {};
7
- for (const key in optionActions) {
8
- if (!optionActions.hasOwnProperty(key)) {
9
- continue;
10
- }
11
- const value = optionActions[key];
12
- obj[getEventHandlerName(key)] = (event) => evaluate({
13
- code: value,
14
- context: options.context,
15
- state: options.state,
16
- event
17
- });
18
- }
19
- return obj;
20
- }
21
- export {
22
- getBlockActions
23
- };
@@ -1,28 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- function getBlockComponentOptions(block) {
21
- var _a;
22
- return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
23
- builderBlock: block
24
- });
25
- }
26
- export {
27
- getBlockComponentOptions
28
- };
@@ -1,29 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- function getBlockProperties(block) {
21
- var _a;
22
- return __spreadProps(__spreadValues({}, block.properties), {
23
- "builder-id": block.id,
24
- class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
25
- });
26
- }
27
- export {
28
- getBlockProperties
29
- };
@@ -1,34 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
- var __hasOwnProp = Object.prototype.hasOwnProperty;
4
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
- var __spreadValues = (a, b) => {
7
- for (var prop in b || (b = {}))
8
- if (__hasOwnProp.call(b, prop))
9
- __defNormalProp(a, prop, b[prop]);
10
- if (__getOwnPropSymbols)
11
- for (var prop of __getOwnPropSymbols(b)) {
12
- if (__propIsEnum.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- }
15
- return a;
16
- };
17
- import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
18
- import { convertStyleObject } from "./convert-style-object.js";
19
- import { sanitizeBlockStyles } from "./sanitize-styles.js";
20
- function getBlockStyles(block) {
21
- var _a, _b, _c, _d, _e;
22
- const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
23
- if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
24
- styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
25
- }
26
- if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
27
- styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
28
- }
29
- sanitizeBlockStyles(styles);
30
- return styles;
31
- }
32
- export {
33
- getBlockStyles
34
- };
@@ -1,6 +0,0 @@
1
- function getBlockTag(block) {
2
- return block.tagName || "div";
3
- }
4
- export {
5
- getBlockTag
6
- };
@@ -1,13 +0,0 @@
1
- import { convertSearchParamsToQueryObject, getBuilderSearchParams } from ".";
2
- const querystring = "someotherValue=jklsjfdal&abc=klfdjklgfds&builder.cachebust=true&builder.preview=page&builder.noCache=true&__builder_editing__=true&builder.overrides.page=037948e52eaf4743afed464f02c70da4&builder.overrides.037948e52eaf4743afed464f02c70da4=037948e52eaf4743afed464f02c70da4&builder.overrides.page%3A%2F=037948e52eaf4743afed464f02c70da4&preview_theme_id=128854393017";
3
- const url = new URL(`localhost:3000/about-us?${querystring}`);
4
- describe("Get Builder SearchParams", () => {
5
- test("correctly converts URLSearchParams to object", () => {
6
- const output = convertSearchParamsToQueryObject(url.searchParams);
7
- expect(output).toMatchSnapshot();
8
- });
9
- test("correctly extracts all builder params from a query object", () => {
10
- const output = getBuilderSearchParams(convertSearchParamsToQueryObject(url.searchParams));
11
- expect(output).toMatchSnapshot();
12
- });
13
- });
@@ -1,33 +0,0 @@
1
- import { isBrowser } from "../is-browser";
2
- const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
3
- const convertSearchParamsToQueryObject = (searchParams) => {
4
- const options = {};
5
- searchParams.forEach((value, key) => {
6
- options[key] = value;
7
- });
8
- return options;
9
- };
10
- const getBuilderSearchParams = (options) => {
11
- const newOptions = {};
12
- Object.keys(options).forEach((key) => {
13
- if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
14
- const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "");
15
- newOptions[trimmedKey] = options[key];
16
- }
17
- });
18
- return newOptions;
19
- };
20
- const getBuilderSearchParamsFromWindow = () => {
21
- if (!isBrowser()) {
22
- return {};
23
- }
24
- const searchParams = new URLSearchParams(window.location.search);
25
- return getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams));
26
- };
27
- const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
28
- export {
29
- convertSearchParamsToQueryObject,
30
- getBuilderSearchParams,
31
- getBuilderSearchParamsFromWindow,
32
- normalizeSearchParams
33
- };
@@ -1,38 +0,0 @@
1
- const handleABTesting = (item, testGroups) => {
2
- if (item.variations && Object.keys(item.variations).length) {
3
- const testGroup = item.id ? testGroups[item.id] : void 0;
4
- const variationValue = testGroup ? item.variations[testGroup] : void 0;
5
- if (testGroup && variationValue) {
6
- item.data = variationValue.data;
7
- item.testVariationId = variationValue.id;
8
- item.testVariationName = variationValue.name;
9
- } else {
10
- let n = 0;
11
- const random = Math.random();
12
- let set = false;
13
- for (const id in item.variations) {
14
- const variation = item.variations[id];
15
- const testRatio = variation.testRatio;
16
- n += testRatio;
17
- if (random < n) {
18
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
19
- set = true;
20
- Object.assign(item, {
21
- data: variation.data,
22
- testVariationId: variation.id,
23
- testVariationName: variationName
24
- });
25
- }
26
- }
27
- if (!set) {
28
- Object.assign(item, {
29
- testVariationId: item.id,
30
- testVariationName: "Default"
31
- });
32
- }
33
- }
34
- }
35
- };
36
- export {
37
- handleABTesting
38
- };
@@ -1,31 +0,0 @@
1
- import { generateContentUrl } from ".";
2
- const testKey = "YJIGb4i01jvw0SRdL5Bt";
3
- const testModel = "page";
4
- const testId = "c1b81bab59704599b997574eb0736def";
5
- const options = {
6
- cachebust: "true",
7
- noCache: "true",
8
- "overrides.037948e52eaf4743afed464f02c70da4": "037948e52eaf4743afed464f02c70da4",
9
- "overrides.page": "037948e52eaf4743afed464f02c70da4",
10
- "overrides.page:/": "037948e52eaf4743afed464f02c70da4",
11
- preview: "page"
12
- };
13
- describe("Generate Content URL", () => {
14
- test("generates the proper value for a simple query", () => {
15
- const output = generateContentUrl({
16
- apiKey: testKey,
17
- model: testModel,
18
- query: { id: testId }
19
- });
20
- expect(output).toMatchSnapshot();
21
- });
22
- test("Handles overrides correctly", () => {
23
- const output = generateContentUrl({
24
- apiKey: testKey,
25
- model: testModel,
26
- query: { id: testId },
27
- options
28
- });
29
- expect(output).toMatchSnapshot();
30
- });
31
- });
@@ -1,99 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
8
- var __spreadValues = (a, b) => {
9
- for (var prop in b || (b = {}))
10
- if (__hasOwnProp.call(b, prop))
11
- __defNormalProp(a, prop, b[prop]);
12
- if (__getOwnPropSymbols)
13
- for (var prop of __getOwnPropSymbols(b)) {
14
- if (__propIsEnum.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- }
17
- return a;
18
- };
19
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- var __async = (__this, __arguments, generator) => {
21
- return new Promise((resolve, reject) => {
22
- var fulfilled = (value) => {
23
- try {
24
- step(generator.next(value));
25
- } catch (e) {
26
- reject(e);
27
- }
28
- };
29
- var rejected = (value) => {
30
- try {
31
- step(generator.throw(value));
32
- } catch (e) {
33
- reject(e);
34
- }
35
- };
36
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
37
- step((generator = generator.apply(__this, __arguments)).next());
38
- });
39
- };
40
- import { flatten } from "../../helpers/flatten.js";
41
- import {
42
- getBuilderSearchParamsFromWindow,
43
- normalizeSearchParams
44
- } from "../get-builder-search-params/index.js";
45
- import { getFetch } from "../get-fetch.js";
46
- import { handleABTesting } from "./ab-testing.js";
47
- const fetch$ = getFetch();
48
- function getContent(options) {
49
- return __async(this, null, function* () {
50
- return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
51
- });
52
- }
53
- const generateContentUrl = (options) => {
54
- const {
55
- limit = 1,
56
- userAttributes,
57
- query,
58
- noTraverse = false,
59
- model,
60
- apiKey
61
- } = options;
62
- const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
63
- const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
64
- const flattened = flatten(queryOptions);
65
- for (const key in flattened) {
66
- url.searchParams.set(key, String(flattened[key]));
67
- }
68
- if (userAttributes) {
69
- url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
70
- }
71
- if (query) {
72
- const flattened2 = flatten({ query });
73
- for (const key in flattened2) {
74
- url.searchParams.set(key, JSON.stringify(flattened2[key]));
75
- }
76
- }
77
- return url;
78
- };
79
- function getAllContent(options) {
80
- return __async(this, null, function* () {
81
- const url = generateContentUrl(options);
82
- const fetch = yield fetch$;
83
- if (!fetch) {
84
- throw new Error("Please install a fetch polyfill");
85
- }
86
- const content = yield fetch(url.href).then((res) => res.json());
87
- if (options.testGroups) {
88
- for (const item of content.results) {
89
- handleABTesting(item, options.testGroups);
90
- }
91
- }
92
- return content;
93
- });
94
- }
95
- export {
96
- generateContentUrl,
97
- getAllContent,
98
- getContent
99
- };
File without changes
@@ -1,33 +0,0 @@
1
- var __async = (__this, __arguments, generator) => {
2
- return new Promise((resolve, reject) => {
3
- var fulfilled = (value) => {
4
- try {
5
- step(generator.next(value));
6
- } catch (e) {
7
- reject(e);
8
- }
9
- };
10
- var rejected = (value) => {
11
- try {
12
- step(generator.throw(value));
13
- } catch (e) {
14
- reject(e);
15
- }
16
- };
17
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
18
- step((generator = generator.apply(__this, __arguments)).next());
19
- });
20
- };
21
- import { getGlobalThis } from "./get-global-this.js";
22
- function getFetch() {
23
- return __async(this, null, function* () {
24
- const globalFetch = getGlobalThis().fetch;
25
- if (typeof globalFetch === "undefined" && typeof global !== "undefined") {
26
- return import("node-fetch").then((d) => d.default || d);
27
- }
28
- return globalFetch.default || globalFetch;
29
- });
30
- }
31
- export {
32
- getFetch
33
- };