@builder.io/sdk-svelte 0.0.1-11 → 0.0.1-12

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-svelte",
3
3
  "description": "Builder.io SDK for Svelte",
4
- "version": "0.0.1-11",
4
+ "version": "0.0.1-12",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "src"
@@ -3,16 +3,15 @@
3
3
 
4
4
 
5
5
 
6
- import { TARGET } from '../../constants/target.js';
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';
11
10
  import { getBlockStyles } from '../../functions/get-block-styles.js';
12
11
  import { getBlockTag } from '../../functions/get-block-tag.js';
13
12
  import { getProcessedBlock } from '../../functions/get-processed-block.js';
14
- import BlockStyles, { } from './block-styles.svelte';
15
13
  import { isEmptyHtmlElement } from './render-block.helpers.js';
14
+ import RenderComponentAndStyles, { } from './render-component-and-styles.svelte';
16
15
 
17
16
 
18
17
 
@@ -70,22 +69,32 @@ return getProcessedBlock({
70
69
  });
71
70
  };
72
71
 
73
- $: propertiesAndActions = () => {
72
+ $: attributes = () => {
74
73
  return { ...getBlockProperties(useBlock()),
75
74
  ...getBlockActions({
76
75
  block: useBlock(),
77
76
  state: builderContext.state,
78
77
  context: builderContext.context
79
- })
78
+ }),
79
+ style: getBlockStyles(useBlock())
80
80
  };
81
81
  };
82
82
 
83
- $: css = () => {
84
- return getBlockStyles(useBlock());
83
+ $: shouldWrap = () => {
84
+ return !componentInfo?.()?.noWrap;
85
85
  };
86
86
 
87
87
  $: componentOptions = () => {
88
- return getBlockComponentOptions(useBlock());
88
+ return { ...getBlockComponentOptions(useBlock()),
89
+
90
+ /**
91
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
92
+ * they are provided to the component itself directly.
93
+ */
94
+ ...(shouldWrap() ? {} : {
95
+ attributes: attributes()
96
+ })
97
+ };
89
98
  };
90
99
 
91
100
  $: children = () => {
@@ -97,6 +106,10 @@ return useBlock().children ?? [];
97
106
  };
98
107
 
99
108
  $: noCompRefChildren = () => {
109
+ /**
110
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
111
+ * we render them outside of `componentRef`
112
+ */
100
113
  return componentRef() ? [] : children();
101
114
  };
102
115
 
@@ -112,41 +125,16 @@ return componentRef() ? [] : children();
112
125
  </script>
113
126
 
114
127
 
115
- {#if !componentInfo?.()?.noWrap }
128
+ {#if shouldWrap() }
116
129
 
117
130
 
118
131
 
119
132
  {#if !isEmptyHtmlElement(tagName()) }
120
133
 
121
134
 
122
- <svelte:element {...propertiesAndActions()} style={css()} this={tagName()} >
123
-
124
-
125
- {#if TARGET === 'vue' || TARGET === 'svelte' }
126
-
127
-
128
- <BlockStyles block={useBlock()} ></BlockStyles>
129
-
135
+ <svelte:element {...attributes()} this={tagName()} >
130
136
 
131
-
132
-
133
- {/if}
134
-
135
-
136
-
137
- {#if componentRef() }
138
- <svelte:component {...componentOptions()} builderBlock={useBlock()} this={componentRef()} >
139
-
140
-
141
- {#each children() as child, index }
142
- <svelte:self key={child.id} block={child} ></svelte:self>
143
- {/each}
144
-
145
-
146
- </svelte:component>
147
-
148
-
149
- {/if}
137
+ <RenderComponentAndStyles block={useBlock()} blockChildren={children()} componentRef={componentRef()} componentOptions={componentOptions()} ></RenderComponentAndStyles>
150
138
 
151
139
 
152
140
 
@@ -161,7 +149,7 @@ return componentRef() ? [] : children();
161
149
 
162
150
 
163
151
  {:else}
164
- <svelte:element {...propertiesAndActions()} style={css()} this={tagName()} ></svelte:element>
152
+ <svelte:element {...attributes()} this={tagName()} ></svelte:element>
165
153
 
166
154
  {/if}
167
155
 
@@ -169,14 +157,6 @@ return componentRef() ? [] : children();
169
157
 
170
158
 
171
159
  {:else}
172
- <svelte:component {...componentOptions()} attributes={propertiesAndActions()} builderBlock={useBlock()} style={css()} this={componentRef()} >
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>
160
+ <RenderComponentAndStyles block={useBlock()} blockChildren={children()} componentRef={componentRef()} componentOptions={componentOptions()} ></RenderComponentAndStyles>
181
161
 
182
162
  {/if}
@@ -0,0 +1,61 @@
1
+ <script>
2
+
3
+
4
+
5
+
6
+ import { TARGET } from '../../constants/target.js';
7
+ import BlockStyles, { } from './block-styles.svelte';
8
+ import RenderBlock, { } from './render-block.svelte';
9
+
10
+
11
+
12
+
13
+
14
+
15
+ export let block;
16
+ export let componentRef;
17
+ export let componentOptions;
18
+ export let blockChildren;
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+ </script>
33
+
34
+
35
+
36
+
37
+ {#if TARGET === 'vue' || TARGET === 'svelte' }
38
+
39
+
40
+ <BlockStyles block={block} ></BlockStyles>
41
+
42
+
43
+
44
+
45
+ {/if}
46
+
47
+
48
+
49
+ {#if componentRef }
50
+ <svelte:component {...componentOptions} this={componentRef} >
51
+
52
+
53
+ {#each blockChildren as child, index }
54
+ <RenderBlock key={child.id} block={child} ></RenderBlock>
55
+ {/each}
56
+
57
+
58
+ </svelte:component>
59
+
60
+
61
+ {/if}
@@ -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