@builder.io/sdk-svelte 0.0.4 → 0.0.5

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 (118) hide show
  1. package/package/--package.json +3 -2
  2. package/package.json +3 -2
  3. package/src/blocks/BaseText.svelte +27 -0
  4. package/src/blocks/button/button.svelte +36 -0
  5. package/src/blocks/button/component-info.ts +42 -0
  6. package/src/blocks/columns/columns.svelte +148 -0
  7. package/src/blocks/columns/component-info.ts +254 -0
  8. package/src/blocks/custom-code/component-info.ts +31 -0
  9. package/src/blocks/custom-code/custom-code.svelte +66 -0
  10. package/src/blocks/embed/component-info.ts +53 -0
  11. package/src/blocks/embed/embed.svelte +51 -0
  12. package/src/blocks/embed/helpers.ts +8 -0
  13. package/src/blocks/form/component-info.ts +282 -0
  14. package/src/blocks/form/form.svelte +332 -0
  15. package/src/blocks/fragment/component-info.ts +10 -0
  16. package/src/blocks/fragment/fragment.svelte +12 -0
  17. package/src/blocks/image/component-info.ts +170 -0
  18. package/src/blocks/image/image.helpers.ts +75 -0
  19. package/src/blocks/image/image.svelte +145 -0
  20. package/src/blocks/img/component-info.ts +21 -0
  21. package/src/blocks/img/img.svelte +51 -0
  22. package/src/blocks/input/component-info.ts +78 -0
  23. package/src/blocks/input/input.svelte +34 -0
  24. package/src/blocks/raw-text/component-info.ts +15 -0
  25. package/src/blocks/raw-text/raw-text.svelte +16 -0
  26. package/src/blocks/section/component-info.ts +50 -0
  27. package/src/blocks/section/section.svelte +34 -0
  28. package/src/blocks/select/component-info.ts +61 -0
  29. package/src/blocks/select/select.svelte +34 -0
  30. package/src/blocks/submit-button/component-info.ts +32 -0
  31. package/src/blocks/submit-button/submit-button.svelte +15 -0
  32. package/src/blocks/symbol/component-info.ts +43 -0
  33. package/src/blocks/symbol/symbol.svelte +100 -0
  34. package/src/blocks/text/component-info.ts +24 -0
  35. package/src/blocks/text/text.svelte +11 -0
  36. package/src/blocks/textarea/component-info.ts +48 -0
  37. package/src/blocks/textarea/textarea.svelte +19 -0
  38. package/src/blocks/util.ts +6 -0
  39. package/src/blocks/video/component-info.ts +109 -0
  40. package/src/blocks/video/video.svelte +102 -0
  41. package/src/components/render-block/block-styles.svelte +62 -0
  42. package/src/components/render-block/render-block.helpers.ts +27 -0
  43. package/src/components/render-block/render-block.svelte +228 -0
  44. package/src/components/render-block/render-component-with-context.svelte +38 -0
  45. package/src/components/render-block/render-component.svelte +35 -0
  46. package/src/components/render-block/render-repeated-block.svelte +53 -0
  47. package/src/components/render-block/types.ts +7 -0
  48. package/src/components/render-blocks.svelte +104 -0
  49. package/src/components/render-content/components/render-styles.svelte +80 -0
  50. package/src/components/render-content/index.ts +1 -0
  51. package/src/components/render-content/render-content.svelte +354 -0
  52. package/src/components/render-inlined-styles.svelte +26 -0
  53. package/src/constants/builder-registered-components.ts +42 -0
  54. package/src/constants/device-sizes.ts +28 -0
  55. package/src/constants/target.ts +2 -0
  56. package/src/context/builder.context.ts +13 -0
  57. package/src/context/types.ts +23 -0
  58. package/src/functions/camel-to-kebab-case.ts +2 -0
  59. package/src/functions/evaluate.ts +52 -0
  60. package/src/functions/event-handler-name.ts +6 -0
  61. package/src/functions/extract-text-styles.ts +39 -0
  62. package/src/functions/fast-clone.ts +5 -0
  63. package/src/functions/get-block-actions-handler.ts +19 -0
  64. package/src/functions/get-block-actions.ts +25 -0
  65. package/src/functions/get-block-component-options.ts +12 -0
  66. package/src/functions/get-block-properties.ts +11 -0
  67. package/src/functions/get-block-tag.ts +7 -0
  68. package/src/functions/get-builder-search-params/fn.test.ts +19 -0
  69. package/src/functions/get-builder-search-params/index.ts +48 -0
  70. package/src/functions/get-content/ab-testing.ts +132 -0
  71. package/src/functions/get-content/fn.test.ts +35 -0
  72. package/src/functions/get-content/index.ts +77 -0
  73. package/src/functions/get-content/types.ts +36 -0
  74. package/src/functions/get-fetch.ts +14 -0
  75. package/src/functions/get-global-this.ts +15 -0
  76. package/src/functions/get-processed-block.test.ts +33 -0
  77. package/src/functions/get-processed-block.ts +54 -0
  78. package/src/functions/get-react-native-block-styles.ts +30 -0
  79. package/src/functions/if-target.ts +20 -0
  80. package/src/functions/is-browser.ts +3 -0
  81. package/src/functions/is-editing.ts +7 -0
  82. package/src/functions/is-iframe.ts +5 -0
  83. package/src/functions/is-previewing.ts +14 -0
  84. package/src/functions/mark-mutable.ts +7 -0
  85. package/src/functions/on-change.test.ts +23 -0
  86. package/src/functions/on-change.ts +29 -0
  87. package/src/functions/register-component.ts +67 -0
  88. package/src/functions/register.ts +46 -0
  89. package/src/functions/sanitize-react-native-block-styles.ts +65 -0
  90. package/src/functions/set-editor-settings.ts +16 -0
  91. package/src/functions/set.test.ts +19 -0
  92. package/src/functions/set.ts +26 -0
  93. package/src/functions/track.ts +90 -0
  94. package/src/functions/transform-block.ts +6 -0
  95. package/src/helpers/ab-tests.ts +22 -0
  96. package/src/helpers/cookie.ts +102 -0
  97. package/src/helpers/css.ts +33 -0
  98. package/src/helpers/flatten.ts +24 -0
  99. package/src/helpers/localStorage.ts +38 -0
  100. package/src/helpers/nullable.ts +4 -0
  101. package/src/helpers/sessionId.ts +34 -0
  102. package/src/helpers/time.ts +4 -0
  103. package/src/helpers/url.test.ts +16 -0
  104. package/src/helpers/url.ts +12 -0
  105. package/src/helpers/uuid.ts +17 -0
  106. package/src/helpers/visitorId.ts +38 -0
  107. package/src/index-helpers/blocks-exports.ts +10 -0
  108. package/src/index-helpers/top-of-file.ts +4 -0
  109. package/src/index.ts +12 -0
  110. package/src/scripts/init-editing.ts +102 -0
  111. package/src/types/builder-block.ts +58 -0
  112. package/src/types/builder-content.ts +39 -0
  113. package/src/types/can-track.ts +3 -0
  114. package/src/types/components.ts +188 -0
  115. package/src/types/deep-partial.ts +7 -0
  116. package/src/types/element.ts +60 -0
  117. package/src/types/targets.ts +6 -0
  118. package/src/types/typescript.ts +7 -0
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.3",
4
+ "version": "0.0.4",
5
5
  "type": "module",
6
6
  "files": [
7
- "package"
7
+ "package",
8
+ "src"
8
9
  ],
9
10
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
10
11
  "repository": {
package/package.json CHANGED
@@ -1,10 +1,11 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.4",
4
+ "version": "0.0.5",
5
5
  "type": "module",
6
6
  "files": [
7
- "package"
7
+ "package",
8
+ "src"
8
9
  ],
9
10
  "homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/svelte#readme",
10
11
  "repository": {
@@ -0,0 +1,27 @@
1
+ <script context="module" lang="ts">
2
+ export interface BaseTextProps {
3
+ text: string;
4
+ }
5
+ </script>
6
+
7
+ <script lang="ts">
8
+ import { getContext, setContext } from "svelte";
9
+
10
+ import BuilderContext from "../context/builder.context.js";
11
+
12
+ export let text: BaseTextProps["text"];
13
+
14
+ function mitosis_styling(node, vars) {
15
+ Object.entries(vars || {}).forEach(([p, v]) => {
16
+ if (p.startsWith("--")) {
17
+ node.style.setProperty(p, v);
18
+ } else {
19
+ node.style[p] = v;
20
+ }
21
+ });
22
+ }
23
+
24
+ let builderContext = getContext(BuilderContext.key);
25
+ </script>
26
+
27
+ <span use:mitosis_styling={builderContext.inheritedStyles}>{text}</span>
@@ -0,0 +1,36 @@
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>
26
+ {:else}
27
+ <button {...attributes} class="button">
28
+ {text}
29
+ </button>
30
+ {/if}
31
+
32
+ <style>
33
+ .button {
34
+ all: unset;
35
+ }
36
+ </style>
@@ -0,0 +1,42 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+
3
+ export const componentInfo: ComponentInfo = {
4
+ name: 'Core:Button',
5
+ builtIn: true,
6
+ image:
7
+ 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',
8
+ defaultStyles: {
9
+ // TODO: make min width more intuitive and set one
10
+ appearance: 'none',
11
+ paddingTop: '15px',
12
+ paddingBottom: '15px',
13
+ paddingLeft: '25px',
14
+ paddingRight: '25px',
15
+ backgroundColor: '#000000',
16
+ color: 'white',
17
+ borderRadius: '4px',
18
+ textAlign: 'center',
19
+ cursor: 'pointer',
20
+ },
21
+ inputs: [
22
+ {
23
+ name: 'text',
24
+ type: 'text',
25
+ defaultValue: 'Click me!',
26
+ bubble: true,
27
+ },
28
+ {
29
+ name: 'link',
30
+ type: 'url',
31
+ bubble: true,
32
+ },
33
+ {
34
+ name: 'openLinkInNewTab',
35
+ type: 'boolean',
36
+ defaultValue: false,
37
+ friendlyName: 'Open link in new tab',
38
+ },
39
+ ],
40
+ static: true,
41
+ noWrap: true,
42
+ };
@@ -0,0 +1,148 @@
1
+ <script context="module" lang="ts">
2
+ import type { BuilderBlock } from "../../types/builder-block";
3
+
4
+ type CSS = {
5
+ [key: string]: string;
6
+ };
7
+
8
+ type Column = {
9
+ blocks: any;
10
+ // TODO: Implement this when support for dynamic CSS lands
11
+ width?: number;
12
+ };
13
+
14
+ type StackColumnsAt = "tablet" | "mobile" | "never";
15
+
16
+ export interface ColumnProps {
17
+ columns?: Column[];
18
+ builderBlock: BuilderBlock;
19
+
20
+ // TODO: Implement this when support for dynamic CSS lands
21
+ space?: number;
22
+ // TODO: Implement this when support for dynamic CSS lands
23
+ stackColumnsAt?: StackColumnsAt;
24
+ // TODO: Implement this when support for dynamic CSS lands
25
+ reverseColumnsWhenStacked?: boolean;
26
+ }
27
+ </script>
28
+
29
+ <script lang="ts">
30
+ import RenderBlocks from "../../components/render-blocks.svelte";
31
+ import { markMutable } from "../../functions/mark-mutable";
32
+
33
+ export let space: ColumnProps["space"];
34
+ export let columns: ColumnProps["columns"];
35
+ export let stackColumnsAt: ColumnProps["stackColumnsAt"];
36
+ export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
37
+ export let builderBlock: ColumnProps["builderBlock"];
38
+
39
+ function mitosis_styling(node, vars) {
40
+ Object.entries(vars || {}).forEach(([p, v]) => {
41
+ if (p.startsWith("--")) {
42
+ node.style.setProperty(p, v);
43
+ } else {
44
+ node.style[p] = v;
45
+ }
46
+ });
47
+ }
48
+
49
+ function getGutterSize() {
50
+ return typeof space === "number" ? space || 0 : 20;
51
+ }
52
+ function getColumns() {
53
+ return columns || [];
54
+ }
55
+ function getWidth(index) {
56
+ const columns = getColumns();
57
+ return columns[index]?.width || 100 / columns.length;
58
+ }
59
+ function getColumnCssWidth(index) {
60
+ const columns = getColumns();
61
+ const gutterSize = getGutterSize();
62
+ const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
63
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
64
+ }
65
+ function maybeApplyForTablet(prop) {
66
+ const _stackColumnsAt = stackColumnsAt || "tablet";
67
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
68
+ }
69
+ $: columnsCssVars = () => {
70
+ const flexDir =
71
+ stackColumnsAt === "never"
72
+ ? "inherit"
73
+ : reverseColumnsWhenStacked
74
+ ? "column-reverse"
75
+ : "column";
76
+ return {
77
+ "--flex-dir": flexDir,
78
+ "--flex-dir-tablet": maybeApplyForTablet(flexDir),
79
+ };
80
+ };
81
+ $: columnCssVars = () => {
82
+ const width = "100%";
83
+ const marginLeft = "0";
84
+ return {
85
+ "--column-width": width,
86
+ "--column-margin-left": marginLeft,
87
+ "--column-width-tablet": maybeApplyForTablet(width),
88
+ "--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
89
+ };
90
+ };
91
+ </script>
92
+
93
+ <div use:mitosis_styling={columnsCssVars()} class="builder-columns div">
94
+ {#each columns as column, index (index)}
95
+ <div
96
+ use:mitosis_styling={{
97
+ width: getColumnCssWidth(index),
98
+ marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
99
+ ...columnCssVars(),
100
+ }}
101
+ class="builder-column div-2"
102
+ >
103
+ <RenderBlocks
104
+ blocks={markMutable(column.blocks)}
105
+ path={`component.options.columns.${index}.blocks`}
106
+ parent={builderBlock.id}
107
+ styleProp={{
108
+ flexGrow: "1",
109
+ }}
110
+ />
111
+ </div>
112
+ {/each}
113
+ </div>
114
+
115
+ <style>
116
+ .div {
117
+ display: flex;
118
+ align-items: stretch;
119
+ line-height: normal;
120
+ }
121
+ @media (max-width: 991px) {
122
+ .div {
123
+ flex-direction: var(--flex-dir-tablet);
124
+ }
125
+ }
126
+ @media (max-width: 639px) {
127
+ .div {
128
+ flex-direction: var(--flex-dir);
129
+ }
130
+ }
131
+ .div-2 {
132
+ display: flex;
133
+ flex-direction: column;
134
+ align-items: stretch;
135
+ }
136
+ @media (max-width: 991px) {
137
+ .div-2 {
138
+ width: var(--column-width-tablet) !important;
139
+ margin-left: var(--column-margin-left-tablet) !important;
140
+ }
141
+ }
142
+ @media (max-width: 639px) {
143
+ .div-2 {
144
+ width: var(--column-width) !important;
145
+ margin-left: var(--column-margin-left) !important;
146
+ }
147
+ }
148
+ </style>
@@ -0,0 +1,254 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ import { markSerializable } from '../util.js';
3
+
4
+ export const componentInfo: ComponentInfo = {
5
+ // TODO: ways to statically preprocess JSON for references, functions, etc
6
+ name: 'Columns',
7
+ builtIn: true,
8
+ inputs: [
9
+ {
10
+ name: 'columns',
11
+ type: 'array',
12
+ broadcast: true,
13
+ subFields: [
14
+ {
15
+ name: 'blocks',
16
+ type: 'array',
17
+ hideFromUI: true,
18
+ defaultValue: [
19
+ {
20
+ '@type': '@builder.io/sdk:Element',
21
+ responsiveStyles: {
22
+ large: {
23
+ display: 'flex',
24
+ flexDirection: 'column',
25
+ alignItems: 'stretch',
26
+ flexShrink: '0',
27
+ position: 'relative',
28
+ marginTop: '30px',
29
+ textAlign: 'center',
30
+ lineHeight: 'normal',
31
+ height: 'auto',
32
+ minHeight: '20px',
33
+ minWidth: '20px',
34
+ overflow: 'hidden',
35
+ },
36
+ },
37
+ component: {
38
+ name: 'Image',
39
+ options: {
40
+ image:
41
+ 'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
42
+ backgroundPosition: 'center',
43
+ backgroundSize: 'cover',
44
+ aspectRatio: 0.7004048582995948,
45
+ },
46
+ },
47
+ },
48
+ {
49
+ '@type': '@builder.io/sdk:Element',
50
+ responsiveStyles: {
51
+ large: {
52
+ display: 'flex',
53
+ flexDirection: 'column',
54
+ alignItems: 'stretch',
55
+ flexShrink: '0',
56
+ position: 'relative',
57
+ marginTop: '30px',
58
+ textAlign: 'center',
59
+ lineHeight: 'normal',
60
+ height: 'auto',
61
+ },
62
+ },
63
+ component: {
64
+ name: 'Text',
65
+ options: {
66
+ text: '<p>Enter some text...</p>',
67
+ },
68
+ },
69
+ },
70
+ ],
71
+ },
72
+ {
73
+ name: 'width',
74
+ type: 'number',
75
+ hideFromUI: true,
76
+ helperText: 'Width %, e.g. set to 50 to fill half of the space',
77
+ },
78
+ {
79
+ name: 'link',
80
+ type: 'url',
81
+ helperText:
82
+ 'Optionally set a url that clicking this column will link to',
83
+ },
84
+ ],
85
+ defaultValue: [
86
+ {
87
+ blocks: [
88
+ {
89
+ '@type': '@builder.io/sdk:Element',
90
+ responsiveStyles: {
91
+ large: {
92
+ display: 'flex',
93
+ flexDirection: 'column',
94
+ alignItems: 'stretch',
95
+ flexShrink: '0',
96
+ position: 'relative',
97
+ marginTop: '30px',
98
+ textAlign: 'center',
99
+ lineHeight: 'normal',
100
+ height: 'auto',
101
+ minHeight: '20px',
102
+ minWidth: '20px',
103
+ overflow: 'hidden',
104
+ },
105
+ },
106
+ component: {
107
+ name: 'Image',
108
+ options: {
109
+ image:
110
+ 'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
111
+ backgroundPosition: 'center',
112
+ backgroundSize: 'cover',
113
+ aspectRatio: 0.7004048582995948,
114
+ },
115
+ },
116
+ },
117
+ {
118
+ '@type': '@builder.io/sdk:Element',
119
+ responsiveStyles: {
120
+ large: {
121
+ display: 'flex',
122
+ flexDirection: 'column',
123
+ alignItems: 'stretch',
124
+ flexShrink: '0',
125
+ position: 'relative',
126
+ marginTop: '30px',
127
+ textAlign: 'center',
128
+ lineHeight: 'normal',
129
+ height: 'auto',
130
+ },
131
+ },
132
+ component: {
133
+ name: 'Text',
134
+ options: {
135
+ text: '<p>Enter some text...</p>',
136
+ },
137
+ },
138
+ },
139
+ ],
140
+ },
141
+ {
142
+ blocks: [
143
+ {
144
+ '@type': '@builder.io/sdk:Element',
145
+ responsiveStyles: {
146
+ large: {
147
+ display: 'flex',
148
+ flexDirection: 'column',
149
+ alignItems: 'stretch',
150
+ flexShrink: '0',
151
+ position: 'relative',
152
+ marginTop: '30px',
153
+ textAlign: 'center',
154
+ lineHeight: 'normal',
155
+ height: 'auto',
156
+ minHeight: '20px',
157
+ minWidth: '20px',
158
+ overflow: 'hidden',
159
+ },
160
+ },
161
+ component: {
162
+ name: 'Image',
163
+ options: {
164
+ image:
165
+ 'https://builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d',
166
+ backgroundPosition: 'center',
167
+ backgroundSize: 'cover',
168
+ aspectRatio: 0.7004048582995948,
169
+ },
170
+ },
171
+ },
172
+ {
173
+ '@type': '@builder.io/sdk:Element',
174
+ responsiveStyles: {
175
+ large: {
176
+ display: 'flex',
177
+ flexDirection: 'column',
178
+ alignItems: 'stretch',
179
+ flexShrink: '0',
180
+ position: 'relative',
181
+ marginTop: '30px',
182
+ textAlign: 'center',
183
+ lineHeight: 'normal',
184
+ height: 'auto',
185
+ },
186
+ },
187
+ component: {
188
+ name: 'Text',
189
+ options: {
190
+ text: '<p>Enter some text...</p>',
191
+ },
192
+ },
193
+ },
194
+ ],
195
+ },
196
+ ],
197
+ onChange: markSerializable((options: Map<string, any>) => {
198
+ function clearWidths() {
199
+ columns.forEach((col) => {
200
+ col.delete('width');
201
+ });
202
+ }
203
+
204
+ const columns: Array<Map<string, any>> = options.get('columns');
205
+
206
+ if (Array.isArray(columns)) {
207
+ const containsColumnWithWidth = !!columns.find((col) =>
208
+ col.get('width')
209
+ );
210
+
211
+ if (containsColumnWithWidth) {
212
+ const containsColumnWithoutWidth = !!columns.find(
213
+ (col) => !col.get('width')
214
+ );
215
+ if (containsColumnWithoutWidth) {
216
+ clearWidths();
217
+ } else {
218
+ const sumWidths = columns.reduce((memo, col) => {
219
+ return memo + col.get('width');
220
+ }, 0);
221
+ const widthsDontAddUp = sumWidths !== 100;
222
+ if (widthsDontAddUp) {
223
+ clearWidths();
224
+ }
225
+ }
226
+ }
227
+ }
228
+ }),
229
+ },
230
+ {
231
+ name: 'space',
232
+ type: 'number',
233
+ defaultValue: 20,
234
+ helperText: 'Size of gap between columns',
235
+ advanced: true,
236
+ },
237
+ {
238
+ name: 'stackColumnsAt',
239
+ type: 'string',
240
+ defaultValue: 'tablet',
241
+ helperText: 'Convert horizontal columns to vertical at what device size',
242
+ enum: ['tablet', 'mobile', 'never'],
243
+ advanced: true,
244
+ },
245
+ {
246
+ name: 'reverseColumnsWhenStacked',
247
+ type: 'boolean',
248
+ defaultValue: false,
249
+ helperText:
250
+ 'When stacking columns for mobile devices, reverse the ordering',
251
+ advanced: true,
252
+ },
253
+ ],
254
+ };
@@ -0,0 +1,31 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+
3
+ export const componentInfo: ComponentInfo = {
4
+ name: 'Custom Code',
5
+ static: true,
6
+ builtIn: true,
7
+ requiredPermissions: ['editCode'],
8
+ inputs: [
9
+ {
10
+ name: 'code',
11
+ type: 'html',
12
+ required: true,
13
+ defaultValue: '<p>Hello there, I am custom HTML code!</p>',
14
+ code: true,
15
+ },
16
+ {
17
+ name: 'replaceNodes',
18
+ type: 'boolean',
19
+ helperText: 'Preserve server rendered dom nodes',
20
+ advanced: true,
21
+ },
22
+ {
23
+ name: 'scriptsClientOnly',
24
+ type: 'boolean',
25
+ defaultValue: false,
26
+ helperText:
27
+ 'Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads',
28
+ advanced: true,
29
+ },
30
+ ],
31
+ };
@@ -0,0 +1,66 @@
1
+ <script context="module" lang="ts">
2
+ export interface CustomCodeProps {
3
+ code: string;
4
+ replaceNodes?: boolean;
5
+ }
6
+ </script>
7
+
8
+ <script lang="ts">
9
+ import { onMount } from "svelte";
10
+
11
+ export let replaceNodes: CustomCodeProps["replaceNodes"];
12
+ export let code: CustomCodeProps["code"];
13
+
14
+ function findAndRunScripts() {
15
+ // TODO: Move this function to standalone one in '@builder.io/utils'
16
+ if (elem && elem.getElementsByTagName && typeof window !== "undefined") {
17
+ const scripts = elem.getElementsByTagName("script");
18
+ for (let i = 0; i < scripts.length; i++) {
19
+ const script = scripts[i];
20
+ if (script.src) {
21
+ if (scriptsInserted.includes(script.src)) {
22
+ continue;
23
+ }
24
+ scriptsInserted.push(script.src);
25
+ const newScript = document.createElement("script");
26
+ newScript.async = true;
27
+ newScript.src = script.src;
28
+ document.head.appendChild(newScript);
29
+ } else if (
30
+ !script.type ||
31
+ [
32
+ "text/javascript",
33
+ "application/javascript",
34
+ "application/ecmascript",
35
+ ].includes(script.type)
36
+ ) {
37
+ if (scriptsRun.includes(script.innerText)) {
38
+ continue;
39
+ }
40
+ try {
41
+ scriptsRun.push(script.innerText);
42
+ new Function(script.innerText)();
43
+ } catch (error) {
44
+ console.warn("`CustomCode`: Error running script:", error);
45
+ }
46
+ }
47
+ }
48
+ }
49
+ }
50
+
51
+ let elem;
52
+
53
+ let scriptsInserted = [];
54
+ let scriptsRun = [];
55
+
56
+ onMount(() => {
57
+ findAndRunScripts();
58
+ });
59
+ </script>
60
+
61
+ <div
62
+ bind:this={elem}
63
+ class={"builder-custom-code" + (replaceNodes ? " replace-nodes" : "")}
64
+ >
65
+ {@html code}
66
+ </div>
@@ -0,0 +1,53 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ import { markSerializable } from '../util.js';
3
+
4
+ export const componentInfo: ComponentInfo = {
5
+ name: 'Embed',
6
+ static: true,
7
+ builtIn: true,
8
+ inputs: [
9
+ {
10
+ name: 'url',
11
+ type: 'url',
12
+ required: true,
13
+ defaultValue: '',
14
+ helperText: 'e.g. enter a youtube url, google map, etc',
15
+ onChange: markSerializable((options: Map<string, any>) => {
16
+ const url = options.get('url');
17
+ if (url) {
18
+ options.set('content', 'Loading...');
19
+ // TODO: get this out of here!
20
+ const apiKey = 'ae0e60e78201a3f2b0de4b';
21
+ return fetch(
22
+ `https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`
23
+ )
24
+ .then((res) => res.json())
25
+ .then((data) => {
26
+ if (options.get('url') === url) {
27
+ if (data.html) {
28
+ options.set('content', data.html);
29
+ } else {
30
+ options.set('content', 'Invalid url, please try another');
31
+ }
32
+ }
33
+ })
34
+ .catch((_err) => {
35
+ options.set(
36
+ 'content',
37
+ 'There was an error embedding this URL, please try again or another URL'
38
+ );
39
+ });
40
+ } else {
41
+ options.delete('content');
42
+ }
43
+ }),
44
+ },
45
+ {
46
+ name: 'content',
47
+ type: 'html',
48
+ defaultValue:
49
+ '<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',
50
+ hideFromUI: true,
51
+ },
52
+ ],
53
+ };