@builder.io/sdk-svelte 0.0.1-3 → 0.0.1-30

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 (77) hide show
  1. package/README.md +19 -0
  2. package/package.json +8 -1
  3. package/src/blocks/button/button.svelte +25 -47
  4. package/src/blocks/columns/columns.svelte +115 -102
  5. package/src/blocks/columns/component-info.js +25 -1
  6. package/src/blocks/custom-code/custom-code.svelte +59 -61
  7. package/src/blocks/embed/component-info.js +20 -1
  8. package/src/blocks/embed/embed.svelte +38 -56
  9. package/src/blocks/embed/helpers.js +9 -0
  10. package/src/blocks/form/form.svelte +264 -294
  11. package/src/blocks/fragment/fragment.svelte +1 -25
  12. package/src/blocks/image/component-info.js +47 -1
  13. package/src/blocks/image/image.helpers.js +48 -0
  14. package/src/blocks/image/image.svelte +126 -116
  15. package/src/blocks/img/img.svelte +25 -35
  16. package/src/blocks/input/input.svelte +17 -30
  17. package/src/blocks/raw-text/raw-text.svelte +4 -25
  18. package/src/blocks/section/section.svelte +20 -35
  19. package/src/blocks/select/select.svelte +16 -36
  20. package/src/blocks/submit-button/submit-button.svelte +4 -29
  21. package/src/blocks/symbol/component-info.js +1 -0
  22. package/src/blocks/symbol/symbol.svelte +67 -52
  23. package/src/blocks/text/text.svelte +1 -24
  24. package/src/blocks/textarea/textarea.svelte +5 -28
  25. package/src/blocks/video/video.svelte +60 -41
  26. package/src/components/render-block/block-styles.svelte +54 -50
  27. package/src/components/render-block/render-block.helpers.js +23 -0
  28. package/src/components/render-block/render-block.svelte +199 -159
  29. package/src/components/render-block/render-component.svelte +20 -0
  30. package/src/components/render-block/render-repeated-block.svelte +29 -0
  31. package/src/components/render-block/types.js +0 -0
  32. package/src/components/render-blocks.svelte +74 -79
  33. package/src/components/render-content/components/render-styles.svelte +43 -63
  34. package/src/components/render-content/index.js +4 -0
  35. package/src/components/render-content/render-content.svelte +266 -207
  36. package/src/components/render-inlined-styles.svelte +15 -43
  37. package/src/constants/builder-registered-components.js +48 -0
  38. package/src/constants/device-sizes.js +3 -21
  39. package/src/context/builder.context.js +7 -1
  40. package/src/functions/camel-to-kebab-case.js +4 -0
  41. package/src/functions/convert-style-object.js +6 -0
  42. package/src/functions/get-block-component-options.js +6 -1
  43. package/src/functions/get-block-styles.js +7 -4
  44. package/src/functions/get-builder-search-params/index.js +12 -1
  45. package/src/functions/get-content/ab-testing.js +38 -0
  46. package/src/functions/get-content/fn.test.js +1 -1
  47. package/src/functions/get-content/index.js +16 -58
  48. package/src/functions/get-content/types.js +0 -0
  49. package/src/functions/get-processed-block.js +15 -8
  50. package/src/functions/get-processed-block.test.js +2 -1
  51. package/src/functions/register-component.js +45 -26
  52. package/src/functions/sanitize-styles.js +5 -0
  53. package/src/helpers/css.js +12 -0
  54. package/src/helpers/flatten.js +34 -0
  55. package/src/index-helpers/blocks-exports.js +10 -8
  56. package/src/types/components.js +0 -0
  57. package/src/types/element.js +0 -0
  58. package/src/blocks/button/index.js +0 -7
  59. package/src/blocks/columns/index.js +0 -7
  60. package/src/blocks/custom-code/index.js +0 -7
  61. package/src/blocks/embed/index.js +0 -7
  62. package/src/blocks/form/index.js +0 -7
  63. package/src/blocks/fragment/index.js +0 -7
  64. package/src/blocks/image/index.js +0 -7
  65. package/src/blocks/img/index.js +0 -7
  66. package/src/blocks/input/index.js +0 -7
  67. package/src/blocks/raw-text/index.js +0 -7
  68. package/src/blocks/section/index.js +0 -7
  69. package/src/blocks/select/index.js +0 -7
  70. package/src/blocks/submit-button/index.js +0 -7
  71. package/src/blocks/symbol/index.js +0 -7
  72. package/src/blocks/text/index.js +0 -7
  73. package/src/blocks/textarea/index.js +0 -7
  74. package/src/blocks/video/index.js +0 -7
  75. package/src/components/error-boundary.svelte +0 -26
  76. package/src/functions/macro-eval.js +0 -5
  77. package/src/functions/previewing-model-name.js +0 -11
@@ -1,49 +1,21 @@
1
1
  <script>
2
-
3
-
4
-
5
-
6
- import { TARGET } from '../constants/target.js';
2
+ import { TARGET } from "../constants/target.js";
7
3
 
8
-
4
+ export let styles;
9
5
 
10
-
11
-
12
-
13
- export let styles;
14
-
15
-
16
- $: injectedStyleScript = () => {
17
- return `<${tagName()}>${styles}</${tagName()}>`;
18
- };
19
-
20
- $: tagName = () => {
21
- // NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
22
- // https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
23
- return 'sty' + 'le';
24
- };
25
-
26
-
27
-
28
-
29
-
30
-
31
-
32
-
33
-
34
-
35
- </script>
36
-
37
-
38
- {#if TARGET === 'svelte' }
39
-
40
-
41
- {@html injectedStyleScript()}
42
-
43
-
6
+ $: injectedStyleScript = () => {
7
+ return `<${tagName()}>${styles}</${tagName()}>`;
8
+ };
44
9
 
10
+ $: tagName = () => {
11
+ // NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
12
+ // https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
13
+ return "sty" + "le";
14
+ };
15
+ </script>
45
16
 
17
+ {#if TARGET === "svelte"}
18
+ {@html injectedStyleScript()}
46
19
  {:else}
47
- <svelte:component this={tagName()} >{styles}</svelte:component>
48
-
49
- {/if}
20
+ <svelte:component this={tagName()}>{styles}</svelte:component>
21
+ {/if}
@@ -0,0 +1,48 @@
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.svelte";
18
+ import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
19
+ import { default as Columns } from "../blocks/columns/columns.svelte";
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.svelte";
23
+ import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
24
+ import { default as Image } from "../blocks/image/image.svelte";
25
+ import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
26
+ import { default as Section } from "../blocks/section/section.svelte";
27
+ import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
28
+ import { default as Symbol } from "../blocks/symbol/symbol.svelte";
29
+ import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
30
+ import { default as Text } from "../blocks/text/text.svelte";
31
+ import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
32
+ import { default as Video } from "../blocks/video/video.svelte";
33
+ import { componentInfo as embedComponentInfo } from "../blocks/embed/component-info";
34
+ import { default as embed } from "../blocks/embed/embed.svelte";
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,10 +1,4 @@
1
- const sizeNames = ["xsmall", "small", "medium", "large"];
2
- const sizes = {
3
- xsmall: {
4
- min: 0,
5
- default: 0,
6
- max: 0
7
- },
1
+ const SIZES = {
8
2
  small: {
9
3
  min: 320,
10
4
  default: 321,
@@ -19,21 +13,9 @@ const sizes = {
19
13
  min: 990,
20
14
  default: 991,
21
15
  max: 1200
22
- },
23
- getWidthForSize(size) {
24
- return this[size].default;
25
- },
26
- getSizeForWidth(width) {
27
- for (const size of sizeNames) {
28
- const value = this[size];
29
- if (width <= value.max) {
30
- return size;
31
- }
32
- }
33
- return "large";
34
16
  }
35
17
  };
18
+ const getMaxWidthQueryForSize = (size) => `@media (max-width: ${SIZES[size].max}px)`;
36
19
  export {
37
- sizeNames,
38
- sizes
20
+ getMaxWidthQueryForSize
39
21
  };
@@ -1,6 +1,12 @@
1
1
  const key = Symbol();
2
2
  var stdin_default = {
3
- Builder: { content: null, context: {}, state: {}, apiKey: null },
3
+ Builder: {
4
+ content: null,
5
+ context: {},
6
+ state: {},
7
+ apiKey: null,
8
+ registeredComponents: {}
9
+ },
4
10
  key
5
11
  };
6
12
  export {
@@ -0,0 +1,4 @@
1
+ const camelToKebabCase = (string) => string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
2
+ export {
3
+ camelToKebabCase
4
+ };
@@ -0,0 +1,6 @@
1
+ const convertStyleObject = (obj) => {
2
+ return obj;
3
+ };
4
+ export {
5
+ convertStyleObject
6
+ };
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,9 +16,12 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  function getBlockComponentOptions(block) {
18
21
  var _a;
19
- return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
22
+ return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
23
+ builderBlock: block
24
+ });
20
25
  }
21
26
  export {
22
27
  getBlockComponentOptions
@@ -14,16 +14,19 @@ var __spreadValues = (a, b) => {
14
14
  }
15
15
  return a;
16
16
  };
17
- import { sizes } from "../constants/device-sizes.js";
17
+ import { getMaxWidthQueryForSize } from "../constants/device-sizes.js";
18
+ import { convertStyleObject } from "./convert-style-object.js";
19
+ import { sanitizeBlockStyles } from "./sanitize-styles.js";
18
20
  function getBlockStyles(block) {
19
21
  var _a, _b, _c, _d, _e;
20
- const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
22
+ const styles = __spreadValues(__spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large)), block.styles);
21
23
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
22
- styles[`@media (max-width: ${sizes.medium})`] = (_c = block.responsiveStyles) == null ? void 0 : _c.medium;
24
+ styles[getMaxWidthQueryForSize("medium")] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
23
25
  }
24
26
  if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
25
- styles[`@media (max-width: ${sizes.small})`] = (_e = block.responsiveStyles) == null ? void 0 : _e.small;
27
+ styles[getMaxWidthQueryForSize("small")] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
26
28
  }
29
+ sanitizeBlockStyles(styles);
27
30
  return styles;
28
31
  }
29
32
  export {
@@ -1,3 +1,4 @@
1
+ import { isBrowser } from "../is-browser";
1
2
  const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
2
3
  const convertSearchParamsToQueryObject = (searchParams) => {
3
4
  const options = {};
@@ -16,7 +17,17 @@ const getBuilderSearchParams = (options) => {
16
17
  });
17
18
  return newOptions;
18
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;
19
28
  export {
20
29
  convertSearchParamsToQueryObject,
21
- getBuilderSearchParams
30
+ getBuilderSearchParams,
31
+ getBuilderSearchParamsFromWindow,
32
+ normalizeSearchParams
22
33
  };
@@ -0,0 +1,38 @@
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,4 +1,4 @@
1
- import { generateContentUrl } from "..js";
1
+ import { generateContentUrl } from ".";
2
2
  const testKey = "YJIGb4i01jvw0SRdL5Bt";
3
3
  const testModel = "page";
4
4
  const testId = "c1b81bab59704599b997574eb0736def";
@@ -37,20 +37,14 @@ var __async = (__this, __arguments, generator) => {
37
37
  step((generator = generator.apply(__this, __arguments)).next());
38
38
  });
39
39
  };
40
+ import { flatten } from "../../helpers/flatten.js";
41
+ import {
42
+ getBuilderSearchParamsFromWindow,
43
+ normalizeSearchParams
44
+ } from "../get-builder-search-params/index.js";
40
45
  import { getFetch } from "../get-fetch.js";
46
+ import { handleABTesting } from "./ab-testing.js";
41
47
  const fetch$ = getFetch();
42
- function flatten(object, path = null, separator = ".") {
43
- return Object.keys(object).reduce((acc, key) => {
44
- const value = object[key];
45
- const newPath = [path, key].filter(Boolean).join(separator);
46
- const isObject = [
47
- typeof value === "object",
48
- value !== null,
49
- !(Array.isArray(value) && value.length === 0)
50
- ].every(Boolean);
51
- return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
52
- }, {});
53
- }
54
48
  function getContent(options) {
55
49
  return __async(this, null, function* () {
56
50
  return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
@@ -66,67 +60,31 @@ const generateContentUrl = (options) => {
66
60
  apiKey
67
61
  } = options;
68
62
  const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
69
- if (options.options) {
70
- const flattened = flatten(options.options);
71
- for (const key in flattened) {
72
- url.searchParams.set(key, String(flattened[key]));
73
- }
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]));
74
67
  }
75
68
  if (userAttributes) {
76
69
  url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
77
70
  }
78
71
  if (query) {
79
- const flattened = flatten({ query });
80
- for (const key in flattened) {
81
- url.searchParams.set(key, JSON.stringify(flattened[key]));
72
+ const flattened2 = flatten({ query });
73
+ for (const key in flattened2) {
74
+ url.searchParams.set(key, JSON.stringify(flattened2[key]));
82
75
  }
83
76
  }
84
77
  return url;
85
78
  };
86
- const handleABTesting = (content, testGroups) => {
87
- for (const item of content.results) {
88
- if (item.variations && Object.keys(item.variations).length) {
89
- const testGroup = testGroups[item.id];
90
- const variationValue = item.variations[testGroup];
91
- if (testGroup && variationValue) {
92
- item.data = variationValue.data;
93
- item.testVariationId = variationValue.id;
94
- item.testVariationName = variationValue.name;
95
- } else {
96
- let n = 0;
97
- const random = Math.random();
98
- let set = false;
99
- for (const id in item.variations) {
100
- const variation = item.variations[id];
101
- const testRatio = variation.testRatio;
102
- n += testRatio;
103
- if (random < n) {
104
- const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
105
- set = true;
106
- Object.assign(item, {
107
- data: variation.data,
108
- testVariationId: variation.id,
109
- testVariationName: variationName
110
- });
111
- }
112
- }
113
- if (!set) {
114
- Object.assign(item, {
115
- testVariationId: item.id,
116
- testVariationName: "Default"
117
- });
118
- }
119
- }
120
- }
121
- }
122
- };
123
79
  function getAllContent(options) {
124
80
  return __async(this, null, function* () {
125
81
  const url = generateContentUrl(options);
126
82
  const fetch = yield fetch$;
127
83
  const content = yield fetch(url.href).then((res) => res.json());
128
84
  if (options.testGroups) {
129
- handleABTesting(content, options.testGroups);
85
+ for (const item of content.results) {
86
+ handleABTesting(item, options.testGroups);
87
+ }
130
88
  }
131
89
  return content;
132
90
  });
File without changes
@@ -20,9 +20,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
20
  import { evaluate } from "./evaluate.js";
21
21
  import { set } from "./set.js";
22
22
  import { transformBlock } from "./transform-block.js";
23
- function getProcessedBlock(options) {
24
- const { state, context } = options;
25
- const block = transformBlock(options.block);
23
+ const evaluateBindings = ({
24
+ block,
25
+ context,
26
+ state
27
+ }) => {
26
28
  if (!block.bindings) {
27
29
  return block;
28
30
  }
@@ -32,14 +34,19 @@ function getProcessedBlock(options) {
32
34
  });
33
35
  for (const binding in block.bindings) {
34
36
  const expression = block.bindings[binding];
35
- const value = evaluate({
36
- code: expression,
37
- state,
38
- context
39
- });
37
+ const value = evaluate({ code: expression, state, context });
40
38
  set(copied, binding, value);
41
39
  }
42
40
  return copied;
41
+ };
42
+ function getProcessedBlock(options) {
43
+ const { state, context } = options;
44
+ const block = transformBlock(options.block);
45
+ if (evaluateBindings) {
46
+ return evaluateBindings({ block, state, context });
47
+ } else {
48
+ return block;
49
+ }
43
50
  }
44
51
  export {
45
52
  getProcessedBlock
@@ -20,7 +20,8 @@ test("Can process bindings", () => {
20
20
  const processed = getProcessedBlock({
21
21
  block,
22
22
  context: {},
23
- state: { test: "hello" }
23
+ state: { test: "hello" },
24
+ evaluateBindings: true
24
25
  });
25
26
  expect(processed).not.toEqual(block);
26
27
  expect((_a = processed.properties) == null ? void 0 : _a.foo).toEqual("baz");
@@ -17,37 +17,56 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { isBrowser } from "./is-browser.js";
21
- const components = {};
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ const components = [];
22
33
  function registerComponent(component, info) {
23
- var _a;
24
- components[info.name] = { component, info };
25
- if (isBrowser()) {
26
- const sendInfo = prepareComponentInfoToSend(info);
27
- (_a = window.parent) == null ? void 0 : _a.postMessage({
28
- type: "builder.registerComponent",
29
- data: sendInfo
30
- }, "*");
31
- }
34
+ components.push(__spreadValues({ component }, info));
35
+ console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
32
36
  return component;
33
37
  }
34
- function prepareComponentInfoToSend(info) {
35
- return __spreadValues(__spreadValues({}, info), info.inputs && {
36
- inputs: info.inputs.map((input) => {
37
- const keysToConvertFnToString = ["onChange", "showIf"];
38
- for (const key of keysToConvertFnToString) {
39
- if (input[key] && typeof input[key] === "function") {
40
- const fn = input[key];
41
- input = __spreadProps(__spreadValues({}, input), {
42
- [key]: `return (${fn.toString()}).apply(this, arguments)`
43
- });
44
- }
45
- }
46
- return input;
47
- })
38
+ const createRegisterComponentMessage = (_a) => {
39
+ var _b = _a, {
40
+ component: _
41
+ } = _b, info = __objRest(_b, [
42
+ "component"
43
+ ]);
44
+ return {
45
+ type: "builder.registerComponent",
46
+ data: prepareComponentInfoToSend(info)
47
+ };
48
+ };
49
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
50
+ const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
51
+ const serializeFn = (fnValue) => {
52
+ const fnStr = fnValue.toString().trim();
53
+ const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
54
+ return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
55
+ };
56
+ const prepareComponentInfoToSend = (_c) => {
57
+ var _d = _c, {
58
+ inputs
59
+ } = _d, info = __objRest(_d, [
60
+ "inputs"
61
+ ]);
62
+ return __spreadProps(__spreadValues({}, fastClone(info)), {
63
+ inputs: inputs == null ? void 0 : inputs.map((input) => Object.entries(input).reduce((acc, [key, value]) => __spreadProps(__spreadValues({}, acc), {
64
+ [key]: serializeValue(value)
65
+ }), {}))
48
66
  });
49
- }
67
+ };
50
68
  export {
51
69
  components,
70
+ createRegisterComponentMessage,
52
71
  registerComponent
53
72
  };
@@ -0,0 +1,5 @@
1
+ const sanitizeBlockStyles = (_styles) => {
2
+ };
3
+ export {
4
+ sanitizeBlockStyles
5
+ };
@@ -0,0 +1,12 @@
1
+ import { camelToKebabCase } from "../functions/camel-to-kebab-case";
2
+ const convertStyleMaptoCSS = (style) => {
3
+ const cssProps = Object.entries(style).map(([key, value]) => {
4
+ if (typeof value === "string") {
5
+ return `${camelToKebabCase(key)}: ${value};`;
6
+ }
7
+ });
8
+ return cssProps.join("\n");
9
+ };
10
+ export {
11
+ convertStyleMaptoCSS
12
+ };
@@ -0,0 +1,34 @@
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 flatten(object, path = null, separator = ".") {
21
+ return Object.keys(object).reduce((acc, key) => {
22
+ const value = object[key];
23
+ const newPath = [path, key].filter(Boolean).join(separator);
24
+ const isObject = [
25
+ typeof value === "object",
26
+ value !== null,
27
+ !(Array.isArray(value) && value.length === 0)
28
+ ].every(Boolean);
29
+ return isObject ? __spreadValues(__spreadValues({}, acc), flatten(value, newPath, separator)) : __spreadProps(__spreadValues({}, acc), { [newPath]: value });
30
+ }, {});
31
+ }
32
+ export {
33
+ flatten
34
+ };
@@ -1,17 +1,19 @@
1
- import { default as default2 } from "../blocks/columns";
2
- import { default as default3 } from "../blocks/image";
3
- import { default as default4 } from "../blocks/text";
4
- import { default as default5 } from "../blocks/video";
5
- import { default as default6 } from "../blocks/symbol";
6
- import { default as default7 } from "../blocks/button";
7
- import { default as default8 } from "../blocks/section";
8
- import { default as default9 } from "../blocks/fragment";
1
+ import { default as default2 } from "../blocks/columns/columns.svelte";
2
+ import { default as default3 } from "../blocks/image/image.svelte";
3
+ import { default as default4 } from "../blocks/text/text.svelte";
4
+ import { default as default5 } from "../blocks/video/video.svelte";
5
+ import { default as default6 } from "../blocks/symbol/symbol.svelte";
6
+ import { default as default7 } from "../blocks/button/button.svelte";
7
+ import { default as default8 } from "../blocks/section/section.svelte";
8
+ import { default as default9 } from "../blocks/fragment/fragment.svelte";
9
9
  import { default as default10 } from "../components/render-content/render-content.svelte";
10
+ import { default as default11 } from "../components/render-blocks.svelte";
10
11
  export {
11
12
  default7 as Button,
12
13
  default2 as Columns,
13
14
  default9 as Fragment,
14
15
  default3 as Image,
16
+ default11 as RenderBlocks,
15
17
  default10 as RenderContent,
16
18
  default8 as Section,
17
19
  default6 as Symbol,
File without changes
File without changes
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import component from "./button.svelte";
3
- import { componentInfo } from "./component-info.js";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import component from "./columns.svelte";
3
- import { componentInfo } from "./component-info.js";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./custom-code.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./embed.svelte";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };