@builder.io/sdk-svelte 0.4.0 → 0.4.2
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 +10 -0
- package/package/blocks/BaseText.svelte +3 -1
- package/package/blocks/columns/columns.svelte +1 -1
- package/package/blocks/embed/embed.svelte +1 -1
- package/package/blocks/img/component-info.js +1 -1
- package/package/blocks/symbol/symbol.svelte +9 -9
- package/package/components/render-block/render-block.svelte +18 -39
- package/package/components/render-block/render-block.svelte.d.ts +2 -1
- package/package/components/render-block/render-component.svelte +1 -1
- package/package/components/render-block/render-component.svelte.d.ts +2 -1
- package/package/components/render-block/render-repeated-block.svelte +5 -13
- package/package/components/render-block/render-repeated-block.svelte.d.ts +1 -1
- package/package/components/render-blocks.svelte +4 -1
- package/package/components/render-content/render-content.svelte +83 -95
- package/package/components/render-content/render-content.svelte.d.ts +5 -5
- package/package/constants/sdk-version.d.ts +1 -1
- package/package/constants/sdk-version.js +1 -1
- package/package/context/builder.context.d.ts +2 -2
- package/package/context/builder.context.js +3 -2
- package/package/functions/get-builder-search-params/index.d.ts +6 -0
- package/package/functions/get-builder-search-params/index.js +6 -0
- package/package/index.d.ts +1 -0
- package/package/index.js +1 -0
- package/package.json +1 -1
- package/src/blocks/BaseText.svelte +3 -1
- package/src/blocks/columns/columns.svelte +1 -1
- package/src/blocks/embed/embed.svelte +1 -1
- package/src/blocks/img/component-info.ts +1 -1
- package/src/blocks/symbol/symbol.svelte +9 -9
- package/src/components/render-block/render-block.svelte +19 -40
- package/src/components/render-block/render-component.svelte +3 -2
- package/src/components/render-block/render-repeated-block.svelte +6 -13
- package/src/components/render-blocks.svelte +4 -1
- package/src/components/render-content/render-content.svelte +94 -103
- package/src/constants/sdk-version.ts +1 -1
- package/src/context/builder.context.ts +3 -2
- package/src/functions/get-builder-search-params/index.ts +6 -0
- package/src/index.ts +2 -0
|
@@ -2,21 +2,21 @@ import { SvelteComponentTyped } from "svelte";
|
|
|
2
2
|
import type { RenderContentProps } from "./render-content.types.js";
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
|
-
content: RenderContentProps["content"];
|
|
6
|
-
data: RenderContentProps["data"];
|
|
7
5
|
canTrack: RenderContentProps["canTrack"];
|
|
8
|
-
locale: RenderContentProps["locale"];
|
|
9
|
-
customComponents: RenderContentProps["customComponents"];
|
|
10
6
|
model: RenderContentProps["model"];
|
|
11
7
|
context: RenderContentProps["context"];
|
|
12
8
|
apiKey: RenderContentProps["apiKey"];
|
|
9
|
+
content: RenderContentProps["content"];
|
|
13
10
|
parentContentId: RenderContentProps["parentContentId"];
|
|
11
|
+
data: RenderContentProps["data"];
|
|
12
|
+
locale: RenderContentProps["locale"];
|
|
13
|
+
apiVersion: RenderContentProps["apiVersion"];
|
|
14
|
+
customComponents: RenderContentProps["customComponents"];
|
|
14
15
|
hideContent: RenderContentProps["hideContent"];
|
|
15
16
|
classNameProp: RenderContentProps["classNameProp"];
|
|
16
17
|
isSsrAbTest: RenderContentProps["isSsrAbTest"];
|
|
17
18
|
includeRefs: RenderContentProps["includeRefs"];
|
|
18
19
|
enrich: RenderContentProps["enrich"];
|
|
19
|
-
apiVersion: RenderContentProps["apiVersion"];
|
|
20
20
|
};
|
|
21
21
|
events: {
|
|
22
22
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "0.4.
|
|
1
|
+
export declare const SDK_VERSION = "0.4.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "0.4.
|
|
1
|
+
export const SDK_VERSION = "0.4.2";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
declare const _default: {
|
|
2
|
-
Builder: {
|
|
2
|
+
Builder: import("svelte/store").Writable<{
|
|
3
3
|
content: null;
|
|
4
4
|
context: {};
|
|
5
5
|
localState: undefined;
|
|
@@ -9,7 +9,7 @@ declare const _default: {
|
|
|
9
9
|
apiVersion: undefined;
|
|
10
10
|
registeredComponents: {};
|
|
11
11
|
inheritedStyles: {};
|
|
12
|
-
}
|
|
12
|
+
}>;
|
|
13
13
|
key: symbol;
|
|
14
14
|
};
|
|
15
15
|
export default _default;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const key = Symbol();
|
|
2
|
+
import { writable } from "svelte/store";
|
|
2
3
|
export default {
|
|
3
|
-
Builder: {
|
|
4
|
+
Builder: writable({
|
|
4
5
|
content: null,
|
|
5
6
|
context: {},
|
|
6
7
|
localState: undefined,
|
|
@@ -10,6 +11,6 @@ export default {
|
|
|
10
11
|
apiVersion: undefined,
|
|
11
12
|
registeredComponents: {},
|
|
12
13
|
inheritedStyles: {},
|
|
13
|
-
},
|
|
14
|
+
}),
|
|
14
15
|
key,
|
|
15
16
|
};
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
type QueryObject = Record<string, string | string[]>;
|
|
2
2
|
export declare const convertSearchParamsToQueryObject: (searchParams: URLSearchParams) => QueryObject;
|
|
3
|
+
/**
|
|
4
|
+
* Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
|
|
5
|
+
* relevant to the Builder SDK.
|
|
6
|
+
*
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
3
9
|
export declare const getBuilderSearchParams: (_options: QueryObject | URLSearchParams | undefined) => QueryObject;
|
|
4
10
|
export declare const getBuilderSearchParamsFromWindow: () => QueryObject;
|
|
5
11
|
export declare const normalizeSearchParams: (searchParams: QueryObject | URLSearchParams) => QueryObject;
|
|
@@ -8,6 +8,12 @@ export const convertSearchParamsToQueryObject = (searchParams) => {
|
|
|
8
8
|
});
|
|
9
9
|
return options;
|
|
10
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Receives a `URLSearchParams` object or a regular query object, and returns the subset of query params that are
|
|
13
|
+
* relevant to the Builder SDK.
|
|
14
|
+
*
|
|
15
|
+
* @returns
|
|
16
|
+
*/
|
|
11
17
|
export const getBuilderSearchParams = (_options) => {
|
|
12
18
|
if (!_options) {
|
|
13
19
|
return {};
|
package/package/index.d.ts
CHANGED
|
@@ -8,6 +8,7 @@ export type { InsertMenuConfig, InsertMenuItem } from './functions/register.js';
|
|
|
8
8
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
9
9
|
export type { Settings } from './functions/set-editor-settings.js';
|
|
10
10
|
export { getAllContent, getContent, processContentResult, } from './functions/get-content/index.js';
|
|
11
|
+
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
11
12
|
export { track } from './functions/track/index.js';
|
|
12
13
|
export type { RegisteredComponent } from './context/types';
|
|
13
14
|
export type { ComponentInfo } from './types/components';
|
package/package/index.js
CHANGED
|
@@ -6,4 +6,5 @@ export { createRegisterComponentMessage } from './functions/register-component.j
|
|
|
6
6
|
export { register } from './functions/register.js';
|
|
7
7
|
export { setEditorSettings } from './functions/set-editor-settings.js';
|
|
8
8
|
export { getAllContent, getContent, processContentResult, } from './functions/get-content/index.js';
|
|
9
|
+
export { getBuilderSearchParams } from './functions/get-builder-search-params/index.js';
|
|
9
10
|
export { track } from './functions/track/index.js';
|
package/package.json
CHANGED
|
@@ -106,7 +106,7 @@
|
|
|
106
106
|
}
|
|
107
107
|
function getWidthForBreakpointSize(size: SizeName) {
|
|
108
108
|
const breakpointSizes = getSizesForBreakpoints(
|
|
109
|
-
builderContext.content?.meta?.breakpoints || {}
|
|
109
|
+
$builderContext.content?.meta?.breakpoints || {}
|
|
110
110
|
);
|
|
111
111
|
return breakpointSizes[size].max;
|
|
112
112
|
}
|
|
@@ -78,12 +78,12 @@
|
|
|
78
78
|
!contentToUse &&
|
|
79
79
|
symbol?.model &&
|
|
80
80
|
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
81
|
-
builderContext?.apiKey
|
|
81
|
+
$builderContext?.apiKey
|
|
82
82
|
) {
|
|
83
83
|
getContent({
|
|
84
84
|
model: symbol.model,
|
|
85
|
-
apiKey: builderContext.apiKey,
|
|
86
|
-
apiVersion: builderContext.apiVersion,
|
|
85
|
+
apiKey: $builderContext.apiKey,
|
|
86
|
+
apiVersion: $builderContext.apiVersion,
|
|
87
87
|
query: {
|
|
88
88
|
id: symbol.entry,
|
|
89
89
|
},
|
|
@@ -115,7 +115,7 @@
|
|
|
115
115
|
fetchContent();
|
|
116
116
|
});
|
|
117
117
|
|
|
118
|
-
function onUpdateFn_0() {
|
|
118
|
+
function onUpdateFn_0(..._args: any[]) {
|
|
119
119
|
fetchContent();
|
|
120
120
|
}
|
|
121
121
|
$: onUpdateFn_0(...[symbol]);
|
|
@@ -130,13 +130,13 @@
|
|
|
130
130
|
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
131
131
|
>
|
|
132
132
|
<RenderContent
|
|
133
|
-
apiVersion={builderContext.apiVersion}
|
|
134
|
-
apiKey={builderContext.apiKey}
|
|
135
|
-
context={builderContext.context}
|
|
136
|
-
customComponents={Object.values(builderContext.registeredComponents)}
|
|
133
|
+
apiVersion={$builderContext.apiVersion}
|
|
134
|
+
apiKey={$builderContext.apiKey}
|
|
135
|
+
context={$builderContext.context}
|
|
136
|
+
customComponents={Object.values($builderContext.registeredComponents)}
|
|
137
137
|
data={{
|
|
138
138
|
...symbol?.data,
|
|
139
|
-
|
|
139
|
+
...$builderContext.localState,
|
|
140
140
|
...contentToUse?.data?.state,
|
|
141
141
|
}}
|
|
142
142
|
model={symbol?.model}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
2
|
export type RenderBlockProps = {
|
|
3
3
|
block: BuilderBlock;
|
|
4
|
-
context: BuilderContextInterface
|
|
4
|
+
context: Writable<BuilderContextInterface>;
|
|
5
5
|
};
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
|
+
import { writable } from "svelte/store";
|
|
10
|
+
|
|
9
11
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
10
12
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
11
13
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
@@ -24,6 +26,7 @@
|
|
|
24
26
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
25
27
|
import RenderComponent from "./render-component.svelte";
|
|
26
28
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
29
|
+
import type { Writable } from "svelte/store";
|
|
27
30
|
|
|
28
31
|
const setAttrs = (node, attrs = {}) => {
|
|
29
32
|
const attrKeys = Object.keys(attrs);
|
|
@@ -49,7 +52,7 @@
|
|
|
49
52
|
$: repeatItem = () => {
|
|
50
53
|
return getRepeatItemData({
|
|
51
54
|
block: block,
|
|
52
|
-
context: context,
|
|
55
|
+
context: $context,
|
|
53
56
|
});
|
|
54
57
|
};
|
|
55
58
|
$: useBlock = () => {
|
|
@@ -57,10 +60,10 @@
|
|
|
57
60
|
? block
|
|
58
61
|
: getProcessedBlock({
|
|
59
62
|
block: block,
|
|
60
|
-
localState: context.localState,
|
|
61
|
-
rootState: context.rootState,
|
|
62
|
-
rootSetState: context.rootSetState,
|
|
63
|
-
context: context.context,
|
|
63
|
+
localState: $context.localState,
|
|
64
|
+
rootState: $context.rootState,
|
|
65
|
+
rootSetState: $context.rootSetState,
|
|
66
|
+
context: $context.context,
|
|
64
67
|
shouldEvaluateBindings: true,
|
|
65
68
|
});
|
|
66
69
|
};
|
|
@@ -76,10 +79,10 @@
|
|
|
76
79
|
$: actions = () => {
|
|
77
80
|
return getBlockActions({
|
|
78
81
|
block: useBlock(),
|
|
79
|
-
rootState: context.rootState,
|
|
80
|
-
rootSetState: context.rootSetState,
|
|
81
|
-
localState: context.localState,
|
|
82
|
-
context: context.context,
|
|
82
|
+
rootState: $context.rootState,
|
|
83
|
+
rootSetState: $context.rootSetState,
|
|
84
|
+
localState: $context.localState,
|
|
85
|
+
context: $context.context,
|
|
83
86
|
});
|
|
84
87
|
};
|
|
85
88
|
$: attributes = () => {
|
|
@@ -90,7 +93,7 @@
|
|
|
90
93
|
? {
|
|
91
94
|
style: getReactNativeBlockStyles({
|
|
92
95
|
block: useBlock(),
|
|
93
|
-
context: context,
|
|
96
|
+
context: $context,
|
|
94
97
|
blockStyles: blockProperties.style,
|
|
95
98
|
}),
|
|
96
99
|
}
|
|
@@ -108,31 +111,6 @@
|
|
|
108
111
|
!component?.component && !repeatItem();
|
|
109
112
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
110
113
|
};
|
|
111
|
-
$: childrenContext = () => {
|
|
112
|
-
const getInheritedTextStyles = () => {
|
|
113
|
-
if (TARGET !== "reactNative") {
|
|
114
|
-
return {};
|
|
115
|
-
}
|
|
116
|
-
return extractTextStyles(
|
|
117
|
-
getReactNativeBlockStyles({
|
|
118
|
-
block: useBlock(),
|
|
119
|
-
context: context,
|
|
120
|
-
blockStyles: attributes().style,
|
|
121
|
-
})
|
|
122
|
-
);
|
|
123
|
-
};
|
|
124
|
-
return {
|
|
125
|
-
apiKey: context.apiKey,
|
|
126
|
-
apiVersion: context.apiVersion,
|
|
127
|
-
localState: context.localState,
|
|
128
|
-
rootState: context.rootState,
|
|
129
|
-
rootSetState: context.rootSetState,
|
|
130
|
-
content: context.content,
|
|
131
|
-
context: context.context,
|
|
132
|
-
registeredComponents: context.registeredComponents,
|
|
133
|
-
inheritedStyles: getInheritedTextStyles(),
|
|
134
|
-
};
|
|
135
|
-
};
|
|
136
114
|
$: renderComponentProps = () => {
|
|
137
115
|
return {
|
|
138
116
|
blockChildren: useBlock().children ?? [],
|
|
@@ -152,15 +130,16 @@
|
|
|
152
130
|
},
|
|
153
131
|
}),
|
|
154
132
|
},
|
|
155
|
-
context: childrenContext
|
|
133
|
+
context: childrenContext,
|
|
156
134
|
};
|
|
157
135
|
};
|
|
158
136
|
|
|
159
137
|
let component = getComponent({
|
|
160
138
|
block: block,
|
|
161
|
-
context: context,
|
|
139
|
+
context: $context,
|
|
162
140
|
});
|
|
163
141
|
let Tag = block.tagName || "div";
|
|
142
|
+
let childrenContext = writable($context);
|
|
164
143
|
</script>
|
|
165
144
|
|
|
166
145
|
{#if canShowBlock()}
|
|
@@ -180,11 +159,11 @@
|
|
|
180
159
|
<RenderComponent {...renderComponentProps()} />
|
|
181
160
|
|
|
182
161
|
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
183
|
-
<svelte:self block={child} context={childrenContext
|
|
162
|
+
<svelte:self block={child} context={childrenContext} />
|
|
184
163
|
{/each}
|
|
185
164
|
|
|
186
165
|
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
187
|
-
<BlockStyles block={child} context={childrenContext
|
|
166
|
+
<BlockStyles block={child} context={$childrenContext} />
|
|
188
167
|
{/each}
|
|
189
168
|
</svelte:element>
|
|
190
169
|
{/if}
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
componentRef: any;
|
|
11
11
|
componentOptions: ComponentOptions;
|
|
12
12
|
blockChildren: BuilderBlock[];
|
|
13
|
-
context: BuilderContextInterface
|
|
13
|
+
context: Writable<BuilderContextInterface>;
|
|
14
14
|
}
|
|
15
15
|
</script>
|
|
16
16
|
|
|
@@ -19,6 +19,7 @@
|
|
|
19
19
|
import BlockStyles from "./block-styles.svelte";
|
|
20
20
|
import RenderBlock from "./render-block.svelte";
|
|
21
21
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
22
|
+
import type { Writable } from "svelte/store";
|
|
22
23
|
|
|
23
24
|
export let componentRef: RenderComponentProps["componentRef"];
|
|
24
25
|
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
@@ -33,7 +34,7 @@
|
|
|
33
34
|
{/each}
|
|
34
35
|
|
|
35
36
|
{#each blockChildren as child ("block-style-" + child.id)}
|
|
36
|
-
<BlockStyles block={child} {context} />
|
|
37
|
+
<BlockStyles block={child} context={$context} />
|
|
37
38
|
{/each}
|
|
38
39
|
</svelte:component>
|
|
39
40
|
{/if}
|
|
@@ -17,26 +17,19 @@
|
|
|
17
17
|
|
|
18
18
|
<script lang="ts">
|
|
19
19
|
import { setContext } from "svelte";
|
|
20
|
+
import { writable } from "svelte/store";
|
|
20
21
|
|
|
21
22
|
import BuilderContext from "../../context/builder.context.js";
|
|
22
23
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
23
24
|
import type { BuilderBlock } from "../../types/builder-block";
|
|
24
25
|
import RenderBlock from "./render-block.svelte";
|
|
25
26
|
|
|
26
|
-
export let block: Props["block"];
|
|
27
27
|
export let repeatContext: Props["repeatContext"];
|
|
28
|
+
export let block: Props["block"];
|
|
29
|
+
|
|
30
|
+
let store = writable(repeatContext);
|
|
28
31
|
|
|
29
|
-
setContext(BuilderContext.key,
|
|
30
|
-
content: repeatContext.content,
|
|
31
|
-
localState: repeatContext.localState,
|
|
32
|
-
rootState: repeatContext.rootState,
|
|
33
|
-
rootSetState: repeatContext.rootSetState,
|
|
34
|
-
context: repeatContext.context,
|
|
35
|
-
apiKey: repeatContext.apiKey,
|
|
36
|
-
registeredComponents: repeatContext.registeredComponents,
|
|
37
|
-
inheritedStyles: repeatContext.inheritedStyles,
|
|
38
|
-
apiVersion: repeatContext.apiVersion,
|
|
39
|
-
});
|
|
32
|
+
setContext(BuilderContext.key, store);
|
|
40
33
|
</script>
|
|
41
34
|
|
|
42
|
-
<RenderBlock {block} context={
|
|
35
|
+
<RenderBlock {block} context={store} />
|
|
@@ -80,6 +80,9 @@
|
|
|
80
80
|
on:mouseenter={(event) => {
|
|
81
81
|
onMouseEnter();
|
|
82
82
|
}}
|
|
83
|
+
on:keypress={(event) => {
|
|
84
|
+
onClick();
|
|
85
|
+
}}
|
|
83
86
|
>
|
|
84
87
|
{#if blocks}
|
|
85
88
|
{#each blocks as block ("render-block-" + block.id)}
|
|
@@ -89,7 +92,7 @@
|
|
|
89
92
|
|
|
90
93
|
{#if blocks}
|
|
91
94
|
{#each blocks as block ("block-style-" + block.id)}
|
|
92
|
-
<BlockStyles {block} context={builderContext} />
|
|
95
|
+
<BlockStyles {block} context={$builderContext} />
|
|
93
96
|
{/each}
|
|
94
97
|
{/if}
|
|
95
98
|
</div>
|