@builder.io/sdk-svelte 0.0.1-6 → 0.0.1-9
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/package.json +1 -1
- package/src/blocks/columns/columns.svelte +1 -1
- package/src/blocks/image/image.svelte +1 -1
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.svelte +17 -6
- package/src/components/render-content/render-content.svelte +10 -8
- package/src/constants/builder-registered-components.js +24 -8
- package/src/functions/register-component.js +24 -7
package/package.json
CHANGED
|
@@ -38,7 +38,7 @@ export let builderBlock;
|
|
|
38
38
|
|
|
39
39
|
<picture >
|
|
40
40
|
|
|
41
|
-
<img loading="lazy" alt={altText}
|
|
41
|
+
<img loading="lazy" alt={altText} role={altText ? 'presentation' : undefined} style={{
|
|
42
42
|
objectPosition: backgroundSize || 'center',
|
|
43
43
|
objectFit: backgroundSize || 'cover'
|
|
44
44
|
}} class={'builder-image' + (className ? ' ' + className : '')} src={image} srcset={srcset} sizes={sizes} />
|
|
@@ -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
|
+
};
|
|
@@ -12,6 +12,7 @@ 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
14
|
import BlockStyles, { } from './block-styles.svelte';
|
|
15
|
+
import { isEmptyHtmlElement } from './render-block.helpers.js';
|
|
15
16
|
|
|
16
17
|
|
|
17
18
|
|
|
@@ -103,9 +104,11 @@ return componentRef() ? [] : children();
|
|
|
103
104
|
</script>
|
|
104
105
|
|
|
105
106
|
|
|
107
|
+
{#if !componentInfo?.()?.noWrap }
|
|
108
|
+
|
|
106
109
|
|
|
107
110
|
|
|
108
|
-
{#if !
|
|
111
|
+
{#if !isEmptyHtmlElement(tagName()) }
|
|
109
112
|
|
|
110
113
|
|
|
111
114
|
<svelte:element {...propertiesAndActions()} style={css()} this={tagName()} >
|
|
@@ -128,7 +131,7 @@ return componentRef() ? [] : children();
|
|
|
128
131
|
|
|
129
132
|
|
|
130
133
|
{#each children() as child, index }
|
|
131
|
-
<svelte:self block={child} ></svelte:self>
|
|
134
|
+
<svelte:self key={child.id} block={child} ></svelte:self>
|
|
132
135
|
{/each}
|
|
133
136
|
|
|
134
137
|
|
|
@@ -140,7 +143,7 @@ return componentRef() ? [] : children();
|
|
|
140
143
|
|
|
141
144
|
|
|
142
145
|
{#each noCompRefChildren() as child, index }
|
|
143
|
-
<svelte:self block={child} ></svelte:self>
|
|
146
|
+
<svelte:self key={child.id} block={child} ></svelte:self>
|
|
144
147
|
{/each}
|
|
145
148
|
|
|
146
149
|
|
|
@@ -149,15 +152,23 @@ return componentRef() ? [] : children();
|
|
|
149
152
|
|
|
150
153
|
|
|
151
154
|
|
|
155
|
+
{:else}
|
|
156
|
+
<svelte:element {...propertiesAndActions()} style={css()} this={tagName()} ></svelte:element>
|
|
157
|
+
|
|
158
|
+
{/if}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
|
|
152
163
|
{:else}
|
|
153
164
|
<svelte:component {...componentOptions()} attributes={propertiesAndActions()} builderBlock={useBlock()} style={css()} this={componentRef()} >
|
|
154
|
-
|
|
165
|
+
|
|
155
166
|
|
|
156
167
|
{#each children() as child, index }
|
|
157
|
-
<svelte:self block={child} ></svelte:self>
|
|
168
|
+
<svelte:self key={child.id} block={child} ></svelte:self>
|
|
158
169
|
{/each}
|
|
159
170
|
|
|
160
171
|
|
|
161
|
-
|
|
172
|
+
</svelte:component>
|
|
162
173
|
|
|
163
174
|
{/if}
|
|
@@ -111,14 +111,16 @@ Object.entries(requests).forEach(([key, url]) => {
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
function emitStateUpdate() {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
if (isEditing()) {
|
|
115
|
+
window.dispatchEvent(new CustomEvent('builder:component:stateChange', {
|
|
116
|
+
detail: {
|
|
117
|
+
state: contentState(),
|
|
118
|
+
ref: {
|
|
119
|
+
name: model
|
|
120
|
+
}
|
|
119
121
|
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
+
}));
|
|
123
|
+
}
|
|
122
124
|
}
|
|
123
125
|
$: useContent = () => {
|
|
124
126
|
const mergedContent = { ...content,
|
|
@@ -150,7 +152,7 @@ const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `
|
|
|
150
152
|
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
151
153
|
...components, ...(customComponents || [])];
|
|
152
154
|
const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,
|
|
153
|
-
[curr.
|
|
155
|
+
[curr.name]: curr
|
|
154
156
|
}), {});
|
|
155
157
|
return allComponents;
|
|
156
158
|
};
|
|
@@ -1,3 +1,19 @@
|
|
|
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
|
+
};
|
|
1
17
|
import { default as Button } from "../blocks/button/button.svelte";
|
|
2
18
|
import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
|
|
3
19
|
import { default as Columns } from "../blocks/columns/columns.svelte";
|
|
@@ -15,14 +31,14 @@ import { default as Text } from "../blocks/text/text.svelte";
|
|
|
15
31
|
import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
|
|
16
32
|
import { default as Video } from "../blocks/video/video.svelte";
|
|
17
33
|
const getDefaultRegisteredComponents = () => [
|
|
18
|
-
{ component: Columns,
|
|
19
|
-
{ component: Image,
|
|
20
|
-
{ component: Text,
|
|
21
|
-
{ component: Video,
|
|
22
|
-
{ component: Symbol,
|
|
23
|
-
{ component: Button,
|
|
24
|
-
{ component: Section,
|
|
25
|
-
{ component: Fragment,
|
|
34
|
+
__spreadValues({ component: Columns }, columnsComponentInfo),
|
|
35
|
+
__spreadValues({ component: Image }, imageComponentInfo),
|
|
36
|
+
__spreadValues({ component: Text }, textComponentInfo),
|
|
37
|
+
__spreadValues({ component: Video }, videoComponentInfo),
|
|
38
|
+
__spreadValues({ component: Symbol }, symbolComponentInfo),
|
|
39
|
+
__spreadValues({ component: Button }, buttonComponentInfo),
|
|
40
|
+
__spreadValues({ component: Section }, sectionComponentInfo),
|
|
41
|
+
__spreadValues({ component: Fragment }, fragmentComponentInfo)
|
|
26
42
|
];
|
|
27
43
|
export {
|
|
28
44
|
getDefaultRegisteredComponents
|
|
@@ -17,19 +17,36 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
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
|
+
};
|
|
20
32
|
import { fastClone } from "./fast-clone.js";
|
|
21
33
|
const components = [];
|
|
22
34
|
function registerComponent(component, info) {
|
|
23
|
-
components.push({ component, info
|
|
35
|
+
components.push(__spreadValues({ component }, info));
|
|
24
36
|
console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
|
|
25
37
|
return component;
|
|
26
38
|
}
|
|
27
|
-
const createRegisterComponentMessage = ({
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
39
|
+
const createRegisterComponentMessage = (_a) => {
|
|
40
|
+
var _b = _a, {
|
|
41
|
+
component
|
|
42
|
+
} = _b, info = __objRest(_b, [
|
|
43
|
+
"component"
|
|
44
|
+
]);
|
|
45
|
+
return {
|
|
46
|
+
type: "builder.registerComponent",
|
|
47
|
+
data: prepareComponentInfoToSend(fastClone(info))
|
|
48
|
+
};
|
|
49
|
+
};
|
|
33
50
|
function prepareComponentInfoToSend(info) {
|
|
34
51
|
return __spreadValues(__spreadValues({}, info), info.inputs && {
|
|
35
52
|
inputs: info.inputs.map((input) => {
|