@builder.io/sdk-svelte 4.1.3 → 4.2.3
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/lib/browser/blocks/form/form/form.svelte +8 -6
- package/lib/browser/blocks/img/component-info.js +33 -3
- package/lib/browser/blocks/img/img.svelte +18 -6
- package/lib/browser/blocks/symbol/symbol.svelte +5 -2
- package/lib/browser/blocks/symbol/symbol.svelte.d.ts +1 -1
- package/lib/browser/blocks/symbol/symbol.types.d.ts +1 -2
- package/lib/browser/blocks/tabs/tabs.svelte +5 -4
- package/lib/browser/blocks/tabs/tabs.svelte.d.ts +1 -1
- package/lib/browser/blocks/text/component-info.js +0 -1
- package/lib/browser/components/awaiter.types.d.ts +7 -0
- package/lib/browser/components/awaiter.types.js +1 -0
- package/lib/browser/components/block/block.svelte +2 -2
- package/lib/browser/components/block/components/component-ref/component-ref.svelte +8 -8
- package/lib/browser/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
- package/lib/browser/components/block/components/interactive-element.svelte +8 -1
- package/lib/browser/components/block/components/live-edit-block-styles.svelte +114 -0
- package/lib/browser/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
- package/lib/browser/components/block/components/style-wrapper.svelte +25 -0
- package/lib/browser/components/block/components/style-wrapper.svelte.d.ts +23 -0
- package/lib/browser/components/content/components/enable-editor.svelte +53 -12
- package/lib/browser/components/live-edit.svelte +20 -0
- package/lib/browser/components/live-edit.svelte.d.ts +26 -0
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/get-content/generate-content-url.js +3 -8
- package/lib/browser/functions/get-content/index.js +8 -0
- package/lib/browser/functions/register.d.ts +18 -0
- package/lib/browser/functions/register.js +12 -0
- package/lib/browser/helpers/find-block.d.ts +18 -0
- package/lib/browser/helpers/find-block.js +41 -0
- package/lib/browser/helpers/subscribe-to-editor.d.ts +3 -2
- package/lib/browser/helpers/subscribe-to-editor.js +4 -2
- package/lib/browser/server-index.d.ts +1 -1
- package/lib/browser/server-index.js +1 -1
- package/lib/edge/blocks/form/form/form.svelte +8 -6
- package/lib/edge/blocks/img/component-info.js +33 -3
- package/lib/edge/blocks/img/img.svelte +18 -6
- package/lib/edge/blocks/symbol/symbol.svelte +5 -2
- package/lib/edge/blocks/symbol/symbol.svelte.d.ts +1 -1
- package/lib/edge/blocks/symbol/symbol.types.d.ts +1 -2
- package/lib/edge/blocks/tabs/tabs.svelte +5 -4
- package/lib/edge/blocks/tabs/tabs.svelte.d.ts +1 -1
- package/lib/edge/blocks/text/component-info.js +0 -1
- package/lib/edge/components/awaiter.types.d.ts +7 -0
- package/lib/edge/components/awaiter.types.js +1 -0
- package/lib/edge/components/block/block.svelte +2 -2
- package/lib/edge/components/block/components/component-ref/component-ref.svelte +8 -8
- package/lib/edge/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
- package/lib/edge/components/block/components/interactive-element.svelte +8 -1
- package/lib/edge/components/block/components/live-edit-block-styles.svelte +114 -0
- package/lib/edge/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
- package/lib/edge/components/block/components/style-wrapper.svelte +25 -0
- package/lib/edge/components/block/components/style-wrapper.svelte.d.ts +23 -0
- package/lib/edge/components/content/components/enable-editor.svelte +53 -12
- package/lib/edge/components/live-edit.svelte +20 -0
- package/lib/edge/components/live-edit.svelte.d.ts +26 -0
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/get-content/generate-content-url.js +3 -8
- package/lib/edge/functions/get-content/index.js +8 -0
- package/lib/edge/functions/register.d.ts +18 -0
- package/lib/edge/functions/register.js +12 -0
- package/lib/edge/helpers/find-block.d.ts +18 -0
- package/lib/edge/helpers/find-block.js +41 -0
- package/lib/edge/helpers/subscribe-to-editor.d.ts +3 -2
- package/lib/edge/helpers/subscribe-to-editor.js +4 -2
- package/lib/edge/server-index.d.ts +1 -1
- package/lib/edge/server-index.js +1 -1
- package/lib/node/blocks/form/form/form.svelte +8 -6
- package/lib/node/blocks/img/component-info.js +33 -3
- package/lib/node/blocks/img/img.svelte +18 -6
- package/lib/node/blocks/symbol/symbol.svelte +5 -2
- package/lib/node/blocks/symbol/symbol.svelte.d.ts +1 -1
- package/lib/node/blocks/symbol/symbol.types.d.ts +1 -2
- package/lib/node/blocks/tabs/tabs.svelte +5 -4
- package/lib/node/blocks/tabs/tabs.svelte.d.ts +1 -1
- package/lib/node/blocks/text/component-info.js +0 -1
- package/lib/node/components/awaiter.types.d.ts +7 -0
- package/lib/node/components/awaiter.types.js +1 -0
- package/lib/node/components/block/block.svelte +2 -2
- package/lib/node/components/block/components/component-ref/component-ref.svelte +8 -8
- package/lib/node/components/block/components/component-ref/component-ref.svelte.d.ts +2 -2
- package/lib/node/components/block/components/interactive-element.svelte +8 -1
- package/lib/node/components/block/components/live-edit-block-styles.svelte +114 -0
- package/lib/node/components/block/components/live-edit-block-styles.svelte.d.ts +22 -0
- package/lib/node/components/block/components/style-wrapper.svelte +25 -0
- package/lib/node/components/block/components/style-wrapper.svelte.d.ts +23 -0
- package/lib/node/components/content/components/enable-editor.svelte +53 -12
- package/lib/node/components/live-edit.svelte +20 -0
- package/lib/node/components/live-edit.svelte.d.ts +26 -0
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/get-content/generate-content-url.js +3 -8
- package/lib/node/functions/get-content/index.js +8 -0
- package/lib/node/functions/register.d.ts +18 -0
- package/lib/node/functions/register.js +12 -0
- package/lib/node/helpers/find-block.d.ts +18 -0
- package/lib/node/helpers/find-block.js +41 -0
- package/lib/node/helpers/subscribe-to-editor.d.ts +3 -2
- package/lib/node/helpers/subscribe-to-editor.js +4 -2
- package/lib/node/server-index.d.ts +1 -1
- package/lib/node/server-index.js +1 -1
- package/package.json +1 -1
- package/src/blocks/form/form/form.svelte +11 -6
- package/src/blocks/img/component-info.ts +33 -3
- package/src/blocks/img/img.svelte +22 -6
- package/src/blocks/symbol/symbol.svelte +5 -2
- package/src/blocks/symbol/symbol.types.ts +1 -1
- package/src/blocks/tabs/tabs.svelte +5 -4
- package/src/blocks/text/component-info.ts +0 -1
- package/src/components/awaiter.types.ts +7 -0
- package/src/components/block/block.svelte +2 -2
- package/src/components/block/components/component-ref/component-ref.svelte +8 -10
- package/src/components/block/components/interactive-element.svelte +7 -0
- package/src/components/block/components/live-edit-block-styles.svelte +146 -0
- package/src/components/block/components/style-wrapper.svelte +41 -0
- package/src/components/content/components/enable-editor.svelte +113 -40
- package/src/components/live-edit.svelte +32 -0
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/get-content/generate-content-url.ts +3 -8
- package/src/functions/get-content/index.ts +8 -0
- package/src/functions/register.ts +29 -0
- package/src/helpers/find-block.ts +40 -0
- package/src/helpers/subscribe-to-editor.ts +7 -4
- package/src/server-index.ts +1 -1
|
@@ -15,7 +15,7 @@ import { getInteractionPropertiesForEvent } from "../../../functions/track/inter
|
|
|
15
15
|
import { getDefaultCanTrack } from "../../../helpers/canTrack";
|
|
16
16
|
import { getCookieSync } from "../../../helpers/cookie";
|
|
17
17
|
import "../../../helpers/preview-lru-cache/set";
|
|
18
|
-
import { createEditorListener } from "../../../helpers/subscribe-to-editor";
|
|
18
|
+
import { createEditorListener, } from "../../../helpers/subscribe-to-editor";
|
|
19
19
|
import { setupBrowserForEditing } from "../../../scripts/init-editing";
|
|
20
20
|
import { triggerAnimation } from "../../block/animator";
|
|
21
21
|
import "../../dynamic-div.svelte";
|
|
@@ -46,7 +46,7 @@ function stringifyStyles(stylesObj) {
|
|
|
46
46
|
}
|
|
47
47
|
return styles;
|
|
48
48
|
}
|
|
49
|
-
function mergeNewRootState(newData) {
|
|
49
|
+
function mergeNewRootState(newData, editType) {
|
|
50
50
|
const combinedState = {
|
|
51
51
|
...$builderContextSignal.rootState,
|
|
52
52
|
...newData,
|
|
@@ -57,8 +57,14 @@ function mergeNewRootState(newData) {
|
|
|
57
57
|
else {
|
|
58
58
|
$builderContextSignal.rootState = combinedState;
|
|
59
59
|
}
|
|
60
|
+
if ($builderContextSignal.rootSetState) {
|
|
61
|
+
$builderContextSignal.rootSetState(combinedState);
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
$builderContextSignal.rootState = combinedState;
|
|
65
|
+
}
|
|
60
66
|
}
|
|
61
|
-
function mergeNewContent(newContent) {
|
|
67
|
+
function mergeNewContent(newContent, editType) {
|
|
62
68
|
const newContentValue = {
|
|
63
69
|
...$builderContextSignal.content,
|
|
64
70
|
...newContent,
|
|
@@ -96,11 +102,11 @@ function processMessage(event) {
|
|
|
96
102
|
animation: (animation) => {
|
|
97
103
|
triggerAnimation(animation);
|
|
98
104
|
},
|
|
99
|
-
contentUpdate: (newContent) => {
|
|
100
|
-
mergeNewContent(newContent);
|
|
105
|
+
contentUpdate: (newContent, editType) => {
|
|
106
|
+
mergeNewContent(newContent, editType);
|
|
101
107
|
},
|
|
102
|
-
stateUpdate: (newState) => {
|
|
103
|
-
mergeNewRootState(newState);
|
|
108
|
+
stateUpdate: (newState, editType) => {
|
|
109
|
+
mergeNewRootState(newState, editType);
|
|
104
110
|
},
|
|
105
111
|
},
|
|
106
112
|
})(event);
|
|
@@ -126,15 +132,20 @@ function onClick(event) {
|
|
|
126
132
|
}
|
|
127
133
|
function runHttpRequests() {
|
|
128
134
|
const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
|
|
129
|
-
Object.entries(requests).forEach(([key,
|
|
130
|
-
if (!
|
|
135
|
+
Object.entries(requests).forEach(([key, httpRequest]) => {
|
|
136
|
+
if (!httpRequest)
|
|
131
137
|
return;
|
|
138
|
+
const isCoreRequest = typeof httpRequest === "object" &&
|
|
139
|
+
httpRequest["@type"] === "@builder.io/core:Request";
|
|
132
140
|
// request already in progress
|
|
133
141
|
if (httpReqsPending[key])
|
|
134
142
|
return;
|
|
135
143
|
// request already completed, and not in edit mode
|
|
136
144
|
if (httpReqsData[key] && !isEditing())
|
|
137
145
|
return;
|
|
146
|
+
const url = isCoreRequest
|
|
147
|
+
? httpRequest.request.url
|
|
148
|
+
: httpRequest;
|
|
138
149
|
httpReqsPending[key] = true;
|
|
139
150
|
const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
140
151
|
code: group,
|
|
@@ -143,8 +154,27 @@ function runHttpRequests() {
|
|
|
143
154
|
rootState: $builderContextSignal.rootState,
|
|
144
155
|
rootSetState: $builderContextSignal.rootSetState,
|
|
145
156
|
})));
|
|
146
|
-
|
|
147
|
-
|
|
157
|
+
const fetchRequestObj = isCoreRequest
|
|
158
|
+
? {
|
|
159
|
+
url: evaluatedUrl,
|
|
160
|
+
method: httpRequest.request.method,
|
|
161
|
+
headers: httpRequest.request.headers,
|
|
162
|
+
body: httpRequest.request.body,
|
|
163
|
+
}
|
|
164
|
+
: {
|
|
165
|
+
url: evaluatedUrl,
|
|
166
|
+
method: "GET",
|
|
167
|
+
};
|
|
168
|
+
logFetch(JSON.stringify(fetchRequestObj));
|
|
169
|
+
const fetchOptions = {
|
|
170
|
+
method: fetchRequestObj.method,
|
|
171
|
+
headers: fetchRequestObj.headers,
|
|
172
|
+
body: fetchRequestObj.body,
|
|
173
|
+
};
|
|
174
|
+
if (fetchRequestObj.method === "GET") {
|
|
175
|
+
delete fetchOptions.body;
|
|
176
|
+
}
|
|
177
|
+
fetch(fetchRequestObj.url, fetchOptions)
|
|
148
178
|
.then((response) => response.json())
|
|
149
179
|
.then((json) => {
|
|
150
180
|
mergeNewRootState({
|
|
@@ -153,7 +183,7 @@ function runHttpRequests() {
|
|
|
153
183
|
httpReqsData[key] = true;
|
|
154
184
|
})
|
|
155
185
|
.catch((err) => {
|
|
156
|
-
console.error("error fetching dynamic data",
|
|
186
|
+
console.error("error fetching dynamic data", JSON.stringify(httpRequest), err);
|
|
157
187
|
})
|
|
158
188
|
.finally(() => {
|
|
159
189
|
httpReqsPending[key] = false;
|
|
@@ -248,6 +278,9 @@ $: showContentProps = () => {
|
|
|
248
278
|
};
|
|
249
279
|
let elementRef;
|
|
250
280
|
let hasExecuted = false;
|
|
281
|
+
let contextValue = $builderContextSignal;
|
|
282
|
+
let prevData = null;
|
|
283
|
+
let prevLocale = "";
|
|
251
284
|
let ContentWrapper = contentWrapper || "div";
|
|
252
285
|
let httpReqsData = {};
|
|
253
286
|
let httpReqsPending = {};
|
|
@@ -304,15 +337,23 @@ $: onUpdateFn_1_builderContextSignal_rootState =
|
|
|
304
337
|
$: onUpdateFn_1(...[onUpdateFn_1_builderContextSignal_rootState]);
|
|
305
338
|
function onUpdateFn_2(..._args) {
|
|
306
339
|
if (data) {
|
|
340
|
+
if (prevData === data) {
|
|
341
|
+
return;
|
|
342
|
+
}
|
|
307
343
|
mergeNewRootState(data);
|
|
344
|
+
prevData = data;
|
|
308
345
|
}
|
|
309
346
|
}
|
|
310
347
|
$: onUpdateFn_2(...[data]);
|
|
311
348
|
function onUpdateFn_3(..._args) {
|
|
312
349
|
if (locale) {
|
|
350
|
+
if (prevLocale === locale) {
|
|
351
|
+
return;
|
|
352
|
+
}
|
|
313
353
|
mergeNewRootState({
|
|
314
354
|
locale: locale,
|
|
315
355
|
});
|
|
356
|
+
prevLocale = locale;
|
|
316
357
|
}
|
|
317
358
|
}
|
|
318
359
|
$: onUpdateFn_3(...[locale]);
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script context="module"></script>
|
|
2
|
+
|
|
3
|
+
<script>import { getContext } from "svelte";
|
|
4
|
+
import { BuilderContext } from "../context/index";
|
|
5
|
+
import { findBlockById } from "../helpers/find-block";
|
|
6
|
+
export let id = undefined;
|
|
7
|
+
export let attributes = undefined;
|
|
8
|
+
export let Wrapper = undefined;
|
|
9
|
+
let context = getContext(BuilderContext.key);
|
|
10
|
+
$: block = () => {
|
|
11
|
+
return findBlockById($context.content, id);
|
|
12
|
+
};
|
|
13
|
+
$: options = () => {
|
|
14
|
+
return block?.()?.component?.options || {};
|
|
15
|
+
};
|
|
16
|
+
</script>
|
|
17
|
+
|
|
18
|
+
<svelte:component this={Wrapper} {...options()} {attributes}
|
|
19
|
+
><slot /></svelte:component
|
|
20
|
+
>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
type LiveEditProps = {
|
|
3
|
+
children?: any;
|
|
4
|
+
id?: any;
|
|
5
|
+
Wrapper?: any;
|
|
6
|
+
attributes?: any;
|
|
7
|
+
};
|
|
8
|
+
declare const __propDef: {
|
|
9
|
+
props: {
|
|
10
|
+
id?: LiveEditProps["id"];
|
|
11
|
+
attributes?: LiveEditProps["attributes"];
|
|
12
|
+
Wrapper?: LiveEditProps["Wrapper"];
|
|
13
|
+
};
|
|
14
|
+
events: {
|
|
15
|
+
[evt: string]: CustomEvent<any>;
|
|
16
|
+
};
|
|
17
|
+
slots: {
|
|
18
|
+
default: {};
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
type LiveEditProps_ = typeof __propDef.props;
|
|
22
|
+
export { LiveEditProps_ as LiveEditProps };
|
|
23
|
+
export type LiveEditEvents = typeof __propDef.events;
|
|
24
|
+
export type LiveEditSlots = typeof __propDef.slots;
|
|
25
|
+
export default class LiveEdit extends SvelteComponent<LiveEditProps, LiveEditEvents, LiveEditSlots> {
|
|
26
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.
|
|
1
|
+
export declare const SDK_VERSION = "4.2.3";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "4.
|
|
1
|
+
export const SDK_VERSION = "4.2.3";
|
|
@@ -20,15 +20,10 @@ export const generateContentUrl = (options) => {
|
|
|
20
20
|
url.searchParams.set('limit', String(limit));
|
|
21
21
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
22
22
|
url.searchParams.set('includeRefs', String(true));
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (finalLocale) {
|
|
26
|
-
url.searchParams.set('locale', finalLocale);
|
|
27
|
-
finalUserAttributes = {
|
|
28
|
-
locale: finalLocale,
|
|
29
|
-
...finalUserAttributes
|
|
30
|
-
};
|
|
23
|
+
if (locale) {
|
|
24
|
+
url.searchParams.set('locale', locale);
|
|
31
25
|
}
|
|
26
|
+
let finalUserAttributes = userAttributes || {};
|
|
32
27
|
if (enrich)
|
|
33
28
|
url.searchParams.set('enrich', String(enrich));
|
|
34
29
|
url.searchParams.set('omit', omit ?? 'meta.componentsUsed');
|
|
@@ -12,6 +12,14 @@ const checkContentHasResults = (content) => 'results' in content;
|
|
|
12
12
|
* Returns the first content entry that matches the given options.
|
|
13
13
|
*/
|
|
14
14
|
export async function fetchOneEntry(options) {
|
|
15
|
+
const finalLocale = options.locale || options.userAttributes?.locale;
|
|
16
|
+
if (finalLocale) {
|
|
17
|
+
options.locale = finalLocale;
|
|
18
|
+
options.userAttributes = {
|
|
19
|
+
locale: finalLocale,
|
|
20
|
+
...options.userAttributes
|
|
21
|
+
};
|
|
22
|
+
}
|
|
15
23
|
const allContent = await fetchEntries({
|
|
16
24
|
...options,
|
|
17
25
|
limit: 1
|
|
@@ -1,5 +1,22 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
2
|
import type { DeepPartial } from '../types/deep-partial';
|
|
3
|
+
import type { Input } from '../types/input';
|
|
4
|
+
export interface Action {
|
|
5
|
+
name: string;
|
|
6
|
+
inputs?: readonly Input[];
|
|
7
|
+
returnType?: Input;
|
|
8
|
+
action: (options: Record<string, any>) => string;
|
|
9
|
+
/**
|
|
10
|
+
* Is an action for expression (e.g. calculating a binding like a formula
|
|
11
|
+
* to fill a value based on locale) or a function (e.g. something to trigger
|
|
12
|
+
* on an event like add to cart) or either (e.g. a custom code block)
|
|
13
|
+
*/
|
|
14
|
+
kind: 'expression' | 'function' | 'any';
|
|
15
|
+
/**
|
|
16
|
+
* Globally unique ID for an action, e.g. "@builder.io:setState"
|
|
17
|
+
*/
|
|
18
|
+
id: string;
|
|
19
|
+
}
|
|
3
20
|
export interface InsertMenuItem {
|
|
4
21
|
name: string;
|
|
5
22
|
icon?: string;
|
|
@@ -14,3 +31,4 @@ export interface InsertMenuConfig {
|
|
|
14
31
|
}
|
|
15
32
|
export declare function register(type: 'insertMenu', info: InsertMenuConfig): void;
|
|
16
33
|
export declare function register(type: string, info: any): void;
|
|
34
|
+
export declare function registerAction(action: Action): void;
|
|
@@ -29,3 +29,15 @@ export function register(type, info) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
|
+
export function registerAction(action) {
|
|
33
|
+
if (isBrowser()) {
|
|
34
|
+
const actionClone = JSON.parse(JSON.stringify(action));
|
|
35
|
+
if (action.action) {
|
|
36
|
+
actionClone.action = action.action.toString();
|
|
37
|
+
}
|
|
38
|
+
window.parent?.postMessage({
|
|
39
|
+
type: 'builder.registerAction',
|
|
40
|
+
data: actionClone
|
|
41
|
+
}, '*');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BuilderBlock, BuilderContent } from '../server-index';
|
|
2
|
+
/**
|
|
3
|
+
* Recursively searches for a block by ID.
|
|
4
|
+
*
|
|
5
|
+
* @param content The Builder content to search through.
|
|
6
|
+
* @param id The ID of the block to search for.
|
|
7
|
+
* @returns The block if found, otherwise null.
|
|
8
|
+
*/
|
|
9
|
+
export declare const findBlockById: (content: BuilderContent, id: string) => BuilderBlock | null;
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to recursively search through block tree.
|
|
12
|
+
*
|
|
13
|
+
* @param blocks The blocks to search through.
|
|
14
|
+
* @param id The ID of the block to search for.
|
|
15
|
+
* @returns The block if found, otherwise null.
|
|
16
|
+
* @private This is an internal implementation detail.
|
|
17
|
+
*/
|
|
18
|
+
export declare const findBlockInTree: (blocks: BuilderBlock[] | undefined, id: string) => BuilderBlock | null;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recursively searches for a block by ID.
|
|
3
|
+
*
|
|
4
|
+
* @param content The Builder content to search through.
|
|
5
|
+
* @param id The ID of the block to search for.
|
|
6
|
+
* @returns The block if found, otherwise null.
|
|
7
|
+
*/
|
|
8
|
+
export const findBlockById = (content, id) => {
|
|
9
|
+
return findBlockInTree(content.data?.blocks, id);
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* Helper function to recursively search through block tree.
|
|
13
|
+
*
|
|
14
|
+
* @param blocks The blocks to search through.
|
|
15
|
+
* @param id The ID of the block to search for.
|
|
16
|
+
* @returns The block if found, otherwise null.
|
|
17
|
+
* @private This is an internal implementation detail.
|
|
18
|
+
*/
|
|
19
|
+
export const findBlockInTree = (blocks, id) => {
|
|
20
|
+
if (!blocks)
|
|
21
|
+
return null;
|
|
22
|
+
for (const block of blocks) {
|
|
23
|
+
if (block.id === id)
|
|
24
|
+
return block;
|
|
25
|
+
if (block.children) {
|
|
26
|
+
const child = findBlockInTree(block.children, id);
|
|
27
|
+
if (child)
|
|
28
|
+
return child;
|
|
29
|
+
}
|
|
30
|
+
if (block.component?.name === 'Columns' && block.component?.options?.columns) {
|
|
31
|
+
for (const column of block.component.options.columns) {
|
|
32
|
+
if (column.blocks) {
|
|
33
|
+
const child = findBlockInTree(column.blocks, id);
|
|
34
|
+
if (child)
|
|
35
|
+
return child;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return null;
|
|
41
|
+
};
|
|
@@ -2,10 +2,11 @@ import type { ContentProps } from '../components/content/content.types';
|
|
|
2
2
|
import type { BuilderAnimation } from '../types/builder-block';
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content';
|
|
4
4
|
import type { Dictionary } from '../types/typescript';
|
|
5
|
+
export type EditType = 'client' | 'server' | undefined;
|
|
5
6
|
type ContentListener = Required<Pick<ContentProps, 'model' | 'trustedHosts'>> & {
|
|
6
7
|
callbacks: {
|
|
7
|
-
contentUpdate: (updatedContent: BuilderContent) => void;
|
|
8
|
-
stateUpdate: (newState: Dictionary<string
|
|
8
|
+
contentUpdate: (updatedContent: BuilderContent, editType?: EditType) => void;
|
|
9
|
+
stateUpdate: (newState: Dictionary<string>, editType?: EditType) => void;
|
|
9
10
|
animation: (updatedContent: BuilderAnimation) => void;
|
|
10
11
|
configureSdk: (updatedContent: any) => void;
|
|
11
12
|
};
|
|
@@ -25,8 +25,9 @@ export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
|
25
25
|
const messageContent = data.data;
|
|
26
26
|
const modelName = messageContent.model;
|
|
27
27
|
const newState = messageContent?.state;
|
|
28
|
+
const editType = messageContent.editType;
|
|
28
29
|
if (modelName === model && newState) {
|
|
29
|
-
callbacks.stateUpdate(newState);
|
|
30
|
+
callbacks.stateUpdate(newState, editType);
|
|
30
31
|
}
|
|
31
32
|
break;
|
|
32
33
|
}
|
|
@@ -35,8 +36,9 @@ export const createEditorListener = ({ model, trustedHosts, callbacks }) => {
|
|
|
35
36
|
const messageContent = data.data;
|
|
36
37
|
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
37
38
|
const contentData = messageContent.data;
|
|
39
|
+
const editType = messageContent.editType;
|
|
38
40
|
if (key === model) {
|
|
39
|
-
callbacks.contentUpdate(contentData);
|
|
41
|
+
callbacks.contentUpdate(contentData, editType);
|
|
40
42
|
}
|
|
41
43
|
break;
|
|
42
44
|
}
|
|
@@ -25,7 +25,7 @@ export type { ComponentInfo } from './types/components';
|
|
|
25
25
|
export { isEditing } from './functions/is-editing';
|
|
26
26
|
export { isPreviewing } from './functions/is-previewing';
|
|
27
27
|
export { createRegisterComponentMessage } from './functions/register-component';
|
|
28
|
-
export { register } from './functions/register';
|
|
28
|
+
export { register, registerAction } from './functions/register';
|
|
29
29
|
export type { InsertMenuConfig, InsertMenuItem } from './functions/register';
|
|
30
30
|
export { setEditorSettings } from './functions/set-editor-settings';
|
|
31
31
|
export type { Settings } from './functions/set-editor-settings';
|
|
@@ -5,7 +5,7 @@ export * from './index-helpers/top-of-file';
|
|
|
5
5
|
export { isEditing } from './functions/is-editing';
|
|
6
6
|
export { isPreviewing } from './functions/is-previewing';
|
|
7
7
|
export { createRegisterComponentMessage } from './functions/register-component';
|
|
8
|
-
export { register } from './functions/register';
|
|
8
|
+
export { register, registerAction } from './functions/register';
|
|
9
9
|
export { setEditorSettings } from './functions/set-editor-settings';
|
|
10
10
|
export { getBuilderSearchParams } from './functions/get-builder-search-params/index';
|
|
11
11
|
export { track } from './functions/track/index';
|
|
@@ -44,6 +44,9 @@ function mergeNewRootState(newData) {
|
|
|
44
44
|
function submissionState() {
|
|
45
45
|
return (isEditing() && previewState) || formState;
|
|
46
46
|
}
|
|
47
|
+
function errorResponse(response) {
|
|
48
|
+
return JSON.stringify(response, null, 2);
|
|
49
|
+
}
|
|
47
50
|
function onSubmit(event) {
|
|
48
51
|
const sendWithJsProp = sendWithJs || sendSubmissionsTo === "email";
|
|
49
52
|
if (sendSubmissionsTo === "zapier") {
|
|
@@ -62,13 +65,16 @@ function onSubmit(event) {
|
|
|
62
65
|
// TODO: maybe support null
|
|
63
66
|
const formPairs = Array.from(el.querySelectorAll("input,select,textarea"))
|
|
64
67
|
.filter((el) => !!el.name)
|
|
68
|
+
.filter((el) => !!el.name &&
|
|
69
|
+
(el.type !== "radio" ||
|
|
70
|
+
el.checked))
|
|
65
71
|
.map((el) => {
|
|
66
72
|
let value;
|
|
67
73
|
const key = el.name;
|
|
68
74
|
if (el instanceof HTMLInputElement) {
|
|
69
75
|
if (el.type === "radio") {
|
|
70
76
|
if (el.checked) {
|
|
71
|
-
value = el.
|
|
77
|
+
value = el.value;
|
|
72
78
|
return {
|
|
73
79
|
key,
|
|
74
80
|
value,
|
|
@@ -288,11 +294,7 @@ let formErrorMessage = "";
|
|
|
288
294
|
/>
|
|
289
295
|
{/if}
|
|
290
296
|
{#if submissionState() === "error" && responseData}
|
|
291
|
-
<pre class="builder-form-error-text pre">{
|
|
292
|
-
responseData,
|
|
293
|
-
null,
|
|
294
|
-
2
|
|
295
|
-
)}</pre>
|
|
297
|
+
<pre class="builder-form-error-text pre">{errorResponse(responseData)}</pre>
|
|
296
298
|
{/if}
|
|
297
299
|
{#if submissionState() === "success"}
|
|
298
300
|
<Blocks
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { IMAGE_FILE_TYPES } from '../../constants/file-types';
|
|
2
2
|
export const componentInfo = {
|
|
3
|
-
// friendlyName?
|
|
4
3
|
name: 'Raw:Img',
|
|
5
4
|
hideFromInsertMenu: true,
|
|
6
5
|
image: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4',
|
|
@@ -10,7 +9,38 @@ export const componentInfo = {
|
|
|
10
9
|
type: 'file',
|
|
11
10
|
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
12
11
|
required: true
|
|
12
|
+
}, {
|
|
13
|
+
name: 'backgroundSize',
|
|
14
|
+
type: 'text',
|
|
15
|
+
defaultValue: 'cover',
|
|
16
|
+
enum: [{
|
|
17
|
+
label: 'contain',
|
|
18
|
+
value: 'contain',
|
|
19
|
+
helperText: 'The image should never get cropped'
|
|
20
|
+
}, {
|
|
21
|
+
label: 'cover',
|
|
22
|
+
value: 'cover',
|
|
23
|
+
helperText: "The image should fill it's box, cropping when needed"
|
|
24
|
+
}]
|
|
25
|
+
}, {
|
|
26
|
+
name: 'backgroundPosition',
|
|
27
|
+
type: 'text',
|
|
28
|
+
defaultValue: 'center',
|
|
29
|
+
enum: ['center', 'top', 'left', 'right', 'bottom', 'top left', 'top right', 'bottom left', 'bottom right']
|
|
30
|
+
}, {
|
|
31
|
+
name: 'altText',
|
|
32
|
+
type: 'string',
|
|
33
|
+
helperText: 'Text to display when the user has images off'
|
|
34
|
+
}, {
|
|
35
|
+
name: 'title',
|
|
36
|
+
type: 'string',
|
|
37
|
+
helperText: 'Text to display when hovering over the asset'
|
|
38
|
+
}, {
|
|
39
|
+
name: 'aspectRatio',
|
|
40
|
+
type: 'number',
|
|
41
|
+
helperText: "This is the ratio of height/width, e.g. set to 1.5 for a 300px wide and 200px tall photo. Set to 0 to not force the image to maintain it's aspect ratio",
|
|
42
|
+
advanced: true,
|
|
43
|
+
defaultValue: 0.7041
|
|
13
44
|
}],
|
|
14
|
-
noWrap: true
|
|
15
|
-
static: true
|
|
45
|
+
noWrap: true
|
|
16
46
|
};
|
|
@@ -6,13 +6,15 @@
|
|
|
6
6
|
<script>import { isEditing } from "../../functions/is-editing";
|
|
7
7
|
import { filterAttrs } from "../helpers";
|
|
8
8
|
import { getSrcSet } from "../image/image.helpers";
|
|
9
|
-
import {
|
|
9
|
+
import { getClassPropName } from "../../functions/get-class-prop-name";
|
|
10
10
|
export let imgSrc = undefined;
|
|
11
11
|
export let image = undefined;
|
|
12
|
+
export let attributes = undefined;
|
|
13
|
+
export let altText = undefined;
|
|
14
|
+
export let title = undefined;
|
|
12
15
|
export let backgroundSize = undefined;
|
|
13
16
|
export let backgroundPosition = undefined;
|
|
14
|
-
export let
|
|
15
|
-
export let attributes = undefined;
|
|
17
|
+
export let aspectRatio = undefined;
|
|
16
18
|
function stringifyStyles(stylesObj) {
|
|
17
19
|
let styles = "";
|
|
18
20
|
for (let key in stylesObj) {
|
|
@@ -34,6 +36,15 @@ $: srcSetToUse = () => {
|
|
|
34
36
|
}
|
|
35
37
|
return getSrcSet(url);
|
|
36
38
|
};
|
|
39
|
+
$: imgAttrs = () => {
|
|
40
|
+
const attrs = {
|
|
41
|
+
...filterAttrs(attributes, "on:", false),
|
|
42
|
+
...filterAttrs(attributes, "on:", true),
|
|
43
|
+
[getClassPropName()]: `builder-raw-img ${attributes[getClassPropName()] || ""}`,
|
|
44
|
+
};
|
|
45
|
+
delete attrs.style;
|
|
46
|
+
return attrs;
|
|
47
|
+
};
|
|
37
48
|
</script>
|
|
38
49
|
|
|
39
50
|
{#key (isEditing() && imgSrc) || "default-key"}
|
|
@@ -41,12 +52,13 @@ $: srcSetToUse = () => {
|
|
|
41
52
|
style={stringifyStyles({
|
|
42
53
|
objectFit: backgroundSize || "cover",
|
|
43
54
|
objectPosition: backgroundPosition || "center",
|
|
55
|
+
aspectRatio: aspectRatio || undefined,
|
|
56
|
+
...(attributes?.style || {}),
|
|
44
57
|
})}
|
|
45
58
|
loading="lazy"
|
|
46
59
|
alt={altText}
|
|
60
|
+
{title}
|
|
47
61
|
src={imgSrc || image}
|
|
48
|
-
|
|
49
|
-
{...filterAttrs(attributes, "on:", false)}
|
|
50
|
-
use:setAttrs={filterAttrs(attributes, "on:", true)}
|
|
62
|
+
{...imgAttrs()}
|
|
51
63
|
/>
|
|
52
64
|
{/key}
|
|
@@ -6,11 +6,11 @@ import { getClassPropName } from "../../functions/get-class-prop-name";
|
|
|
6
6
|
import { setAttrs } from "../helpers";
|
|
7
7
|
import { fetchSymbolContent } from "./symbol.helpers";
|
|
8
8
|
export let symbol = undefined;
|
|
9
|
+
export let builderComponents;
|
|
9
10
|
export let attributes = undefined;
|
|
10
11
|
export let dynamic = undefined;
|
|
11
12
|
export let builderContext;
|
|
12
13
|
export let builderBlock;
|
|
13
|
-
export let builderComponents;
|
|
14
14
|
export let builderLinkComponent = undefined;
|
|
15
15
|
function setContent() {
|
|
16
16
|
if (contentToUse && symbolEntry === symbol?.entry)
|
|
@@ -31,6 +31,9 @@ $: blocksWrapper = () => {
|
|
|
31
31
|
$: contentWrapper = () => {
|
|
32
32
|
return "div";
|
|
33
33
|
};
|
|
34
|
+
$: customComponents = () => {
|
|
35
|
+
return Object.values(builderComponents);
|
|
36
|
+
};
|
|
34
37
|
$: className = () => {
|
|
35
38
|
return [
|
|
36
39
|
...[attributes[getClassPropName()]],
|
|
@@ -67,7 +70,7 @@ $: onUpdateFn_0(...[symbol]);
|
|
|
67
70
|
...$builderContext.context,
|
|
68
71
|
symbolId: builderBlock?.id,
|
|
69
72
|
}}
|
|
70
|
-
customComponents={
|
|
73
|
+
customComponents={customComponents()}
|
|
71
74
|
data={{
|
|
72
75
|
...symbol?.data,
|
|
73
76
|
...$builderContext.localState,
|
|
@@ -3,11 +3,11 @@ import type { SymbolProps } from "./symbol.types";
|
|
|
3
3
|
declare const __propDef: {
|
|
4
4
|
props: {
|
|
5
5
|
symbol?: SymbolProps["symbol"];
|
|
6
|
+
builderComponents: SymbolProps["builderComponents"];
|
|
6
7
|
attributes?: SymbolProps["attributes"];
|
|
7
8
|
dynamic?: SymbolProps["dynamic"];
|
|
8
9
|
builderContext: SymbolProps["builderContext"];
|
|
9
10
|
builderBlock: SymbolProps["builderBlock"];
|
|
10
|
-
builderComponents: SymbolProps["builderComponents"];
|
|
11
11
|
builderLinkComponent?: SymbolProps["builderLinkComponent"];
|
|
12
12
|
};
|
|
13
13
|
events: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContent } from '../../types/builder-content';
|
|
2
2
|
import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
|
|
3
|
-
interface SymbolInfo {
|
|
3
|
+
export interface SymbolInfo {
|
|
4
4
|
model?: string;
|
|
5
5
|
entry?: string;
|
|
6
6
|
data?: any;
|
|
@@ -16,4 +16,3 @@ export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, Bu
|
|
|
16
16
|
inheritState?: boolean;
|
|
17
17
|
renderToLiquid?: boolean;
|
|
18
18
|
}
|
|
19
|
-
export {};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
<script>import Blocks from "../../components/blocks/blocks.svelte";
|
|
2
2
|
export let defaultActiveTab = undefined;
|
|
3
3
|
export let tabs;
|
|
4
|
+
export let activeTabStyle = undefined;
|
|
4
5
|
export let collapsible = undefined;
|
|
5
6
|
export let tabHeaderLayout = undefined;
|
|
6
|
-
export let activeTabStyle = undefined;
|
|
7
7
|
export let builderBlock;
|
|
8
8
|
export let builderContext;
|
|
9
9
|
export let builderComponents;
|
|
@@ -21,6 +21,9 @@ function stringifyStyles(stylesObj) {
|
|
|
21
21
|
function activeTabContent(active) {
|
|
22
22
|
return tabs && tabs[active].content;
|
|
23
23
|
}
|
|
24
|
+
function getTabStyle(index) {
|
|
25
|
+
return index === activeTab ? activeTabStyle : {};
|
|
26
|
+
}
|
|
24
27
|
function onClick(index) {
|
|
25
28
|
if (index === activeTab && collapsible) {
|
|
26
29
|
activeTab = -1;
|
|
@@ -44,9 +47,7 @@ let activeTab = defaultActiveTab ? defaultActiveTab - 1 : 0;
|
|
|
44
47
|
>
|
|
45
48
|
{#each tabs as tab, index (index)}
|
|
46
49
|
<span
|
|
47
|
-
style={stringifyStyles(
|
|
48
|
-
...(activeTab === index ? activeTabStyle : {}),
|
|
49
|
-
})}
|
|
50
|
+
style={stringifyStyles(getTabStyle(index))}
|
|
50
51
|
class={`builder-tab-wrap ${
|
|
51
52
|
activeTab === index ? "builder-tab-active" : ""
|
|
52
53
|
}`}
|
|
@@ -4,9 +4,9 @@ declare const __propDef: {
|
|
|
4
4
|
props: {
|
|
5
5
|
defaultActiveTab?: TabsProps["defaultActiveTab"];
|
|
6
6
|
tabs: TabsProps["tabs"];
|
|
7
|
+
activeTabStyle?: TabsProps["activeTabStyle"];
|
|
7
8
|
collapsible?: TabsProps["collapsible"];
|
|
8
9
|
tabHeaderLayout?: TabsProps["tabHeaderLayout"];
|
|
9
|
-
activeTabStyle?: TabsProps["activeTabStyle"];
|
|
10
10
|
builderBlock: TabsProps["builderBlock"];
|
|
11
11
|
builderContext: TabsProps["builderContext"];
|
|
12
12
|
builderComponents: TabsProps["builderComponents"];
|
|
@@ -6,7 +6,6 @@ export const componentInfo = {
|
|
|
6
6
|
} : {},
|
|
7
7
|
name: 'Text',
|
|
8
8
|
static: true,
|
|
9
|
-
isRSC: true,
|
|
10
9
|
image: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929',
|
|
11
10
|
inputs: [{
|
|
12
11
|
name: 'text',
|