@builder.io/sdk-svelte 0.0.1-2 → 0.0.1-20
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.
- package/README.md +19 -0
- package/package.json +22 -4
- package/src/blocks/button/button.svelte +1 -0
- package/src/blocks/columns/columns.svelte +13 -13
- package/src/blocks/custom-code/custom-code.svelte +3 -3
- package/src/blocks/embed/embed.svelte +3 -3
- package/src/blocks/form/form.svelte +5 -5
- package/src/blocks/fragment/fragment.svelte +1 -0
- package/src/blocks/image/image.svelte +9 -8
- package/src/blocks/img/img.svelte +2 -2
- package/src/blocks/input/input.svelte +1 -1
- package/src/blocks/raw-text/raw-text.svelte +1 -0
- package/src/blocks/section/section.svelte +1 -0
- package/src/blocks/select/select.svelte +1 -1
- package/src/blocks/submit-button/submit-button.svelte +1 -0
- package/src/blocks/symbol/component-info.js +1 -0
- package/src/blocks/symbol/symbol.svelte +11 -6
- package/src/blocks/text/text.svelte +1 -0
- package/src/blocks/textarea/textarea.svelte +1 -0
- package/src/blocks/video/video.svelte +1 -0
- package/src/components/render-block/block-styles.svelte +41 -27
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.svelte +58 -49
- package/src/components/render-block/render-component.svelte +58 -0
- package/src/components/render-blocks.svelte +29 -10
- package/src/components/render-content/components/render-styles.svelte +6 -6
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.svelte +72 -33
- package/src/components/render-inlined-styles.svelte +4 -2
- package/src/constants/builder-registered-components.js +45 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/context/builder.context.js +1 -1
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/evaluate.js +2 -2
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-block-actions.js +2 -2
- package/src/functions/get-block-component-options.js +6 -1
- package/src/functions/get-block-styles.js +3 -3
- package/src/functions/get-content/index.js +1 -1
- package/src/functions/get-fetch.js +1 -1
- package/src/functions/get-processed-block.js +3 -3
- package/src/functions/get-processed-block.test.js +1 -1
- package/src/functions/if-target.js +1 -1
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +2 -2
- package/src/functions/on-change.test.js +1 -1
- package/src/functions/previewing-model-name.js +1 -1
- package/src/functions/register-component.js +30 -13
- package/src/functions/register.js +1 -1
- package/src/functions/set-editor-settings.js +1 -1
- package/src/functions/set.test.js +1 -1
- package/src/functions/track.js +3 -3
- package/src/helpers/css.js +12 -0
- package/src/index-helpers/blocks-exports.js +10 -8
- package/src/index.js +10 -10
- package/src/scripts/init-editing.js +4 -4
- package/src/types/components.js +0 -0
- package/src/types/element.js +0 -0
- package/src/blocks/button/index.js +0 -7
- package/src/blocks/columns/index.js +0 -7
- package/src/blocks/custom-code/index.js +0 -7
- package/src/blocks/embed/index.js +0 -7
- package/src/blocks/form/index.js +0 -7
- package/src/blocks/fragment/index.js +0 -7
- package/src/blocks/image/index.js +0 -7
- package/src/blocks/img/index.js +0 -7
- package/src/blocks/input/index.js +0 -7
- package/src/blocks/raw-text/index.js +0 -7
- package/src/blocks/section/index.js +0 -7
- package/src/blocks/select/index.js +0 -7
- package/src/blocks/submit-button/index.js +0 -7
- package/src/blocks/symbol/index.js +0 -7
- package/src/blocks/text/index.js +0 -7
- package/src/blocks/textarea/index.js +0 -7
- package/src/blocks/video/index.js +0 -7
- package/src/components/error-boundary.svelte +0 -26
- package/src/functions/macro-eval.js +0 -5
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,12 +1,30 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.0.1-
|
|
5
|
-
"
|
|
6
|
-
|
|
4
|
+
"version": "0.0.1-20",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"files": [
|
|
7
|
+
"src"
|
|
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
|
+
},
|
|
15
|
+
"main": "./src/index.js",
|
|
16
|
+
"module": "./src/index.js",
|
|
17
|
+
"svelte": "./src/index.js",
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"import": "./src/index.js",
|
|
21
|
+
"require": "./src/index.js"
|
|
22
|
+
}
|
|
7
23
|
},
|
|
8
|
-
"main": "src/index.js",
|
|
9
24
|
"scripts": {
|
|
10
25
|
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"node-fetch": "^2.6.1"
|
|
11
29
|
}
|
|
12
30
|
}
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
6
|
+
import RenderBlocks from '../../components/render-blocks.svelte';
|
|
7
|
+
|
|
8
8
|
|
|
9
9
|
|
|
10
10
|
|
|
@@ -15,31 +15,31 @@ export let columns;
|
|
|
15
15
|
export let stackColumnsAt;
|
|
16
16
|
export let reverseColumnsWhenStacked;
|
|
17
17
|
|
|
18
|
-
function getGutterSize() {
|
|
18
|
+
const getGutterSize = function getGutterSize() {
|
|
19
19
|
return typeof space === 'number' ? space || 0 : 20;
|
|
20
|
-
}
|
|
20
|
+
};
|
|
21
21
|
|
|
22
|
-
function getColumns() {
|
|
22
|
+
const getColumns = function getColumns() {
|
|
23
23
|
return columns || [];
|
|
24
|
-
}
|
|
24
|
+
};
|
|
25
25
|
|
|
26
|
-
function getWidth(index) {
|
|
26
|
+
const getWidth = function getWidth(index) {
|
|
27
27
|
const columns = getColumns();
|
|
28
28
|
return columns[index]?.width || 100 / columns.length;
|
|
29
|
-
}
|
|
29
|
+
};
|
|
30
30
|
|
|
31
|
-
function getColumnCssWidth(index) {
|
|
31
|
+
const getColumnCssWidth = function getColumnCssWidth(index) {
|
|
32
32
|
const columns = getColumns();
|
|
33
33
|
const gutterSize = getGutterSize();
|
|
34
34
|
const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
|
|
35
35
|
return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
|
|
36
|
-
}
|
|
36
|
+
};
|
|
37
37
|
|
|
38
|
-
function maybeApplyForTablet(prop) {
|
|
38
|
+
const maybeApplyForTablet = function maybeApplyForTablet(prop) {
|
|
39
39
|
const _stackColumnsAt = stackColumnsAt || 'tablet';
|
|
40
40
|
|
|
41
41
|
return _stackColumnsAt === 'tablet' ? prop : 'inherit';
|
|
42
|
-
}
|
|
42
|
+
};
|
|
43
43
|
$: columnsCssVars = () => {
|
|
44
44
|
const flexDir = stackColumnsAt === 'never' ? 'inherit' : reverseColumnsWhenStacked ? 'column-reverse' : 'column';
|
|
45
45
|
return {
|
|
@@ -78,7 +78,7 @@ return {
|
|
|
78
78
|
width: getColumnCssWidth(index),
|
|
79
79
|
marginLeft: `${index === 0 ? 0 : getGutterSize()}px`,
|
|
80
80
|
...columnCssVars()
|
|
81
|
-
}} >
|
|
81
|
+
}} key={index} >
|
|
82
82
|
|
|
83
83
|
<RenderBlocks blocks={column.blocks} ></RenderBlocks>
|
|
84
84
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -13,10 +14,9 @@
|
|
|
13
14
|
export let replaceNodes;
|
|
14
15
|
export let code;
|
|
15
16
|
|
|
16
|
-
function findAndRunScripts() {
|
|
17
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
17
18
|
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
18
19
|
if (elem && typeof window !== 'undefined') {
|
|
19
|
-
/** @type {HTMLScriptElement[]} */
|
|
20
20
|
const scripts = elem.getElementsByTagName('script');
|
|
21
21
|
|
|
22
22
|
for (let i = 0; i < scripts.length; i++) {
|
|
@@ -46,7 +46,7 @@ if (elem && typeof window !== 'undefined') {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
}
|
|
49
|
+
};
|
|
50
50
|
|
|
51
51
|
|
|
52
52
|
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -12,10 +13,9 @@
|
|
|
12
13
|
export let elem;
|
|
13
14
|
export let content;
|
|
14
15
|
|
|
15
|
-
function findAndRunScripts() {
|
|
16
|
+
const findAndRunScripts = function findAndRunScripts() {
|
|
16
17
|
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
17
18
|
if (elem && typeof window !== 'undefined') {
|
|
18
|
-
/** @type {HTMLScriptElement[]} */
|
|
19
19
|
const scripts = elem.getElementsByTagName('script');
|
|
20
20
|
|
|
21
21
|
for (let i = 0; i < scripts.length; i++) {
|
|
@@ -45,7 +45,7 @@ if (elem && typeof window !== 'undefined') {
|
|
|
45
45
|
}
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
|
-
}
|
|
48
|
+
};
|
|
49
49
|
|
|
50
50
|
|
|
51
51
|
|
|
@@ -3,9 +3,9 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
|
|
6
|
+
import RenderBlock from '../../components/render-block/render-block.svelte';
|
|
7
|
+
import { isEditing } from '../../functions/is-editing.js';
|
|
8
|
+
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
|
|
@@ -31,7 +31,7 @@ export let errorMessage;
|
|
|
31
31
|
export let sendingMessage;
|
|
32
32
|
export let successMessage;
|
|
33
33
|
|
|
34
|
-
function onSubmit(event) {
|
|
34
|
+
const onSubmit = function onSubmit(event) {
|
|
35
35
|
const sendWithJs = sendWithJs || sendSubmissionsTo === 'email';
|
|
36
36
|
|
|
37
37
|
if (sendSubmissionsTo === 'zapier') {
|
|
@@ -232,7 +232,7 @@ if (sendSubmissionsTo === 'zapier') {
|
|
|
232
232
|
formState = 'error';
|
|
233
233
|
});
|
|
234
234
|
}
|
|
235
|
-
}
|
|
235
|
+
};
|
|
236
236
|
$: submissionState = () => {
|
|
237
237
|
return isEditing() && previewState || formState;
|
|
238
238
|
};
|
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
|
|
9
10
|
|
|
10
11
|
|
|
@@ -34,30 +35,30 @@ export let builderBlock;
|
|
|
34
35
|
|
|
35
36
|
</script>
|
|
36
37
|
|
|
37
|
-
<div
|
|
38
|
+
<div class="div" >
|
|
38
39
|
|
|
39
40
|
<picture >
|
|
40
41
|
|
|
41
|
-
<img loading="lazy"
|
|
42
|
+
<img loading="lazy" alt={altText} role={altText ? 'presentation' : undefined} style={{
|
|
42
43
|
objectPosition: backgroundSize || 'center',
|
|
43
44
|
objectFit: backgroundSize || 'cover'
|
|
44
|
-
}} class={'builder-image' + (className ? ' ' + className : '')} src={image} srcset={srcset} sizes={sizes} />
|
|
45
|
+
}} class={'builder-image' + (className ? ' ' + className : '') + 'img'} src={image} srcset={srcset} sizes={sizes} />
|
|
45
46
|
|
|
46
47
|
|
|
47
|
-
<source
|
|
48
|
+
<source srcset={srcset} />
|
|
48
49
|
|
|
49
50
|
</picture>
|
|
50
51
|
|
|
51
52
|
|
|
52
53
|
|
|
53
54
|
{#if aspectRatio && !(fitContent && builderBlock?.children?.length) }
|
|
55
|
+
|
|
56
|
+
|
|
54
57
|
<div class="builder-image-sizer div-2" style={{
|
|
55
58
|
paddingTop: aspectRatio * 100 + '%'
|
|
56
|
-
}} >
|
|
57
|
-
|
|
58
|
-
{' '}
|
|
59
|
+
}} ></div>
|
|
59
60
|
|
|
60
|
-
|
|
61
|
+
|
|
61
62
|
|
|
62
63
|
|
|
63
64
|
{/if}
|
|
@@ -3,10 +3,10 @@
|
|
|
3
3
|
import { afterUpdate } from 'svelte'
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
9
|
-
|
|
6
|
+
import RenderContent from '../../components/render-content/render-content.svelte';
|
|
7
|
+
import BuilderContext from '../../context/builder.context';
|
|
8
|
+
import { getContent } from '../../functions/get-content/index.js';
|
|
9
|
+
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
import { getContext, setContext } from "svelte";
|
|
@@ -25,7 +25,9 @@ let content = null;
|
|
|
25
25
|
|
|
26
26
|
onMount(() => { content = symbol?.content; });
|
|
27
27
|
|
|
28
|
-
|
|
28
|
+
|
|
29
|
+
function onUpdateFn_0() {
|
|
30
|
+
const symbolToUse = symbol;
|
|
29
31
|
|
|
30
32
|
if (symbolToUse && !symbolToUse.content && !content && symbolToUse.model) {
|
|
31
33
|
getContent({
|
|
@@ -37,7 +39,10 @@ getContent({
|
|
|
37
39
|
}).then(response => {
|
|
38
40
|
content = response;
|
|
39
41
|
});
|
|
40
|
-
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
$: onUpdateFn_0(...[props.symbol?.content, props.symbol?.model, props.symbol?.entry, state.content])
|
|
45
|
+
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
</script>
|
|
@@ -3,41 +3,46 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import
|
|
7
|
-
|
|
6
|
+
import { TARGET } from '../../constants/target.js';
|
|
7
|
+
import BuilderContext from '../../context/builder.context';
|
|
8
|
+
import { getProcessedBlock } from '../../functions/get-processed-block.js';
|
|
9
|
+
import RenderInlinedStyles from '../render-inlined-styles.svelte';
|
|
10
|
+
import { convertStyleMaptoCSS } from '../../helpers/css.js';
|
|
11
|
+
import { getMaxWidthQueryForSize } from '../../constants/device-sizes.js';
|
|
12
|
+
|
|
8
13
|
|
|
9
14
|
|
|
10
|
-
|
|
15
|
+
import { getContext, setContext } from "svelte";
|
|
11
16
|
|
|
12
17
|
|
|
13
18
|
export let block;
|
|
14
19
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return '';
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
let str = `.${block.id} {`;
|
|
27
|
-
|
|
28
|
-
for (const key in styleObject) {
|
|
29
|
-
const value = styleObject[key];
|
|
30
|
-
|
|
31
|
-
if (typeof value === 'string') {
|
|
32
|
-
str += `${camelToKebabCase(key)}: ${value};`;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
20
|
+
|
|
21
|
+
$: useBlock = () => {
|
|
22
|
+
return getProcessedBlock({
|
|
23
|
+
block: block,
|
|
24
|
+
state: builderContext.state,
|
|
25
|
+
context: builderContext.context
|
|
26
|
+
});
|
|
27
|
+
};
|
|
35
28
|
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
$: css = () => {
|
|
30
|
+
const styles = useBlock().responsiveStyles;
|
|
31
|
+
const largeStyles = styles?.large;
|
|
32
|
+
const mediumStyles = styles?.medium;
|
|
33
|
+
const smallStyles = styles?.small;
|
|
34
|
+
return `
|
|
35
|
+
${largeStyles ? `.${useBlock().id} {${convertStyleMaptoCSS(largeStyles)}}` : ''}
|
|
36
|
+
${mediumStyles ? `${getMaxWidthQueryForSize('medium')} {
|
|
37
|
+
.${useBlock().id} {${convertStyleMaptoCSS(mediumStyles)}}
|
|
38
|
+
}` : ''}
|
|
39
|
+
${smallStyles ? `${getMaxWidthQueryForSize('small')} {
|
|
40
|
+
.${useBlock().id} {${convertStyleMaptoCSS(smallStyles)}}
|
|
41
|
+
}` : ''}
|
|
42
|
+
}`;
|
|
38
43
|
};
|
|
39
44
|
|
|
40
|
-
|
|
45
|
+
let builderContext = getContext(BuilderContext.key);
|
|
41
46
|
|
|
42
47
|
|
|
43
48
|
|
|
@@ -48,4 +53,13 @@ return str;
|
|
|
48
53
|
|
|
49
54
|
</script>
|
|
50
55
|
|
|
51
|
-
|
|
56
|
+
|
|
57
|
+
{#if TARGET === 'vue2' || TARGET === 'vue3' || TARGET === 'svelte' }
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
<RenderInlinedStyles styles={css()} ></RenderInlinedStyles>
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
{/if}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
const EMPTY_HTML_ELEMENTS = [
|
|
2
|
+
"area",
|
|
3
|
+
"base",
|
|
4
|
+
"br",
|
|
5
|
+
"col",
|
|
6
|
+
"embed",
|
|
7
|
+
"hr",
|
|
8
|
+
"img",
|
|
9
|
+
"input",
|
|
10
|
+
"keygen",
|
|
11
|
+
"link",
|
|
12
|
+
"meta",
|
|
13
|
+
"param",
|
|
14
|
+
"source",
|
|
15
|
+
"track",
|
|
16
|
+
"wbr"
|
|
17
|
+
];
|
|
18
|
+
const isEmptyHtmlElement = (tagName) => {
|
|
19
|
+
return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
|
|
20
|
+
};
|
|
21
|
+
export {
|
|
22
|
+
isEmptyHtmlElement
|
|
23
|
+
};
|