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

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 (91) hide show
  1. package/README.md +19 -0
  2. package/package.json +8 -1
  3. package/src/blocks/button/button.svelte +35 -48
  4. package/src/blocks/columns/columns.svelte +137 -103
  5. package/src/blocks/columns/component-info.js +26 -1
  6. package/src/blocks/custom-code/custom-code.svelte +58 -53
  7. package/src/blocks/embed/component-info.js +21 -1
  8. package/src/blocks/embed/embed.svelte +45 -57
  9. package/src/blocks/embed/helpers.js +9 -0
  10. package/src/blocks/form/form.svelte +313 -296
  11. package/src/blocks/fragment/fragment.svelte +9 -25
  12. package/src/blocks/image/component-info.js +48 -1
  13. package/src/blocks/image/image.helpers.js +48 -0
  14. package/src/blocks/image/image.svelte +146 -117
  15. package/src/blocks/img/img.svelte +48 -36
  16. package/src/blocks/input/input.svelte +30 -31
  17. package/src/blocks/raw-text/raw-text.svelte +12 -26
  18. package/src/blocks/section/section.svelte +30 -36
  19. package/src/blocks/select/select.svelte +30 -37
  20. package/src/blocks/submit-button/submit-button.svelte +12 -30
  21. package/src/blocks/symbol/component-info.js +1 -0
  22. package/src/blocks/symbol/symbol.svelte +88 -53
  23. package/src/blocks/text/text.svelte +8 -25
  24. package/src/blocks/textarea/textarea.svelte +16 -29
  25. package/src/blocks/util.js +7 -0
  26. package/src/blocks/video/video.svelte +88 -41
  27. package/src/components/render-block/block-styles.svelte +58 -51
  28. package/src/components/render-block/render-block.helpers.js +23 -0
  29. package/src/components/render-block/render-block.svelte +204 -160
  30. package/src/components/render-block/render-component.svelte +30 -0
  31. package/src/components/render-block/render-repeated-block.svelte +45 -0
  32. package/src/components/render-block/types.js +0 -0
  33. package/src/components/render-blocks.svelte +88 -80
  34. package/src/components/render-content/components/render-styles.svelte +59 -63
  35. package/src/components/render-content/index.js +4 -0
  36. package/src/components/render-content/render-content.svelte +316 -207
  37. package/src/components/render-inlined-styles.svelte +26 -48
  38. package/src/constants/builder-registered-components.js +51 -0
  39. package/src/constants/device-sizes.js +3 -21
  40. package/src/context/builder.context.js +7 -1
  41. package/src/functions/camel-to-kebab-case.js +4 -0
  42. package/src/functions/convert-style-object.js +6 -0
  43. package/src/functions/get-block-component-options.js +6 -1
  44. package/src/functions/get-block-styles.js +7 -4
  45. package/src/functions/get-builder-search-params/index.js +12 -1
  46. package/src/functions/get-content/ab-testing.js +38 -0
  47. package/src/functions/get-content/fn.test.js +1 -1
  48. package/src/functions/get-content/index.js +16 -58
  49. package/src/functions/get-content/types.js +0 -0
  50. package/src/functions/get-fetch.js +2 -2
  51. package/src/functions/get-processed-block.js +19 -8
  52. package/src/functions/get-processed-block.test.js +2 -1
  53. package/src/functions/register-component.js +45 -26
  54. package/src/functions/sanitize-styles.js +5 -0
  55. package/src/functions/track.js +71 -2
  56. package/src/helpers/cookie.js +59 -0
  57. package/src/helpers/css.js +12 -0
  58. package/src/helpers/flatten.js +34 -0
  59. package/src/helpers/localStorage.js +34 -0
  60. package/src/helpers/nullable.js +4 -0
  61. package/src/helpers/sessionId.js +26 -0
  62. package/src/helpers/time.js +5 -0
  63. package/src/helpers/url.js +10 -0
  64. package/src/helpers/url.test.js +15 -0
  65. package/src/helpers/uuid.js +13 -0
  66. package/src/helpers/visitorId.js +33 -0
  67. package/src/index-helpers/blocks-exports.js +10 -8
  68. package/src/scripts/init-editing.js +4 -5
  69. package/src/types/can-track.js +0 -0
  70. package/src/types/components.js +0 -0
  71. package/src/types/element.js +0 -0
  72. package/src/blocks/button/index.js +0 -7
  73. package/src/blocks/columns/index.js +0 -7
  74. package/src/blocks/custom-code/index.js +0 -7
  75. package/src/blocks/embed/index.js +0 -7
  76. package/src/blocks/form/index.js +0 -7
  77. package/src/blocks/fragment/index.js +0 -7
  78. package/src/blocks/image/index.js +0 -7
  79. package/src/blocks/img/index.js +0 -7
  80. package/src/blocks/input/index.js +0 -7
  81. package/src/blocks/raw-text/index.js +0 -7
  82. package/src/blocks/section/index.js +0 -7
  83. package/src/blocks/select/index.js +0 -7
  84. package/src/blocks/submit-button/index.js +0 -7
  85. package/src/blocks/symbol/index.js +0 -7
  86. package/src/blocks/text/index.js +0 -7
  87. package/src/blocks/textarea/index.js +0 -7
  88. package/src/blocks/video/index.js +0 -7
  89. package/src/components/error-boundary.svelte +0 -26
  90. package/src/functions/macro-eval.js +0 -5
  91. package/src/functions/previewing-model-name.js +0 -11
package/README.md ADDED
@@ -0,0 +1,19 @@
1
+ # Builder.io Svelte SDK (BETA)
2
+
3
+ This is the Svelte SDK. It is currently in beta.
4
+
5
+ ## Mitosis
6
+
7
+ This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
8
+
9
+ ## Feature Support
10
+
11
+ To check the status of the SDK, look at [these tables](../../README.md#feature-implementation).
12
+
13
+ ## Getting Started
14
+
15
+ ```
16
+ npm install @builder.io/sdk-svelte@dev
17
+ ```
18
+
19
+ Take a look at [our example repo](/examples/svelte/sveltekit) for how to use this SDK.
package/package.json CHANGED
@@ -1,13 +1,20 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.1-3",
4
+ "version": "0.0.1-32",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "src"
8
8
  ],
9
+ "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/BuilderIO/builder.git",
13
+ "directory": "packages/sdks/output/svelte"
14
+ },
9
15
  "main": "./src/index.js",
10
16
  "module": "./src/index.js",
17
+ "svelte": "./src/index.js",
11
18
  "exports": {
12
19
  ".": {
13
20
  "import": "./src/index.js",
@@ -1,49 +1,36 @@
1
- <script>
2
-
3
-
4
-
5
-
6
-
7
-
8
-
9
-
10
-
11
-
12
- export let attributes;
13
- export let text;
14
- export let link;
15
- export let openLinkInNewTab;
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
-
24
-
25
-
26
-
27
-
28
-
29
- </script>
30
-
31
-
32
-
33
-
34
- {#if link }
35
-
36
-
37
- <a {...attributes} role="button" href={link} target={openLinkInNewTab ? '_blank' : undefined} >
38
-
39
- {text}
40
-
41
- </a>
42
-
43
-
44
-
45
-
1
+ <script context="module" lang="ts">
2
+ export interface ButtonProps {
3
+ attributes?: any;
4
+ text?: string;
5
+ link?: string;
6
+ openLinkInNewTab?: boolean;
7
+ }
8
+ </script>
9
+
10
+ <script lang="ts">
11
+ export let attributes: ButtonProps["attributes"];
12
+ export let text: ButtonProps["text"];
13
+ export let link: ButtonProps["link"];
14
+ export let openLinkInNewTab: ButtonProps["openLinkInNewTab"];
15
+ </script>
16
+
17
+ {#if link}
18
+ <a
19
+ {...attributes}
20
+ role="button"
21
+ href={link}
22
+ target={openLinkInNewTab ? "_blank" : undefined}
23
+ >
24
+ {text}
25
+ </a>
46
26
  {:else}
47
- <span {...attributes}>{text}</span>
48
-
49
- {/if}
27
+ <button {...attributes} class="button">
28
+ {text}
29
+ </button>
30
+ {/if}
31
+
32
+ <style>
33
+ .button {
34
+ all: unset;
35
+ }
36
+ </style>
@@ -1,103 +1,137 @@
1
- <script>
2
-
3
-
4
-
5
-
6
- import RenderBlocks, { } from '../../components/render-blocks.svelte';
7
-
8
-
9
-
10
-
11
-
12
-
13
- export let space;
14
- export let columns;
15
- export let stackColumnsAt;
16
- export let reverseColumnsWhenStacked;
17
-
18
- function getGutterSize() {
19
- return typeof space === 'number' ? space || 0 : 20;
20
- }
21
-
22
- function getColumns() {
23
- return columns || [];
24
- }
25
-
26
- function getWidth(index) {
27
- const columns = getColumns();
28
- return columns[index]?.width || 100 / columns.length;
29
- }
30
-
31
- function getColumnCssWidth(index) {
32
- const columns = getColumns();
33
- const gutterSize = getGutterSize();
34
- const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
35
- return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
36
- }
37
-
38
- function maybeApplyForTablet(prop) {
39
- const _stackColumnsAt = stackColumnsAt || 'tablet';
40
-
41
- return _stackColumnsAt === 'tablet' ? prop : 'inherit';
42
- }
43
- $: columnsCssVars = () => {
44
- const flexDir = stackColumnsAt === 'never' ? 'inherit' : reverseColumnsWhenStacked ? 'column-reverse' : 'column';
45
- return {
46
- '--flex-dir': flexDir,
47
- '--flex-dir-tablet': maybeApplyForTablet(flexDir)
48
- };
49
- };
50
-
51
- $: columnCssVars = () => {
52
- const width = '100%';
53
- const marginLeft = '0';
54
- return {
55
- '--column-width': width,
56
- '--column-margin-left': marginLeft,
57
- '--column-width-tablet': maybeApplyForTablet(width),
58
- '--column-margin-left-tablet': maybeApplyForTablet(marginLeft)
59
- };
60
- };
61
-
62
-
63
-
64
-
65
-
66
-
67
-
68
-
69
-
70
-
71
- </script>
72
-
73
- <div class="builder-columns div" style={columnsCssVars()} >
74
-
75
-
76
- {#each columns as column, index }
77
- <div class="builder-column div-2" style={{
78
- width: getColumnCssWidth(index),
79
- marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
80
- ...columnCssVars()
81
- }} >
82
-
83
- <RenderBlocks blocks={column.blocks} ></RenderBlocks>
84
-
85
- </div>
86
- {/each}
87
-
88
-
89
- </div>
90
-
91
- <style>
92
- .div {
93
- display: flex;
94
- align-items: stretch;
95
- line-height: normal; }@media (max-width: 999px) { .div {
96
- flex-direction: var(--flex-dir-tablet); } }@media (max-width: 639px) { .div {
97
- flex-direction: var(--flex-dir); } }.div-2 {
98
- flex-grow: 1; }@media (max-width: 999px) { .div-2 {
99
- width: var(--column-width-tablet) !important;
100
- margin-left: var(--column-margin-left-tablet) !important; } }@media (max-width: 639px) { .div-2 {
101
- width: var(--column-width) !important;
102
- margin-left: var(--column-margin-left) !important; } }
103
- </style>
1
+ <script context="module" lang="ts">
2
+ type Column = {
3
+ blocks: any; // TODO: Implement this when support for dynamic CSS lands
4
+
5
+ width?: number;
6
+ };
7
+
8
+ type StackColumnsAt = "tablet" | "mobile" | "never";
9
+
10
+ export interface ColumnProps {
11
+ columns?: Column[];
12
+ builderBlock: BuilderBlock; // TODO: Implement this when support for dynamic CSS lands
13
+
14
+ space?: number; // TODO: Implement this when support for dynamic CSS lands
15
+
16
+ stackColumnsAt?: StackColumnsAt; // TODO: Implement this when support for dynamic CSS lands
17
+
18
+ reverseColumnsWhenStacked?: boolean;
19
+ }
20
+ </script>
21
+
22
+ <script lang="ts">
23
+ import RenderBlocks from "../../components/render-blocks.svelte";
24
+
25
+ export let space: ColumnProps["space"];
26
+ export let columns: ColumnProps["columns"];
27
+ export let stackColumnsAt: ColumnProps["stackColumnsAt"];
28
+ export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
29
+ export let builderBlock: ColumnProps["builderBlock"];
30
+
31
+ function mitosis_styling(node, vars) {
32
+ Object.entries(vars).forEach(([p, v]) => {
33
+ node.style[p] = v;
34
+ });
35
+ }
36
+
37
+ const getGutterSize = function getGutterSize() {
38
+ return typeof space === "number" ? space || 0 : 20;
39
+ };
40
+
41
+ const getColumns = function getColumns() {
42
+ return columns || [];
43
+ };
44
+
45
+ const getWidth = function getWidth(index) {
46
+ const columns = getColumns();
47
+ return columns[index]?.width || 100 / columns.length;
48
+ };
49
+
50
+ const getColumnCssWidth = function getColumnCssWidth(index) {
51
+ const columns = getColumns();
52
+ const gutterSize = getGutterSize();
53
+ const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
54
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
55
+ };
56
+
57
+ const maybeApplyForTablet = function maybeApplyForTablet(prop) {
58
+ const _stackColumnsAt = stackColumnsAt || "tablet";
59
+
60
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
61
+ };
62
+ $: columnsCssVars = () => {
63
+ const flexDir =
64
+ stackColumnsAt === "never"
65
+ ? "inherit"
66
+ : reverseColumnsWhenStacked
67
+ ? "column-reverse"
68
+ : "column";
69
+ return {
70
+ "--flex-dir": flexDir,
71
+ "--flex-dir-tablet": maybeApplyForTablet(flexDir),
72
+ };
73
+ };
74
+
75
+ $: columnCssVars = () => {
76
+ const width = "100%";
77
+ const marginLeft = "0";
78
+ return {
79
+ "--column-width": width,
80
+ "--column-margin-left": marginLeft,
81
+ "--column-width-tablet": maybeApplyForTablet(width),
82
+ "--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
83
+ };
84
+ };
85
+ </script>
86
+
87
+ <div use:mitosis_styling={columnsCssVars()} class="builder-columns div">
88
+ {#each columns as column, index (index)}
89
+ <div
90
+ use:mitosis_styling={{
91
+ width: getColumnCssWidth(index),
92
+ marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
93
+ ...columnCssVars(),
94
+ }}
95
+ class="builder-column div-2"
96
+ >
97
+ <RenderBlocks
98
+ blocks={column.blocks}
99
+ path={`component.options.columns.${index}.blocks`}
100
+ parent={builderBlock.id}
101
+ />
102
+ </div>
103
+ {/each}
104
+ </div>
105
+
106
+ <style>
107
+ .div {
108
+ display: flex;
109
+ align-items: stretch;
110
+ line-height: normal;
111
+ }
112
+ @media (max-width: 991px) {
113
+ .div {
114
+ flex-direction: var(--flex-dir-tablet);
115
+ }
116
+ }
117
+ @media (max-width: 639px) {
118
+ .div {
119
+ flex-direction: var(--flex-dir);
120
+ }
121
+ }
122
+ .div-2 {
123
+ flex-grow: 1;
124
+ }
125
+ @media (max-width: 991px) {
126
+ .div-2 {
127
+ width: var(--column-width-tablet) !important;
128
+ margin-left: var(--column-margin-left-tablet) !important;
129
+ }
130
+ }
131
+ @media (max-width: 639px) {
132
+ .div-2 {
133
+ width: var(--column-width) !important;
134
+ margin-left: var(--column-margin-left) !important;
135
+ }
136
+ }
137
+ </style>
@@ -1,3 +1,4 @@
1
+ import { markSerializable } from "../util";
1
2
  const componentInfo = {
2
3
  name: "Columns",
3
4
  builtIn: true,
@@ -186,7 +187,31 @@ const componentInfo = {
186
187
  ]
187
188
  }
188
189
  ],
189
- onChange: " function clearWidths() { columns.forEach(col => { col.delete('width'); }); } const columns = options.get('columns') as Array<Map<String, any>>; if (Array.isArray(columns)) { const containsColumnWithWidth = !!columns.find(col => col.get('width')); if (containsColumnWithWidth) { const containsColumnWithoutWidth = !!columns.find(col => !col.get('width')); if (containsColumnWithoutWidth) { clearWidths(); } else { const sumWidths = columns.reduce((memo, col) => { return memo + col.get('width'); }, 0); const widthsDontAddUp = sumWidths !== 100; if (widthsDontAddUp) { clearWidths(); } } } } "
190
+ onChange: markSerializable((options) => {
191
+ function clearWidths() {
192
+ columns.forEach((col) => {
193
+ col.delete("width");
194
+ });
195
+ }
196
+ const columns = options.get("columns");
197
+ if (Array.isArray(columns)) {
198
+ const containsColumnWithWidth = !!columns.find((col) => col.get("width"));
199
+ if (containsColumnWithWidth) {
200
+ const containsColumnWithoutWidth = !!columns.find((col) => !col.get("width"));
201
+ if (containsColumnWithoutWidth) {
202
+ clearWidths();
203
+ } else {
204
+ const sumWidths = columns.reduce((memo, col) => {
205
+ return memo + col.get("width");
206
+ }, 0);
207
+ const widthsDontAddUp = sumWidths !== 100;
208
+ if (widthsDontAddUp) {
209
+ clearWidths();
210
+ }
211
+ }
212
+ }
213
+ }
214
+ })
190
215
  },
191
216
  {
192
217
  name: "space",
@@ -1,64 +1,69 @@
1
- <script>
2
- import { onMount } from 'svelte'
3
-
4
-
5
-
6
-
7
-
1
+ <script context="module" lang="ts">
2
+ export interface CustomCodeProps {
3
+ code: string;
4
+ replaceNodes?: boolean;
5
+ }
6
+ </script>
8
7
 
9
-
8
+ <script lang="ts">
9
+ import { onMount } from "svelte";
10
10
 
11
-
12
- export let elem;
13
- export let replaceNodes;
14
- export let code;
15
-
16
- function findAndRunScripts() {
17
- // TODO: Move this function to standalone one in '@builder.io/utils'
18
- if (elem && typeof window !== 'undefined') {
19
- /** @type {HTMLScriptElement[]} */
20
- const scripts = elem.getElementsByTagName('script');
11
+ export let elem: CustomCodeProps["elem"];
12
+ export let replaceNodes: CustomCodeProps["replaceNodes"];
13
+ export let code: CustomCodeProps["code"];
21
14
 
22
- for (let i = 0; i < scripts.length; i++) {
23
- const script = scripts[i];
15
+ const findAndRunScripts = function findAndRunScripts() {
16
+ // TODO: Move this function to standalone one in '@builder.io/utils'
17
+ if (elem && typeof window !== "undefined") {
18
+ const scripts = elem.getElementsByTagName("script");
24
19
 
25
- if (script.src) {
26
- if (scriptsInserted.includes(script.src)) {
27
- continue;
28
- }
20
+ for (let i = 0; i < scripts.length; i++) {
21
+ const script = scripts[i];
29
22
 
30
- scriptsInserted.push(script.src);
31
- const newScript = document.createElement('script');
32
- newScript.async = true;
33
- newScript.src = script.src;
34
- document.head.appendChild(newScript);
35
- } else if (!script.type || ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(script.type)) {
36
- if (scriptsRun.includes(script.innerText)) {
37
- continue;
38
- }
23
+ if (script.src) {
24
+ if (scriptsInserted.includes(script.src)) {
25
+ continue;
26
+ }
27
+
28
+ scriptsInserted.push(script.src);
29
+ const newScript = document.createElement("script");
30
+ newScript.async = true;
31
+ newScript.src = script.src;
32
+ document.head.appendChild(newScript);
33
+ } else if (
34
+ !script.type ||
35
+ [
36
+ "text/javascript",
37
+ "application/javascript",
38
+ "application/ecmascript",
39
+ ].includes(script.type)
40
+ ) {
41
+ if (scriptsRun.includes(script.innerText)) {
42
+ continue;
43
+ }
39
44
 
40
- try {
41
- scriptsRun.push(script.innerText);
42
- new Function(script.innerText)();
43
- } catch (error) {
44
- console.warn('`CustomCode`: Error running script:', error);
45
+ try {
46
+ scriptsRun.push(script.innerText);
47
+ new Function(script.innerText)();
48
+ } catch (error) {
49
+ console.warn("`CustomCode`: Error running script:", error);
50
+ }
51
+ }
45
52
  }
46
53
  }
47
- }
48
- }
49
- }
50
-
51
-
52
-
53
-
54
- let scriptsInserted = [];
55
- let scriptsRun = [];
56
-
57
- onMount(() => { findAndRunScripts(); });
54
+ };
58
55
 
59
-
56
+ let scriptsInserted = [];
57
+ let scriptsRun = [];
60
58
 
61
-
62
- </script>
59
+ onMount(() => {
60
+ findAndRunScripts();
61
+ });
62
+ </script>
63
63
 
64
- <div bind:this={elem} class={'builder-custom-code' + (replaceNodes ? ' replace-nodes' : '')} >{@html code}</div>
64
+ <div
65
+ bind:this={elem}
66
+ class={"builder-custom-code" + (replaceNodes ? " replace-nodes" : "")}
67
+ >
68
+ {@html code}
69
+ </div>
@@ -1,3 +1,4 @@
1
+ import { markSerializable } from "../util";
1
2
  const componentInfo = {
2
3
  name: "Embed",
3
4
  static: true,
@@ -9,7 +10,26 @@ const componentInfo = {
9
10
  required: true,
10
11
  defaultValue: "",
11
12
  helperText: "e.g. enter a youtube url, google map, etc",
12
- onChange: " const url = options.get('url'); if (url) { options.set('content', 'Loading...'); // TODO: get this out of here! const apiKey = 'ae0e60e78201a3f2b0de4b'; return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`) .then(res => res.json()) .then(data => { if (options.get('url') === url) { if (data.html) { options.set('content', data.html); } else { options.set('content', 'Invalid url, please try another'); } } }) .catch(err => { options.set( 'content', 'There was an error embedding this URL, please try again or another URL' ); }); } else { options.delete('content'); } "
13
+ onChange: markSerializable((options) => {
14
+ const url = options.get("url");
15
+ if (url) {
16
+ options.set("content", "Loading...");
17
+ const apiKey = "ae0e60e78201a3f2b0de4b";
18
+ return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`).then((res) => res.json()).then((data) => {
19
+ if (options.get("url") === url) {
20
+ if (data.html) {
21
+ options.set("content", data.html);
22
+ } else {
23
+ options.set("content", "Invalid url, please try another");
24
+ }
25
+ }
26
+ }).catch((_err) => {
27
+ options.set("content", "There was an error embedding this URL, please try again or another URL");
28
+ });
29
+ } else {
30
+ options.delete("content");
31
+ }
32
+ })
13
33
  },
14
34
  {
15
35
  name: "content",