@builder.io/sdk-svelte 0.0.1-3 → 0.0.1-6
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 +15 -0
- package/package.json +2 -1
- package/src/components/render-block/render-block.svelte +5 -5
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.svelte +23 -1
- package/src/components/render-inlined-styles.svelte +2 -0
- package/src/constants/builder-registered-components.js +29 -0
- package/src/context/builder.context.js +1 -1
- package/src/functions/fast-clone.js +4 -0
- package/src/functions/get-content/fn.test.js +1 -1
- package/src/functions/register-component.js +13 -13
- package/src/index-helpers/blocks-exports.js +8 -8
- 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/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Builder.io Svelte SDK (BETA)
|
|
2
|
+
|
|
3
|
+
This is the Svelte SDK. It is currently in beta.
|
|
4
|
+
|
|
5
|
+
## Feature Support
|
|
6
|
+
|
|
7
|
+
To check the status of the SDK, look at [these tables](../../README.md#feature-implementation).
|
|
8
|
+
|
|
9
|
+
## Getting Started
|
|
10
|
+
|
|
11
|
+
```
|
|
12
|
+
npm install @builder.io/sdk-svelte@dev
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Take a look at [our example repo](/examples/svelte/sveltekit) for how to use this SDK.
|
package/package.json
CHANGED
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "0.0.1-
|
|
4
|
+
"version": "0.0.1-6",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"src"
|
|
8
8
|
],
|
|
9
9
|
"main": "./src/index.js",
|
|
10
10
|
"module": "./src/index.js",
|
|
11
|
+
"svelte": "./src/index.js",
|
|
11
12
|
"exports": {
|
|
12
13
|
".": {
|
|
13
14
|
"import": "./src/index.js",
|
|
@@ -11,7 +11,6 @@ import { getBlockProperties } from '../../functions/get-block-properties.js'
|
|
|
11
11
|
import { getBlockStyles } from '../../functions/get-block-styles.js';
|
|
12
12
|
import { getBlockTag } from '../../functions/get-block-tag.js';
|
|
13
13
|
import { getProcessedBlock } from '../../functions/get-processed-block.js';
|
|
14
|
-
import { components } from '../../functions/register-component.js';
|
|
15
14
|
import BlockStyles, { } from './block-styles.svelte';
|
|
16
15
|
|
|
17
16
|
|
|
@@ -29,16 +28,17 @@ if (!componentName) {
|
|
|
29
28
|
return null;
|
|
30
29
|
}
|
|
31
30
|
|
|
32
|
-
const ref =
|
|
31
|
+
const ref = builderContext.registeredComponents[componentName];
|
|
33
32
|
|
|
34
|
-
if (
|
|
33
|
+
if (!ref) {
|
|
35
34
|
// TODO: Public doc page with more info about this message
|
|
36
35
|
console.warn(`
|
|
37
36
|
Could not find a registered component named "${componentName}".
|
|
38
37
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
38
|
+
return undefined;
|
|
39
|
+
} else {
|
|
40
|
+
return ref;
|
|
39
41
|
}
|
|
40
|
-
|
|
41
|
-
return ref;
|
|
42
42
|
};
|
|
43
43
|
|
|
44
44
|
$: componentInfo = () => {
|
|
@@ -3,7 +3,8 @@
|
|
|
3
3
|
import { afterUpdate } from 'svelte'
|
|
4
4
|
import { onDestroy } from 'svelte'
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import { getDefaultRegisteredComponents } from '../../constants/builder-registered-components.js';
|
|
7
|
+
import { TARGET } from '../../constants/target.js';
|
|
7
8
|
import BuilderContext, { } from '../../context/builder.context';
|
|
8
9
|
import { evaluate } from '../../functions/evaluate.js';
|
|
9
10
|
import { convertSearchParamsToQueryObject , getBuilderSearchParams } from '../../functions/get-builder-search-params/index.js';
|
|
@@ -13,6 +14,7 @@ import { isBrowser } from '../../functions/is-browser.js';
|
|
|
13
14
|
import { isEditing } from '../../functions/is-editing.js';
|
|
14
15
|
import { isPreviewing } from '../../functions/is-previewing.js';
|
|
15
16
|
import { previewingModelName } from '../../functions/previewing-model-name.js';
|
|
17
|
+
import { components , createRegisterComponentMessage } from '../../functions/register-component.js';
|
|
16
18
|
import { track } from '../../functions/track.js';
|
|
17
19
|
import RenderBlocks, { } from '../render-blocks.svelte';
|
|
18
20
|
import RenderContentStyles, { } from './components/render-styles.svelte';
|
|
@@ -24,6 +26,7 @@ import RenderContentStyles, { } from './components/render-styles.svelte';
|
|
|
24
26
|
|
|
25
27
|
export let content;
|
|
26
28
|
export let data;
|
|
29
|
+
export let customComponents;
|
|
27
30
|
export let model;
|
|
28
31
|
export let apiKey;
|
|
29
32
|
|
|
@@ -139,6 +142,19 @@ $: context = () => {
|
|
|
139
142
|
return {};
|
|
140
143
|
};
|
|
141
144
|
|
|
145
|
+
$: allRegisteredComponents = () => {
|
|
146
|
+
const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
147
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
148
|
+
// existing usage.
|
|
149
|
+
// This is why we spread `components` after the default Builder.io components, but before the `customComponents`,
|
|
150
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
151
|
+
...components, ...(customComponents || [])];
|
|
152
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,
|
|
153
|
+
[curr.info.name]: curr
|
|
154
|
+
}), {});
|
|
155
|
+
return allComponents;
|
|
156
|
+
};
|
|
157
|
+
|
|
142
158
|
$: httpReqsData = () => {
|
|
143
159
|
return {};
|
|
144
160
|
};
|
|
@@ -152,6 +168,8 @@ return contentState();
|
|
|
152
168
|
return context();
|
|
153
169
|
}, get apiKey() {
|
|
154
170
|
return apiKey;
|
|
171
|
+
}, get registeredComponents() {
|
|
172
|
+
return allRegisteredComponents();
|
|
155
173
|
},});
|
|
156
174
|
let overrideContent = null;
|
|
157
175
|
let update = 0;
|
|
@@ -159,6 +177,10 @@ let overrideState = {};
|
|
|
159
177
|
|
|
160
178
|
onMount(() => { if (isBrowser()) {
|
|
161
179
|
if (isEditing()) {
|
|
180
|
+
Object.values(allRegisteredComponents()).forEach(registeredComponent => {
|
|
181
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
182
|
+
window.parent?.postMessage(message, '*');
|
|
183
|
+
});
|
|
162
184
|
window.addEventListener('message', processMessage);
|
|
163
185
|
window.addEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate);
|
|
164
186
|
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { default as Button } from "../blocks/button/button.svelte";
|
|
2
|
+
import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
|
|
3
|
+
import { default as Columns } from "../blocks/columns/columns.svelte";
|
|
4
|
+
import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
|
|
5
|
+
import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
|
|
6
|
+
import { default as Fragment } from "../blocks/fragment/fragment.svelte";
|
|
7
|
+
import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
|
|
8
|
+
import { default as Image } from "../blocks/image/image.svelte";
|
|
9
|
+
import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
|
|
10
|
+
import { default as Section } from "../blocks/section/section.svelte";
|
|
11
|
+
import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
|
|
12
|
+
import { default as Symbol } from "../blocks/symbol/symbol.svelte";
|
|
13
|
+
import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
|
|
14
|
+
import { default as Text } from "../blocks/text/text.svelte";
|
|
15
|
+
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
|
|
16
|
+
import { default as Video } from "../blocks/video/video.svelte";
|
|
17
|
+
const getDefaultRegisteredComponents = () => [
|
|
18
|
+
{ component: Columns, info: columnsComponentInfo },
|
|
19
|
+
{ component: Image, info: imageComponentInfo },
|
|
20
|
+
{ component: Text, info: textComponentInfo },
|
|
21
|
+
{ component: Video, info: videoComponentInfo },
|
|
22
|
+
{ component: Symbol, info: symbolComponentInfo },
|
|
23
|
+
{ component: Button, info: buttonComponentInfo },
|
|
24
|
+
{ component: Section, info: sectionComponentInfo },
|
|
25
|
+
{ component: Fragment, info: fragmentComponentInfo }
|
|
26
|
+
];
|
|
27
|
+
export {
|
|
28
|
+
getDefaultRegisteredComponents
|
|
29
|
+
};
|
|
@@ -17,27 +17,26 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
-
import {
|
|
21
|
-
const components =
|
|
20
|
+
import { fastClone } from "./fast-clone.js";
|
|
21
|
+
const components = [];
|
|
22
22
|
function registerComponent(component, info) {
|
|
23
|
-
|
|
24
|
-
|
|
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
|
-
}
|
|
23
|
+
components.push({ component, info });
|
|
24
|
+
console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
|
|
32
25
|
return component;
|
|
33
26
|
}
|
|
27
|
+
const createRegisterComponentMessage = ({
|
|
28
|
+
info
|
|
29
|
+
}) => ({
|
|
30
|
+
type: "builder.registerComponent",
|
|
31
|
+
data: prepareComponentInfoToSend(fastClone(info))
|
|
32
|
+
});
|
|
34
33
|
function prepareComponentInfoToSend(info) {
|
|
35
34
|
return __spreadValues(__spreadValues({}, info), info.inputs && {
|
|
36
35
|
inputs: info.inputs.map((input) => {
|
|
37
36
|
const keysToConvertFnToString = ["onChange", "showIf"];
|
|
38
37
|
for (const key of keysToConvertFnToString) {
|
|
39
|
-
|
|
40
|
-
|
|
38
|
+
const fn = input[key];
|
|
39
|
+
if (fn && typeof fn === "function") {
|
|
41
40
|
input = __spreadProps(__spreadValues({}, input), {
|
|
42
41
|
[key]: `return (${fn.toString()}).apply(this, arguments)`
|
|
43
42
|
});
|
|
@@ -49,5 +48,6 @@ function prepareComponentInfoToSend(info) {
|
|
|
49
48
|
}
|
|
50
49
|
export {
|
|
51
50
|
components,
|
|
51
|
+
createRegisterComponentMessage,
|
|
52
52
|
registerComponent
|
|
53
53
|
};
|
|
@@ -1,11 +1,11 @@
|
|
|
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
10
|
export {
|
|
11
11
|
default7 as Button,
|
|
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
|
-
};
|
package/src/blocks/form/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { registerComponent } from "../../functions/register-component.js";
|
|
2
|
-
import { componentInfo } from "./component-info.js";
|
|
3
|
-
import component from "./form.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 "./fragment.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 "./image.svelte";
|
|
4
|
-
var stdin_default = registerComponent(component, componentInfo);
|
|
5
|
-
export {
|
|
6
|
-
stdin_default as default
|
|
7
|
-
};
|
package/src/blocks/img/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { registerComponent } from "../../functions/register-component.js";
|
|
2
|
-
import { componentInfo } from "./component-info.js";
|
|
3
|
-
import component from "./img.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 "./input.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 "./raw-text.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 "./section.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 "./select.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 "./submit-button.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 "./symbol.svelte";
|
|
4
|
-
var stdin_default = registerComponent(component, componentInfo);
|
|
5
|
-
export {
|
|
6
|
-
stdin_default as default
|
|
7
|
-
};
|
package/src/blocks/text/index.js
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { registerComponent } from "../../functions/register-component.js";
|
|
2
|
-
import { componentInfo } from "./component-info.js";
|
|
3
|
-
import component from "./text.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 "./textarea.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 "./video.svelte";
|
|
4
|
-
var stdin_default = registerComponent(component, componentInfo);
|
|
5
|
-
export {
|
|
6
|
-
stdin_default as default
|
|
7
|
-
};
|