@builder.io/sdk-svelte 0.0.1-10 → 0.0.1-13
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/components/render-block/block-styles.svelte +27 -7
- package/src/components/render-block/render-block.svelte +29 -39
- package/src/components/render-block/render-component.svelte +58 -0
- package/src/components/render-blocks.svelte +20 -1
- package/src/functions/get-block-component-options.js +6 -1
package/package.json
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import
|
|
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';
|
|
7
10
|
|
|
8
11
|
|
|
9
12
|
|
|
10
|
-
|
|
13
|
+
import { getContext, setContext } from "svelte";
|
|
11
14
|
|
|
12
15
|
|
|
13
16
|
export let block;
|
|
@@ -15,15 +18,23 @@
|
|
|
15
18
|
function camelToKebabCase(string) {
|
|
16
19
|
return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
17
20
|
}
|
|
18
|
-
$:
|
|
21
|
+
$: useBlock = () => {
|
|
22
|
+
return getProcessedBlock({
|
|
23
|
+
block: block,
|
|
24
|
+
state: builderContext.state,
|
|
25
|
+
context: builderContext.context
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
$: css = () => {
|
|
19
30
|
// TODO: media queries
|
|
20
|
-
const styleObject =
|
|
31
|
+
const styleObject = useBlock().responsiveStyles?.large;
|
|
21
32
|
|
|
22
33
|
if (!styleObject) {
|
|
23
34
|
return '';
|
|
24
35
|
}
|
|
25
36
|
|
|
26
|
-
let str = `.${
|
|
37
|
+
let str = `.${useBlock().id} {`;
|
|
27
38
|
|
|
28
39
|
for (const key in styleObject) {
|
|
29
40
|
const value = styleObject[key];
|
|
@@ -37,7 +48,7 @@ str += '}';
|
|
|
37
48
|
return str;
|
|
38
49
|
};
|
|
39
50
|
|
|
40
|
-
|
|
51
|
+
let builderContext = getContext(BuilderContext.key);
|
|
41
52
|
|
|
42
53
|
|
|
43
54
|
|
|
@@ -48,4 +59,13 @@ return str;
|
|
|
48
59
|
|
|
49
60
|
</script>
|
|
50
61
|
|
|
51
|
-
|
|
62
|
+
|
|
63
|
+
{#if TARGET === 'vue' || TARGET === 'svelte' }
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
<RenderInlinedStyles styles={css()} ></RenderInlinedStyles>
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
{/if}
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {
|
|
7
|
-
import BuilderContext, { } from '../../context/builder.context';
|
|
6
|
+
import BuilderContext, { } from '../../context/builder.context';
|
|
8
7
|
import { getBlockActions } from '../../functions/get-block-actions.js';
|
|
9
8
|
import { getBlockComponentOptions } from '../../functions/get-block-component-options.js';
|
|
10
9
|
import { getBlockProperties } from '../../functions/get-block-properties.js';
|
|
@@ -13,6 +12,7 @@ import { getBlockTag } from '../../functions/get-block-tag.js';
|
|
|
13
12
|
import { getProcessedBlock } from '../../functions/get-processed-block.js';
|
|
14
13
|
import BlockStyles, { } from './block-styles.svelte';
|
|
15
14
|
import { isEmptyHtmlElement } from './render-block.helpers.js';
|
|
15
|
+
import RenderComponent, { } from './render-component.svelte';
|
|
16
16
|
|
|
17
17
|
|
|
18
18
|
|
|
@@ -70,22 +70,32 @@ return getProcessedBlock({
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
|
|
73
|
-
$:
|
|
73
|
+
$: attributes = () => {
|
|
74
74
|
return { ...getBlockProperties(useBlock()),
|
|
75
75
|
...getBlockActions({
|
|
76
76
|
block: useBlock(),
|
|
77
77
|
state: builderContext.state,
|
|
78
78
|
context: builderContext.context
|
|
79
|
-
})
|
|
79
|
+
}),
|
|
80
|
+
style: getBlockStyles(useBlock())
|
|
80
81
|
};
|
|
81
82
|
};
|
|
82
83
|
|
|
83
|
-
$:
|
|
84
|
-
return
|
|
84
|
+
$: shouldWrap = () => {
|
|
85
|
+
return !componentInfo?.()?.noWrap;
|
|
85
86
|
};
|
|
86
87
|
|
|
87
88
|
$: componentOptions = () => {
|
|
88
|
-
return getBlockComponentOptions(useBlock())
|
|
89
|
+
return { ...getBlockComponentOptions(useBlock()),
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
93
|
+
* they are provided to the component itself directly.
|
|
94
|
+
*/
|
|
95
|
+
...(shouldWrap() ? {} : {
|
|
96
|
+
attributes: attributes()
|
|
97
|
+
})
|
|
98
|
+
};
|
|
89
99
|
};
|
|
90
100
|
|
|
91
101
|
$: children = () => {
|
|
@@ -97,6 +107,10 @@ return useBlock().children ?? [];
|
|
|
97
107
|
};
|
|
98
108
|
|
|
99
109
|
$: noCompRefChildren = () => {
|
|
110
|
+
/**
|
|
111
|
+
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
112
|
+
* we render them outside of `componentRef`
|
|
113
|
+
*/
|
|
100
114
|
return componentRef() ? [] : children();
|
|
101
115
|
};
|
|
102
116
|
|
|
@@ -112,46 +126,30 @@ return componentRef() ? [] : children();
|
|
|
112
126
|
</script>
|
|
113
127
|
|
|
114
128
|
|
|
115
|
-
{#if
|
|
129
|
+
{#if shouldWrap() }
|
|
116
130
|
|
|
117
131
|
|
|
118
132
|
|
|
119
133
|
{#if !isEmptyHtmlElement(tagName()) }
|
|
120
134
|
|
|
121
135
|
|
|
122
|
-
<svelte:element {...
|
|
136
|
+
<svelte:element {...attributes()} this={tagName()} >
|
|
123
137
|
|
|
124
|
-
|
|
125
|
-
{#if TARGET === 'vue' || TARGET === 'svelte' }
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
<BlockStyles block={useBlock()} ></BlockStyles>
|
|
138
|
+
<RenderComponent blockChildren={children()} componentRef={componentRef()} componentOptions={componentOptions()} ></RenderComponent>
|
|
129
139
|
|
|
130
140
|
|
|
131
141
|
|
|
132
|
-
|
|
133
|
-
{/if}
|
|
134
|
-
|
|
135
142
|
|
|
136
143
|
|
|
137
|
-
{#
|
|
138
|
-
<svelte:
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
{#each children() as child, index }
|
|
142
|
-
<svelte:self key={child.id} block={child} ></svelte:self>
|
|
144
|
+
{#each noCompRefChildren() as child, index }
|
|
145
|
+
<svelte:self key={'render-block-' + child.id} block={child} ></svelte:self>
|
|
143
146
|
{/each}
|
|
144
147
|
|
|
145
148
|
|
|
146
|
-
</svelte:component>
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
{/if}
|
|
150
|
-
|
|
151
149
|
|
|
152
150
|
|
|
153
151
|
{#each noCompRefChildren() as child, index }
|
|
154
|
-
<
|
|
152
|
+
<BlockStyles key={'block-style-' + child.id} block={child} ></BlockStyles>
|
|
155
153
|
{/each}
|
|
156
154
|
|
|
157
155
|
|
|
@@ -161,7 +159,7 @@ return componentRef() ? [] : children();
|
|
|
161
159
|
|
|
162
160
|
|
|
163
161
|
{:else}
|
|
164
|
-
<svelte:element {...
|
|
162
|
+
<svelte:element {...attributes()} this={tagName()} ></svelte:element>
|
|
165
163
|
|
|
166
164
|
{/if}
|
|
167
165
|
|
|
@@ -169,14 +167,6 @@ return componentRef() ? [] : children();
|
|
|
169
167
|
|
|
170
168
|
|
|
171
169
|
{:else}
|
|
172
|
-
<
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
{#each children() as child, index }
|
|
176
|
-
<svelte:self key={child.id} block={child} ></svelte:self>
|
|
177
|
-
{/each}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
</svelte:component>
|
|
170
|
+
<RenderComponent blockChildren={children()} componentRef={componentRef()} componentOptions={componentOptions()} ></RenderComponent>
|
|
181
171
|
|
|
182
172
|
{/if}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
import BlockStyles, { } from './block-styles.svelte';
|
|
7
|
+
import RenderBlock, { } from './render-block.svelte';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
export let componentRef;
|
|
15
|
+
export let componentOptions;
|
|
16
|
+
export let blockChildren;
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
</script>
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
{#if componentRef }
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
<svelte:component {...componentOptions} this={componentRef} >
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
{#each blockChildren as child, index }
|
|
42
|
+
<RenderBlock key={'render-block-' + child.id} block={child} ></RenderBlock>
|
|
43
|
+
{/each}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
{#each blockChildren as child, index }
|
|
49
|
+
<BlockStyles key={'block-style-' + child.id} block={child} ></BlockStyles>
|
|
50
|
+
{/each}
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
</svelte:component>
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
{/if}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
import { isEditing } from '../functions/is-editing.js';
|
|
7
|
+
import BlockStyles, { } from './render-block/block-styles.svelte';
|
|
7
8
|
import RenderBlock, { } from './render-block/render-block.svelte';
|
|
8
9
|
|
|
9
10
|
|
|
@@ -58,12 +59,30 @@ class: className()
|
|
|
58
59
|
}} on:click="{event => onClick()}" on:mouseenter="{event => onMouseEnter()}" class={className()} >
|
|
59
60
|
|
|
60
61
|
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
{#if blocks }
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
{#each blocks as block, index }
|
|
69
|
+
<RenderBlock key={'render-block-' + block.id} block={block} ></RenderBlock>
|
|
70
|
+
{/each}
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
{/if}
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
61
80
|
{#if blocks }
|
|
62
81
|
|
|
63
82
|
|
|
64
83
|
|
|
65
84
|
{#each blocks as block, index }
|
|
66
|
-
<
|
|
85
|
+
<BlockStyles key={'block-style-' + block.id} block={block} ></BlockStyles>
|
|
67
86
|
{/each}
|
|
68
87
|
|
|
69
88
|
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
2
4
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
3
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
4
6
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
@@ -14,9 +16,12 @@ var __spreadValues = (a, b) => {
|
|
|
14
16
|
}
|
|
15
17
|
return a;
|
|
16
18
|
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
17
20
|
function getBlockComponentOptions(block) {
|
|
18
21
|
var _a;
|
|
19
|
-
return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options)
|
|
22
|
+
return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
|
|
23
|
+
builderBlock: block
|
|
24
|
+
});
|
|
20
25
|
}
|
|
21
26
|
export {
|
|
22
27
|
getBlockComponentOptions
|