@builder.io/sdk-svelte 0.1.6 → 0.1.8
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/--package.json +1 -1
- package/package/CHANGELOG.md +8 -0
- package/package/blocks/columns/columns.svelte +5 -3
- package/package/blocks/columns/columns.svelte.d.ts +0 -3
- package/package/components/render-block/block-styles.svelte +12 -1
- package/package/components/render-block/render-block.svelte +33 -22
- package/package/components/render-block/render-component.svelte.d.ts +0 -3
- package/package/types/builder-block.d.ts +8 -0
- package/package.json +1 -1
- package/src/blocks/columns/columns.svelte +8 -5
- package/src/components/render-block/block-styles.svelte +12 -1
- package/src/components/render-block/render-block.svelte +33 -22
- package/src/components/render-block/render-component.svelte +0 -4
- package/src/types/builder-block.ts +10 -0
package/package/--package.json
CHANGED
package/package/CHANGELOG.md
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>import
|
|
3
|
+
<script>import { getContext } from "svelte";
|
|
4
|
+
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
4
5
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
5
6
|
import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
|
|
6
7
|
import { TARGET } from "../../constants/target.js";
|
|
7
8
|
import { convertStyleMapToCSS } from "../../helpers/css";
|
|
9
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
8
10
|
export let space;
|
|
9
11
|
export let columns;
|
|
10
12
|
export let stackColumnsAt;
|
|
11
13
|
export let reverseColumnsWhenStacked;
|
|
12
|
-
export let customBreakpoints;
|
|
13
14
|
export let builderBlock;
|
|
14
15
|
function mitosis_styling(node, vars) {
|
|
15
16
|
Object.entries(vars || {}).forEach(([p, v]) => {
|
|
@@ -21,6 +22,7 @@ function mitosis_styling(node, vars) {
|
|
|
21
22
|
}
|
|
22
23
|
});
|
|
23
24
|
}
|
|
25
|
+
let builderContext = getContext(BuilderContext.key);
|
|
24
26
|
function getGutterSize() {
|
|
25
27
|
return typeof space === "number" ? space || 0 : 20;
|
|
26
28
|
}
|
|
@@ -42,7 +44,7 @@ function maybeApplyForTablet(prop) {
|
|
|
42
44
|
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
43
45
|
}
|
|
44
46
|
function getWidthForBreakpointSize(size) {
|
|
45
|
-
const breakpointSizes = getSizesForBreakpoints(
|
|
47
|
+
const breakpointSizes = getSizesForBreakpoints(builderContext.content?.meta?.breakpoints || {});
|
|
46
48
|
return breakpointSizes[size].max;
|
|
47
49
|
}
|
|
48
50
|
$: columnsCssVars = () => {
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { BuilderBlock } from "../../types/builder-block";
|
|
3
|
-
import type { Breakpoints } from "../../types/builder-content";
|
|
4
3
|
declare type Column = {
|
|
5
4
|
blocks: any;
|
|
6
5
|
width?: number;
|
|
@@ -12,7 +11,6 @@ export interface ColumnProps {
|
|
|
12
11
|
space?: number;
|
|
13
12
|
stackColumnsAt?: StackColumnsAt;
|
|
14
13
|
reverseColumnsWhenStacked?: boolean;
|
|
15
|
-
customBreakpoints?: Breakpoints;
|
|
16
14
|
}
|
|
17
15
|
declare const __propDef: {
|
|
18
16
|
props: {
|
|
@@ -20,7 +18,6 @@ declare const __propDef: {
|
|
|
20
18
|
columns: ColumnProps["columns"];
|
|
21
19
|
stackColumnsAt: ColumnProps["stackColumnsAt"];
|
|
22
20
|
reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
|
|
23
|
-
customBreakpoints: ColumnProps["customBreakpoints"];
|
|
24
21
|
builderBlock: ColumnProps["builderBlock"];
|
|
25
22
|
};
|
|
26
23
|
events: {
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
import { TARGET } from "../../constants/target.js";
|
|
5
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
6
6
|
import { createCssClass } from "../../helpers/css.js";
|
|
7
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
7
8
|
import RenderInlinedStyles from "../render-inlined-styles.svelte";
|
|
8
9
|
export let block;
|
|
9
10
|
export let context;
|
|
@@ -15,6 +16,16 @@ $: useBlock = () => {
|
|
|
15
16
|
shouldEvaluateBindings: true,
|
|
16
17
|
});
|
|
17
18
|
};
|
|
19
|
+
$: canShowBlock = () => {
|
|
20
|
+
// only render styles for blocks that are visible
|
|
21
|
+
if (checkIsDefined(useBlock().hide)) {
|
|
22
|
+
return !useBlock().hide;
|
|
23
|
+
}
|
|
24
|
+
if (checkIsDefined(useBlock().show)) {
|
|
25
|
+
return useBlock().show;
|
|
26
|
+
}
|
|
27
|
+
return true;
|
|
28
|
+
};
|
|
18
29
|
$: css = () => {
|
|
19
30
|
const styles = useBlock().responsiveStyles;
|
|
20
31
|
const content = context.content;
|
|
@@ -47,6 +58,6 @@ $: css = () => {
|
|
|
47
58
|
};
|
|
48
59
|
</script>
|
|
49
60
|
|
|
50
|
-
{#if TARGET !== "reactNative" && css()}
|
|
61
|
+
{#if TARGET !== "reactNative" && css() && canShowBlock()}
|
|
51
62
|
<RenderInlinedStyles styles={css()} />
|
|
52
63
|
{/if}
|
|
@@ -12,6 +12,7 @@ import { TARGET } from "../../constants/target.js";
|
|
|
12
12
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
13
13
|
import RenderComponent from "./render-component.svelte";
|
|
14
14
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
15
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
15
16
|
const setAttrs = (node, attrs = {}) => {
|
|
16
17
|
const attrKeys = Object.keys(attrs);
|
|
17
18
|
const setup = (attr) => node.addEventListener(attr.substr(3), attrs[attr]);
|
|
@@ -43,6 +44,15 @@ $: useBlock = () => {
|
|
|
43
44
|
shouldEvaluateBindings: true,
|
|
44
45
|
});
|
|
45
46
|
};
|
|
47
|
+
$: canShowBlock = () => {
|
|
48
|
+
if (checkIsDefined(useBlock().hide)) {
|
|
49
|
+
return !useBlock().hide;
|
|
50
|
+
}
|
|
51
|
+
if (checkIsDefined(useBlock().show)) {
|
|
52
|
+
return useBlock().show;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
};
|
|
46
56
|
$: proxyState = () => {
|
|
47
57
|
if (typeof Proxy === "undefined") {
|
|
48
58
|
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
@@ -99,7 +109,6 @@ $: renderComponentProps = () => {
|
|
|
99
109
|
...actions(),
|
|
100
110
|
},
|
|
101
111
|
}),
|
|
102
|
-
customBreakpoints: childrenContext?.()?.content?.meta?.breakpoints,
|
|
103
112
|
},
|
|
104
113
|
context: childrenContext(),
|
|
105
114
|
};
|
|
@@ -145,30 +154,32 @@ let repeatItemData = getRepeatItemData({
|
|
|
145
154
|
});
|
|
146
155
|
</script>
|
|
147
156
|
|
|
148
|
-
{#if
|
|
149
|
-
{#if
|
|
150
|
-
|
|
151
|
-
|
|
157
|
+
{#if canShowBlock()}
|
|
158
|
+
{#if !component?.noWrap}
|
|
159
|
+
{#if isEmptyHtmlElement(tag())}
|
|
160
|
+
<svelte:element this={tag()} {...attributes()} use:setAttrs={actions()} />
|
|
161
|
+
{/if}
|
|
152
162
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
163
|
+
{#if !isEmptyHtmlElement(tag()) && repeatItemData}
|
|
164
|
+
{#each repeatItemData as data, index (index)}
|
|
165
|
+
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
166
|
+
{/each}
|
|
167
|
+
{/if}
|
|
158
168
|
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
169
|
+
{#if !isEmptyHtmlElement(tag()) && !repeatItemData}
|
|
170
|
+
<svelte:element this={tag()} {...attributes()} use:setAttrs={actions()}>
|
|
171
|
+
<RenderComponent {...renderComponentProps()} />
|
|
162
172
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
173
|
+
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
174
|
+
<svelte:self block={child} context={childrenContext()} />
|
|
175
|
+
{/each}
|
|
166
176
|
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
177
|
+
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
178
|
+
<BlockStyles block={child} context={childrenContext()} />
|
|
179
|
+
{/each}
|
|
180
|
+
</svelte:element>
|
|
181
|
+
{/if}
|
|
182
|
+
{:else}
|
|
183
|
+
<RenderComponent {...renderComponentProps()} />
|
|
171
184
|
{/if}
|
|
172
|
-
{:else}
|
|
173
|
-
<RenderComponent {...renderComponentProps()} />
|
|
174
185
|
{/if}
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
3
3
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
4
|
-
import type { Breakpoints } from "../../types/builder-content.js";
|
|
5
4
|
declare type ComponentOptions = {
|
|
6
5
|
[index: string]: any;
|
|
7
|
-
customBreakpoints?: Breakpoints;
|
|
8
6
|
attributes?: {
|
|
9
7
|
[index: string]: any;
|
|
10
8
|
};
|
|
@@ -14,7 +12,6 @@ export interface RenderComponentProps {
|
|
|
14
12
|
componentOptions: ComponentOptions;
|
|
15
13
|
blockChildren: BuilderBlock[];
|
|
16
14
|
context: BuilderContextInterface;
|
|
17
|
-
customBreakpoints?: Breakpoints;
|
|
18
15
|
}
|
|
19
16
|
declare const __propDef: {
|
|
20
17
|
props: {
|
|
@@ -54,5 +54,13 @@ export interface BuilderBlock {
|
|
|
54
54
|
} | null;
|
|
55
55
|
animations?: any[];
|
|
56
56
|
style?: Partial<CSSStyleDeclaration>;
|
|
57
|
+
/**
|
|
58
|
+
* generated by the "Hide If" binding
|
|
59
|
+
*/
|
|
60
|
+
hide?: boolean;
|
|
61
|
+
/**
|
|
62
|
+
* generated by the "Show If" binding
|
|
63
|
+
*/
|
|
64
|
+
show?: boolean;
|
|
57
65
|
}
|
|
58
66
|
export {};
|
package/package.json
CHANGED
|
@@ -3,8 +3,6 @@
|
|
|
3
3
|
|
|
4
4
|
import type { SizeName } from "../../constants/device-sizes";
|
|
5
5
|
|
|
6
|
-
import type { Breakpoints } from "../../types/builder-content";
|
|
7
|
-
|
|
8
6
|
type Column = {
|
|
9
7
|
blocks: any;
|
|
10
8
|
// TODO: Implement this when support for dynamic CSS lands
|
|
@@ -23,22 +21,23 @@
|
|
|
23
21
|
stackColumnsAt?: StackColumnsAt;
|
|
24
22
|
// TODO: Implement this when support for dynamic CSS lands
|
|
25
23
|
reverseColumnsWhenStacked?: boolean;
|
|
26
|
-
customBreakpoints?: Breakpoints;
|
|
27
24
|
}
|
|
28
25
|
</script>
|
|
29
26
|
|
|
30
27
|
<script lang="ts">
|
|
28
|
+
import { getContext } from "svelte";
|
|
29
|
+
|
|
31
30
|
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
32
31
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
33
32
|
import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
|
|
34
33
|
import { TARGET } from "../../constants/target.js";
|
|
35
34
|
import { convertStyleMapToCSS } from "../../helpers/css";
|
|
35
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
36
36
|
|
|
37
37
|
export let space: ColumnProps["space"];
|
|
38
38
|
export let columns: ColumnProps["columns"];
|
|
39
39
|
export let stackColumnsAt: ColumnProps["stackColumnsAt"];
|
|
40
40
|
export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"];
|
|
41
|
-
export let customBreakpoints: ColumnProps["customBreakpoints"];
|
|
42
41
|
export let builderBlock: ColumnProps["builderBlock"];
|
|
43
42
|
|
|
44
43
|
function mitosis_styling(node, vars) {
|
|
@@ -51,6 +50,8 @@
|
|
|
51
50
|
});
|
|
52
51
|
}
|
|
53
52
|
|
|
53
|
+
let builderContext = getContext(BuilderContext.key);
|
|
54
|
+
|
|
54
55
|
function getGutterSize() {
|
|
55
56
|
return typeof space === "number" ? space || 0 : 20;
|
|
56
57
|
}
|
|
@@ -72,7 +73,9 @@
|
|
|
72
73
|
return _stackColumnsAt === "tablet" ? prop : "inherit";
|
|
73
74
|
}
|
|
74
75
|
function getWidthForBreakpointSize(size) {
|
|
75
|
-
const breakpointSizes = getSizesForBreakpoints(
|
|
76
|
+
const breakpointSizes = getSizesForBreakpoints(
|
|
77
|
+
builderContext.content?.meta?.breakpoints || {}
|
|
78
|
+
);
|
|
76
79
|
return breakpointSizes[size].max;
|
|
77
80
|
}
|
|
78
81
|
$: columnsCssVars = () => {
|
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
import { TARGET } from "../../constants/target.js";
|
|
18
18
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
19
19
|
import { createCssClass } from "../../helpers/css.js";
|
|
20
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
20
21
|
import RenderInlinedStyles from "../render-inlined-styles.svelte";
|
|
21
22
|
|
|
22
23
|
export let block: BlockStylesProps["block"];
|
|
@@ -30,6 +31,16 @@
|
|
|
30
31
|
shouldEvaluateBindings: true,
|
|
31
32
|
});
|
|
32
33
|
};
|
|
34
|
+
$: canShowBlock = () => {
|
|
35
|
+
// only render styles for blocks that are visible
|
|
36
|
+
if (checkIsDefined(useBlock().hide)) {
|
|
37
|
+
return !useBlock().hide;
|
|
38
|
+
}
|
|
39
|
+
if (checkIsDefined(useBlock().show)) {
|
|
40
|
+
return useBlock().show;
|
|
41
|
+
}
|
|
42
|
+
return true;
|
|
43
|
+
};
|
|
33
44
|
$: css = () => {
|
|
34
45
|
const styles = useBlock().responsiveStyles;
|
|
35
46
|
const content = context.content;
|
|
@@ -70,6 +81,6 @@
|
|
|
70
81
|
};
|
|
71
82
|
</script>
|
|
72
83
|
|
|
73
|
-
{#if TARGET !== "reactNative" && css()}
|
|
84
|
+
{#if TARGET !== "reactNative" && css() && canShowBlock()}
|
|
74
85
|
<RenderInlinedStyles styles={css()} />
|
|
75
86
|
{/if}
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
32
32
|
import RenderComponent from "./render-component.svelte";
|
|
33
33
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
34
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
34
35
|
|
|
35
36
|
const setAttrs = (node, attrs = {}) => {
|
|
36
37
|
const attrKeys = Object.keys(attrs);
|
|
@@ -66,6 +67,15 @@
|
|
|
66
67
|
shouldEvaluateBindings: true,
|
|
67
68
|
});
|
|
68
69
|
};
|
|
70
|
+
$: canShowBlock = () => {
|
|
71
|
+
if (checkIsDefined(useBlock().hide)) {
|
|
72
|
+
return !useBlock().hide;
|
|
73
|
+
}
|
|
74
|
+
if (checkIsDefined(useBlock().show)) {
|
|
75
|
+
return useBlock().show;
|
|
76
|
+
}
|
|
77
|
+
return true;
|
|
78
|
+
};
|
|
69
79
|
$: proxyState = () => {
|
|
70
80
|
if (typeof Proxy === "undefined") {
|
|
71
81
|
console.error(
|
|
@@ -125,7 +135,6 @@
|
|
|
125
135
|
...actions(),
|
|
126
136
|
},
|
|
127
137
|
}),
|
|
128
|
-
customBreakpoints: childrenContext?.()?.content?.meta?.breakpoints,
|
|
129
138
|
},
|
|
130
139
|
context: childrenContext(),
|
|
131
140
|
};
|
|
@@ -175,30 +184,32 @@
|
|
|
175
184
|
});
|
|
176
185
|
</script>
|
|
177
186
|
|
|
178
|
-
{#if
|
|
179
|
-
{#if
|
|
180
|
-
|
|
181
|
-
|
|
187
|
+
{#if canShowBlock()}
|
|
188
|
+
{#if !component?.noWrap}
|
|
189
|
+
{#if isEmptyHtmlElement(tag())}
|
|
190
|
+
<svelte:element this={tag()} {...attributes()} use:setAttrs={actions()} />
|
|
191
|
+
{/if}
|
|
182
192
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
193
|
+
{#if !isEmptyHtmlElement(tag()) && repeatItemData}
|
|
194
|
+
{#each repeatItemData as data, index (index)}
|
|
195
|
+
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
196
|
+
{/each}
|
|
197
|
+
{/if}
|
|
188
198
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
199
|
+
{#if !isEmptyHtmlElement(tag()) && !repeatItemData}
|
|
200
|
+
<svelte:element this={tag()} {...attributes()} use:setAttrs={actions()}>
|
|
201
|
+
<RenderComponent {...renderComponentProps()} />
|
|
192
202
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
203
|
+
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
204
|
+
<svelte:self block={child} context={childrenContext()} />
|
|
205
|
+
{/each}
|
|
196
206
|
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
207
|
+
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
208
|
+
<BlockStyles block={child} context={childrenContext()} />
|
|
209
|
+
{/each}
|
|
210
|
+
</svelte:element>
|
|
211
|
+
{/if}
|
|
212
|
+
{:else}
|
|
213
|
+
<RenderComponent {...renderComponentProps()} />
|
|
201
214
|
{/if}
|
|
202
|
-
{:else}
|
|
203
|
-
<RenderComponent {...renderComponentProps()} />
|
|
204
215
|
{/if}
|
|
@@ -3,11 +3,8 @@
|
|
|
3
3
|
|
|
4
4
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
5
5
|
|
|
6
|
-
import type { Breakpoints } from "../../types/builder-content.js";
|
|
7
|
-
|
|
8
6
|
type ComponentOptions = {
|
|
9
7
|
[index: string]: any;
|
|
10
|
-
customBreakpoints?: Breakpoints;
|
|
11
8
|
attributes?: {
|
|
12
9
|
[index: string]: any;
|
|
13
10
|
};
|
|
@@ -18,7 +15,6 @@
|
|
|
18
15
|
componentOptions: ComponentOptions;
|
|
19
16
|
blockChildren: BuilderBlock[];
|
|
20
17
|
context: BuilderContextInterface;
|
|
21
|
-
customBreakpoints?: Breakpoints;
|
|
22
18
|
}
|
|
23
19
|
</script>
|
|
24
20
|
|
|
@@ -56,4 +56,14 @@ export interface BuilderBlock {
|
|
|
56
56
|
} | null;
|
|
57
57
|
animations?: any[]; // TODO: type the animation spec
|
|
58
58
|
style?: Partial<CSSStyleDeclaration>;
|
|
59
|
+
|
|
60
|
+
/**
|
|
61
|
+
* generated by the "Hide If" binding
|
|
62
|
+
*/
|
|
63
|
+
hide?: boolean;
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* generated by the "Show If" binding
|
|
67
|
+
*/
|
|
68
|
+
show?: boolean;
|
|
59
69
|
}
|