@builder.io/sdk-svelte 0.2.2 → 0.3.1
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 +3 -1
- package/package/CHANGELOG.md +4 -0
- package/package/blocks/columns/columns.svelte +21 -24
- package/package/blocks/columns/columns.svelte.d.ts +1 -1
- package/package/blocks/image/image.svelte +1 -2
- package/package/blocks/image/image.svelte.d.ts +2 -2
- package/package/blocks/symbol/symbol.svelte +1 -3
- package/package/blocks/symbol/symbol.svelte.d.ts +2 -2
- package/package/components/render-block/block-styles.svelte +3 -3
- package/package/components/render-block/block-styles.svelte.d.ts +2 -2
- package/package/components/render-block/render-block.helpers.d.ts +0 -1
- package/package/components/render-block/render-block.helpers.js +8 -20
- package/package/components/render-block/render-block.svelte +22 -19
- package/package/components/render-block/render-block.svelte.d.ts +2 -2
- package/package/components/render-block/render-component.svelte +1 -3
- package/package/components/render-block/render-component.svelte.d.ts +2 -2
- package/package/components/render-block/render-repeated-block.svelte +4 -4
- package/package/components/render-block/render-repeated-block.svelte.d.ts +2 -2
- package/package/components/render-blocks.svelte +0 -1
- package/package/components/render-blocks.svelte.d.ts +1 -1
- package/package/components/render-content/components/render-styles.svelte +8 -9
- package/package/components/render-content/components/render-styles.svelte.d.ts +1 -1
- package/package/components/render-content/render-content.svelte +18 -12
- package/package/components/render-content/render-content.svelte.d.ts +1 -1
- package/package/components/render-inlined-styles.svelte +2 -2
- package/package/constants/sdk-version.d.ts +1 -0
- package/package/constants/sdk-version.js +1 -0
- package/package/context/builder.context.d.ts +3 -2
- package/package/context/builder.context.js +3 -2
- package/package/context/types.d.ts +17 -2
- package/package/functions/evaluate.d.ts +4 -3
- package/package/functions/evaluate.js +23 -2
- package/package/functions/evaluate.test.d.ts +1 -0
- package/package/functions/evaluate.test.js +17 -0
- package/package/functions/get-block-actions-handler.d.ts +1 -1
- package/package/functions/get-block-actions-handler.js +3 -1
- package/package/functions/get-block-actions.d.ts +1 -1
- package/package/functions/get-content/index.js +1 -1
- package/package/functions/get-processed-block.d.ts +2 -2
- package/package/functions/get-processed-block.js +16 -4
- package/package/functions/get-processed-block.test.js +3 -1
- package/package/index.d.ts +1 -0
- package/package/scripts/init-editing.js +2 -0
- package/package.json +1 -4
- package/src/blocks/columns/columns.svelte +26 -30
- package/src/blocks/image/image.svelte +3 -3
- package/src/blocks/symbol/symbol.svelte +3 -3
- package/src/components/render-block/block-styles.svelte +5 -3
- package/src/components/render-block/render-block.helpers.ts +9 -31
- package/src/components/render-block/render-block.svelte +23 -18
- package/src/components/render-block/render-component.svelte +2 -2
- package/src/components/render-block/render-repeated-block.svelte +6 -4
- package/src/components/render-blocks.svelte +1 -1
- package/src/components/render-content/components/render-styles.svelte +9 -9
- package/src/components/render-content/render-content.svelte +25 -12
- package/src/components/render-inlined-styles.svelte +2 -2
- package/src/constants/sdk-version.ts +1 -0
- package/src/context/builder.context.ts +3 -2
- package/src/context/types.ts +17 -2
- package/src/functions/evaluate.test.ts +21 -0
- package/src/functions/evaluate.ts +46 -4
- package/src/functions/get-block-actions-handler.ts +7 -2
- package/src/functions/get-block-actions.ts +4 -1
- package/src/functions/get-content/index.ts +1 -1
- package/src/functions/get-processed-block.test.ts +3 -1
- package/src/functions/get-processed-block.ts +28 -6
- package/src/index.ts +1 -0
- package/src/scripts/init-editing.ts +2 -0
|
@@ -11,8 +11,23 @@ export type BuilderRenderContext = Record<string, unknown>;
|
|
|
11
11
|
export interface BuilderContextInterface {
|
|
12
12
|
content: Nullable<BuilderContent>;
|
|
13
13
|
context: BuilderRenderContext;
|
|
14
|
-
|
|
15
|
-
|
|
14
|
+
/**
|
|
15
|
+
* The state of the application.
|
|
16
|
+
*
|
|
17
|
+
* NOTE: see `localState` below to understand how it is different from `rootState`.
|
|
18
|
+
*/
|
|
19
|
+
rootState: BuilderRenderState;
|
|
20
|
+
/**
|
|
21
|
+
* Some frameworks have a `setState` function which needs to be invoked to notify
|
|
22
|
+
* the framework of state change. (other frameworks don't in which case it is `undefined')
|
|
23
|
+
*/
|
|
24
|
+
rootSetState: ((rootState: BuilderRenderState) => void) | undefined;
|
|
25
|
+
/**
|
|
26
|
+
* The local state of the current component. This is different from `rootState` in that
|
|
27
|
+
* it can be a child state created by a repeater containing local state.
|
|
28
|
+
* The `rootState` is where all of the state mutations are actually stored.
|
|
29
|
+
*/
|
|
30
|
+
localState: BuilderRenderState | undefined;
|
|
16
31
|
apiKey: string | null;
|
|
17
32
|
apiVersion: ApiVersion | undefined;
|
|
18
33
|
registeredComponents: RegisteredComponents;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
|
-
export declare function evaluate({ code, context,
|
|
1
|
+
import type { BuilderContextInterface, BuilderRenderState } from '../context/types.js';
|
|
2
|
+
export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression, }: {
|
|
3
3
|
code: string;
|
|
4
4
|
event?: Event;
|
|
5
5
|
isExpression?: boolean;
|
|
6
|
-
} & Pick<BuilderContextInterface, '
|
|
6
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
7
|
+
export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isBrowser } from './is-browser.js';
|
|
2
2
|
import { isEditing } from './is-editing.js';
|
|
3
|
-
export function evaluate({ code, context,
|
|
3
|
+
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, }) {
|
|
4
4
|
if (code === '') {
|
|
5
5
|
console.warn('Skipping evaluation of empty code block.');
|
|
6
6
|
return;
|
|
@@ -20,9 +20,30 @@ export function evaluate({ code, context, state, event, isExpression = true, })
|
|
|
20
20
|
code.trim().startsWith('return '));
|
|
21
21
|
const useCode = useReturn ? `return (${code});` : code;
|
|
22
22
|
try {
|
|
23
|
-
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder,
|
|
23
|
+
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
|
|
24
24
|
}
|
|
25
25
|
catch (e) {
|
|
26
26
|
console.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
|
+
export function flattenState(rootState, localState, rootSetState) {
|
|
30
|
+
if (rootState === localState) {
|
|
31
|
+
throw new Error('rootState === localState');
|
|
32
|
+
}
|
|
33
|
+
return new Proxy(rootState, {
|
|
34
|
+
get: (_, prop) => {
|
|
35
|
+
if (localState && prop in localState) {
|
|
36
|
+
return localState[prop];
|
|
37
|
+
}
|
|
38
|
+
return rootState[prop];
|
|
39
|
+
},
|
|
40
|
+
set: (_, prop, value) => {
|
|
41
|
+
if (localState && prop in localState) {
|
|
42
|
+
throw new Error('Writing to local state is not allowed as it is read-only.');
|
|
43
|
+
}
|
|
44
|
+
rootState[prop] = value;
|
|
45
|
+
rootSetState?.(rootState);
|
|
46
|
+
return true;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flattenState } from './evaluate';
|
|
2
|
+
describe('flatten state', () => {
|
|
3
|
+
it('should behave normally when no PROTO_STATE', () => {
|
|
4
|
+
const localState = {};
|
|
5
|
+
const rootState = { foo: 'bar' };
|
|
6
|
+
const flattened = flattenState(rootState, localState, undefined);
|
|
7
|
+
expect(flattened.foo).toEqual('bar');
|
|
8
|
+
flattened.foo = 'baz';
|
|
9
|
+
expect(rootState.foo).toEqual('baz');
|
|
10
|
+
});
|
|
11
|
+
it('should shadow write ', () => {
|
|
12
|
+
const rootState = { foo: 'foo' };
|
|
13
|
+
const localState = { foo: 'baz' };
|
|
14
|
+
const flattened = flattenState(rootState, localState, undefined);
|
|
15
|
+
expect(() => (flattened.foo = 'bar')).toThrow('Writing to local state is not allowed as it is read-only.');
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -2,7 +2,7 @@ import type { BuilderContextInterface } from '../context/types.js';
|
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
3
|
type Options = {
|
|
4
4
|
block: BuilderBlock;
|
|
5
|
-
} & Pick<BuilderContextInterface, '
|
|
5
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>;
|
|
6
6
|
type EventHandler = (event: Event) => any;
|
|
7
7
|
export declare const createEventHandler: (value: string, options: Options) => EventHandler;
|
|
8
8
|
export {};
|
|
@@ -2,7 +2,9 @@ import { evaluate } from './evaluate.js';
|
|
|
2
2
|
export const createEventHandler = (value, options) => (event) => evaluate({
|
|
3
3
|
code: value,
|
|
4
4
|
context: options.context,
|
|
5
|
-
|
|
5
|
+
localState: options.localState,
|
|
6
|
+
rootState: options.rootState,
|
|
7
|
+
rootSetState: options.rootSetState,
|
|
6
8
|
event,
|
|
7
9
|
isExpression: false,
|
|
8
10
|
});
|
|
@@ -5,5 +5,5 @@ type Actions = {
|
|
|
5
5
|
};
|
|
6
6
|
export declare function getBlockActions(options: {
|
|
7
7
|
block: BuilderBlock;
|
|
8
|
-
} & Pick<BuilderContextInterface, '
|
|
8
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions;
|
|
9
9
|
export {};
|
|
@@ -15,7 +15,7 @@ export async function getAllContent(options) {
|
|
|
15
15
|
const res = await fetch(url.href);
|
|
16
16
|
const content = await res.json();
|
|
17
17
|
if ('status' in content && !('results' in content)) {
|
|
18
|
-
logger.error('Error fetching data. ', content, options);
|
|
18
|
+
logger.error('Error fetching data. ', { url, content, options });
|
|
19
19
|
return content;
|
|
20
20
|
}
|
|
21
21
|
const canTrack = options.canTrack !== false;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types.js';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block.js';
|
|
3
|
-
export declare function getProcessedBlock({ block, context, shouldEvaluateBindings,
|
|
3
|
+
export declare function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState, }: {
|
|
4
4
|
block: BuilderBlock;
|
|
5
5
|
/**
|
|
6
6
|
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
7
7
|
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
8
8
|
*/
|
|
9
9
|
shouldEvaluateBindings: boolean;
|
|
10
|
-
} & Pick<BuilderContextInterface, '
|
|
10
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock;
|
|
@@ -2,7 +2,7 @@ import { evaluate } from './evaluate.js';
|
|
|
2
2
|
import { fastClone } from './fast-clone.js';
|
|
3
3
|
import { set } from './set.js';
|
|
4
4
|
import { transformBlock } from './transform-block.js';
|
|
5
|
-
const evaluateBindings = ({ block, context,
|
|
5
|
+
const evaluateBindings = ({ block, context, localState, rootState, rootSetState, }) => {
|
|
6
6
|
if (!block.bindings) {
|
|
7
7
|
return block;
|
|
8
8
|
}
|
|
@@ -14,15 +14,27 @@ const evaluateBindings = ({ block, context, state, }) => {
|
|
|
14
14
|
};
|
|
15
15
|
for (const binding in block.bindings) {
|
|
16
16
|
const expression = block.bindings[binding];
|
|
17
|
-
const value = evaluate({
|
|
17
|
+
const value = evaluate({
|
|
18
|
+
code: expression,
|
|
19
|
+
localState,
|
|
20
|
+
rootState,
|
|
21
|
+
rootSetState,
|
|
22
|
+
context,
|
|
23
|
+
});
|
|
18
24
|
set(copied, binding, value);
|
|
19
25
|
}
|
|
20
26
|
return copied;
|
|
21
27
|
};
|
|
22
|
-
export function getProcessedBlock({ block, context, shouldEvaluateBindings,
|
|
28
|
+
export function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState, }) {
|
|
23
29
|
const transformedBlock = transformBlock(block);
|
|
24
30
|
if (shouldEvaluateBindings) {
|
|
25
|
-
return evaluateBindings({
|
|
31
|
+
return evaluateBindings({
|
|
32
|
+
block: transformedBlock,
|
|
33
|
+
localState,
|
|
34
|
+
rootState,
|
|
35
|
+
rootSetState,
|
|
36
|
+
context,
|
|
37
|
+
});
|
|
26
38
|
}
|
|
27
39
|
else {
|
|
28
40
|
return transformedBlock;
|
|
@@ -19,7 +19,9 @@ test('Can process bindings', () => {
|
|
|
19
19
|
const processed = getProcessedBlock({
|
|
20
20
|
block,
|
|
21
21
|
context: {},
|
|
22
|
-
|
|
22
|
+
rootState: { test: 'hello' },
|
|
23
|
+
rootSetState: undefined,
|
|
24
|
+
localState: undefined,
|
|
23
25
|
shouldEvaluateBindings: true,
|
|
24
26
|
});
|
|
25
27
|
expect(processed).not.toEqual(block);
|
package/package/index.d.ts
CHANGED
|
@@ -10,3 +10,4 @@ export * from './functions/get-builder-search-params/index.js';
|
|
|
10
10
|
export { track } from './functions/track/index.js';
|
|
11
11
|
export type { RegisteredComponent } from './context/types';
|
|
12
12
|
export type { ComponentInfo } from './types/components';
|
|
13
|
+
export type { RenderContentProps } from './components/render-content/render-content.types.js';
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDK_VERSION } from '../constants/sdk-version.js';
|
|
1
2
|
import { TARGET } from '../constants/target.js';
|
|
2
3
|
import { isBrowser } from '../functions/is-browser.js';
|
|
3
4
|
import { register } from '../functions/register.js';
|
|
@@ -32,6 +33,7 @@ export const setupBrowserForEditing = (options = {}) => {
|
|
|
32
33
|
type: 'builder.sdkInfo',
|
|
33
34
|
data: {
|
|
34
35
|
target: TARGET,
|
|
36
|
+
version: SDK_VERSION,
|
|
35
37
|
// TODO: compile these in
|
|
36
38
|
// type: process.env.SDK_TYPE,
|
|
37
39
|
// version: process.env.SDK_VERSION,
|
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.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"package",
|
|
@@ -28,9 +28,6 @@
|
|
|
28
28
|
},
|
|
29
29
|
"types": "./package/index.d.ts",
|
|
30
30
|
"scripts": {
|
|
31
|
-
"release:patch": "yarn run build && npm version patch && npm publish",
|
|
32
|
-
"release:minor": "yarn run build && npm version minor && npm publish",
|
|
33
|
-
"release:dev": "yarn run build && npm version prerelease && npm publish --tag dev",
|
|
34
31
|
"dev": "vite dev",
|
|
35
32
|
"build": "svelte-kit sync && svelte-package",
|
|
36
33
|
"build:watch": "svelte-kit sync && svelte-package --watch",
|
|
@@ -11,12 +11,8 @@
|
|
|
11
11
|
export interface ColumnProps {
|
|
12
12
|
columns?: Column[];
|
|
13
13
|
builderBlock: BuilderBlock;
|
|
14
|
-
|
|
15
|
-
// TODO: Implement this when support for dynamic CSS lands
|
|
16
14
|
space?: number;
|
|
17
|
-
// TODO: Implement this when support for dynamic CSS lands
|
|
18
15
|
stackColumnsAt?: StackColumnsAt;
|
|
19
|
-
// TODO: Implement this when support for dynamic CSS lands
|
|
20
16
|
reverseColumnsWhenStacked?: boolean;
|
|
21
17
|
}
|
|
22
18
|
</script>
|
|
@@ -25,13 +21,13 @@
|
|
|
25
21
|
import { getContext } from "svelte";
|
|
26
22
|
|
|
27
23
|
import RenderBlocks from "../../components/render-blocks.svelte";
|
|
28
|
-
import { BuilderBlock } from "../../types/builder-block";
|
|
24
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
29
25
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
30
|
-
import { SizeName } from "../../constants/device-sizes";
|
|
26
|
+
import type { SizeName } from "../../constants/device-sizes";
|
|
31
27
|
import RenderInlinedStyles from "../../components/render-inlined-styles.svelte";
|
|
32
28
|
import { TARGET } from "../../constants/target.js";
|
|
33
29
|
import BuilderContext from "../../context/builder.context.js";
|
|
34
|
-
import { Dictionary } from "../../types/typescript";
|
|
30
|
+
import type { Dictionary } from "../../types/typescript";
|
|
35
31
|
|
|
36
32
|
export let space: ColumnProps["space"];
|
|
37
33
|
export let columns: ColumnProps["columns"];
|
|
@@ -84,7 +80,7 @@
|
|
|
84
80
|
} as any as Dictionary<string>;
|
|
85
81
|
}
|
|
86
82
|
const width = getColumnCssWidth(index);
|
|
87
|
-
const gutterPixels = `${
|
|
83
|
+
const gutterPixels = `${gutter}px`;
|
|
88
84
|
const mobileWidth = "100%";
|
|
89
85
|
const mobileMarginLeft = 0;
|
|
90
86
|
return {
|
|
@@ -130,30 +126,30 @@
|
|
|
130
126
|
};
|
|
131
127
|
$: columnsStyles = () => {
|
|
132
128
|
return `
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
129
|
+
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
130
|
+
.${builderBlock.id}-breakpoints {
|
|
131
|
+
flex-direction: var(--flex-dir-tablet);
|
|
132
|
+
align-items: stretch;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.${builderBlock.id}-breakpoints > .builder-column {
|
|
136
|
+
width: var(--column-width-tablet) !important;
|
|
137
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
138
|
+
}
|
|
142
139
|
}
|
|
143
|
-
}
|
|
144
140
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
141
|
+
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
142
|
+
.${builderBlock.id}-breakpoints {
|
|
143
|
+
flex-direction: var(--flex-dir);
|
|
144
|
+
align-items: stretch;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
.${builderBlock.id}-breakpoints > .builder-column {
|
|
148
|
+
width: var(--column-width-mobile) !important;
|
|
149
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
150
|
+
}
|
|
151
|
+
},
|
|
152
|
+
`;
|
|
157
153
|
};
|
|
158
154
|
|
|
159
155
|
let gutterSize = typeof space === "number" ? space || 0 : 20;
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
height?: number;
|
|
8
8
|
width?: number;
|
|
9
9
|
altText?: string;
|
|
10
|
-
backgroundSize?:
|
|
10
|
+
backgroundSize?: "cover" | "contain";
|
|
11
11
|
backgroundPosition?: string;
|
|
12
12
|
srcset?: string;
|
|
13
13
|
aspectRatio?: number;
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
</script>
|
|
21
21
|
|
|
22
22
|
<script lang="ts">
|
|
23
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
23
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
24
24
|
import { getSrcSet } from "./image.helpers.js";
|
|
25
25
|
|
|
26
26
|
export let image: ImageProps["image"];
|
|
@@ -81,7 +81,7 @@
|
|
|
81
81
|
width: "100%",
|
|
82
82
|
left: "0px",
|
|
83
83
|
top: "0px",
|
|
84
|
-
};
|
|
84
|
+
} as const;
|
|
85
85
|
const out = aspectRatio ? aspectRatioStyles : undefined;
|
|
86
86
|
return out;
|
|
87
87
|
};
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
import RenderContent from "../../components/render-content/render-content.svelte";
|
|
25
25
|
import BuilderContext from "../../context/builder.context.js";
|
|
26
26
|
import { getContent } from "../../functions/get-content/index.js";
|
|
27
|
-
import { BuilderContent } from "../../types/builder-content.js";
|
|
28
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
27
|
+
import type { BuilderContent } from "../../types/builder-content.js";
|
|
28
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
29
29
|
import { TARGET } from "../../constants/target";
|
|
30
30
|
import { logger } from "../../helpers/logger";
|
|
31
31
|
|
|
@@ -136,7 +136,7 @@
|
|
|
136
136
|
customComponents={Object.values(builderContext.registeredComponents)}
|
|
137
137
|
data={{
|
|
138
138
|
...symbol?.data,
|
|
139
|
-
...builderContext.
|
|
139
|
+
...builderContext.localState,
|
|
140
140
|
...contentToUse?.data?.state,
|
|
141
141
|
}}
|
|
142
142
|
model={symbol?.model}
|
|
@@ -11,11 +11,11 @@
|
|
|
11
11
|
getSizesForBreakpoints,
|
|
12
12
|
} from "../../constants/device-sizes.js";
|
|
13
13
|
import { TARGET } from "../../constants/target.js";
|
|
14
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
14
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
15
15
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
16
16
|
import { createCssClass } from "../../helpers/css.js";
|
|
17
17
|
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
18
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
19
19
|
import RenderInlinedStyles from "../render-inlined-styles.svelte";
|
|
20
20
|
|
|
21
21
|
export let block: BlockStylesProps["block"];
|
|
@@ -24,7 +24,9 @@
|
|
|
24
24
|
$: useBlock = () => {
|
|
25
25
|
return getProcessedBlock({
|
|
26
26
|
block: block,
|
|
27
|
-
|
|
27
|
+
localState: context.localState,
|
|
28
|
+
rootState: context.rootState,
|
|
29
|
+
rootSetState: context.rootSetState,
|
|
28
30
|
context: context.context,
|
|
29
31
|
shouldEvaluateBindings: true,
|
|
30
32
|
});
|
|
@@ -1,7 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
BuilderContextInterface,
|
|
3
|
-
BuilderRenderState,
|
|
4
|
-
} from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface } from '../../context/types';
|
|
5
2
|
import { evaluate } from '../../functions/evaluate';
|
|
6
3
|
import { getProcessedBlock } from '../../functions/get-processed-block';
|
|
7
4
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
@@ -44,7 +41,9 @@ export const getComponent = ({
|
|
|
44
41
|
}) => {
|
|
45
42
|
const componentName = getProcessedBlock({
|
|
46
43
|
block,
|
|
47
|
-
|
|
44
|
+
localState: context.localState,
|
|
45
|
+
rootState: context.rootState,
|
|
46
|
+
rootSetState: context.rootSetState,
|
|
48
47
|
context: context.context,
|
|
49
48
|
shouldEvaluateBindings: false,
|
|
50
49
|
}).component?.name;
|
|
@@ -85,7 +84,9 @@ export const getRepeatItemData = ({
|
|
|
85
84
|
|
|
86
85
|
const itemsArray = evaluate({
|
|
87
86
|
code: repeat.collection,
|
|
88
|
-
|
|
87
|
+
localState: context.localState,
|
|
88
|
+
rootState: context.rootState,
|
|
89
|
+
rootSetState: context.rootSetState,
|
|
89
90
|
context: context.context,
|
|
90
91
|
});
|
|
91
92
|
|
|
@@ -100,8 +101,8 @@ export const getRepeatItemData = ({
|
|
|
100
101
|
const repeatArray = itemsArray.map<RepeatData>((item, index) => ({
|
|
101
102
|
context: {
|
|
102
103
|
...context,
|
|
103
|
-
|
|
104
|
-
...context.
|
|
104
|
+
localState: {
|
|
105
|
+
...context.localState,
|
|
105
106
|
$index: index,
|
|
106
107
|
$item: item,
|
|
107
108
|
[itemNameToUse]: item,
|
|
@@ -113,26 +114,3 @@ export const getRepeatItemData = ({
|
|
|
113
114
|
|
|
114
115
|
return repeatArray;
|
|
115
116
|
};
|
|
116
|
-
|
|
117
|
-
export const getProxyState = (
|
|
118
|
-
context: BuilderContextInterface
|
|
119
|
-
): BuilderContextInterface['state'] => {
|
|
120
|
-
if (typeof Proxy === 'undefined') {
|
|
121
|
-
console.error(
|
|
122
|
-
'no Proxy available in this environment, cannot proxy state.'
|
|
123
|
-
);
|
|
124
|
-
return context.state;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const useState = new Proxy(context.state, {
|
|
128
|
-
set: (obj, prop: keyof BuilderRenderState, value) => {
|
|
129
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
130
|
-
obj[prop] = value;
|
|
131
|
-
|
|
132
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
133
|
-
context.setState?.(obj);
|
|
134
|
-
return true;
|
|
135
|
-
},
|
|
136
|
-
});
|
|
137
|
-
return useState;
|
|
138
|
-
};
|
|
@@ -6,20 +6,19 @@
|
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
9
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
10
10
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
11
11
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
12
12
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
13
13
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
14
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
14
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
15
|
import BlockStyles from "./block-styles.svelte";
|
|
16
16
|
import {
|
|
17
17
|
getComponent,
|
|
18
|
-
getProxyState,
|
|
19
18
|
getRepeatItemData,
|
|
20
19
|
isEmptyHtmlElement,
|
|
21
20
|
} from "./render-block.helpers.js";
|
|
22
|
-
import { RenderComponentProps } from "./render-component.svelte";
|
|
21
|
+
import type { RenderComponentProps } from "./render-component.svelte";
|
|
23
22
|
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
24
23
|
import { TARGET } from "../../constants/target.js";
|
|
25
24
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
@@ -47,12 +46,20 @@
|
|
|
47
46
|
export let block: RenderBlockProps["block"];
|
|
48
47
|
export let context: RenderBlockProps["context"];
|
|
49
48
|
|
|
49
|
+
$: repeatItem = () => {
|
|
50
|
+
return getRepeatItemData({
|
|
51
|
+
block: block,
|
|
52
|
+
context: context,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
50
55
|
$: useBlock = () => {
|
|
51
|
-
return
|
|
56
|
+
return repeatItem()
|
|
52
57
|
? block
|
|
53
58
|
: getProcessedBlock({
|
|
54
59
|
block: block,
|
|
55
|
-
|
|
60
|
+
localState: context.localState,
|
|
61
|
+
rootState: context.rootState,
|
|
62
|
+
rootSetState: context.rootSetState,
|
|
56
63
|
context: context.context,
|
|
57
64
|
shouldEvaluateBindings: true,
|
|
58
65
|
});
|
|
@@ -69,7 +76,9 @@
|
|
|
69
76
|
$: actions = () => {
|
|
70
77
|
return getBlockActions({
|
|
71
78
|
block: useBlock(),
|
|
72
|
-
|
|
79
|
+
rootState: context.rootState,
|
|
80
|
+
rootSetState: context.rootSetState,
|
|
81
|
+
localState: context.localState,
|
|
73
82
|
context: context.context,
|
|
74
83
|
});
|
|
75
84
|
};
|
|
@@ -96,7 +105,7 @@
|
|
|
96
105
|
* blocks, and the children will be repeated within those blocks.
|
|
97
106
|
*/
|
|
98
107
|
const shouldRenderChildrenOutsideRef =
|
|
99
|
-
!component?.component && !
|
|
108
|
+
!component?.component && !repeatItem();
|
|
100
109
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
101
110
|
};
|
|
102
111
|
$: childrenContext = () => {
|
|
@@ -115,10 +124,11 @@
|
|
|
115
124
|
return {
|
|
116
125
|
apiKey: context.apiKey,
|
|
117
126
|
apiVersion: context.apiVersion,
|
|
118
|
-
|
|
127
|
+
localState: context.localState,
|
|
128
|
+
rootState: context.rootState,
|
|
129
|
+
rootSetState: context.rootSetState,
|
|
119
130
|
content: context.content,
|
|
120
131
|
context: context.context,
|
|
121
|
-
setState: context.setState,
|
|
122
132
|
registeredComponents: context.registeredComponents,
|
|
123
133
|
inheritedStyles: getInheritedTextStyles(),
|
|
124
134
|
};
|
|
@@ -150,12 +160,7 @@
|
|
|
150
160
|
block: block,
|
|
151
161
|
context: context,
|
|
152
162
|
});
|
|
153
|
-
let repeatItemData = getRepeatItemData({
|
|
154
|
-
block: block,
|
|
155
|
-
context: context,
|
|
156
|
-
});
|
|
157
163
|
let tag = block.tagName || "div";
|
|
158
|
-
let proxyState = getProxyState(context);
|
|
159
164
|
</script>
|
|
160
165
|
|
|
161
166
|
{#if canShowBlock()}
|
|
@@ -164,13 +169,13 @@
|
|
|
164
169
|
<svelte:element this={tag} {...attributes()} use:setAttrs={actions()} />
|
|
165
170
|
{/if}
|
|
166
171
|
|
|
167
|
-
{#if !isEmptyHtmlElement(tag) &&
|
|
168
|
-
{#each
|
|
172
|
+
{#if !isEmptyHtmlElement(tag) && repeatItem()}
|
|
173
|
+
{#each repeatItem() as data, index (index)}
|
|
169
174
|
<RenderRepeatedBlock repeatContext={data.context} block={data.block} />
|
|
170
175
|
{/each}
|
|
171
176
|
{/if}
|
|
172
177
|
|
|
173
|
-
{#if !isEmptyHtmlElement(tag) && !
|
|
178
|
+
{#if !isEmptyHtmlElement(tag) && !repeatItem()}
|
|
174
179
|
<svelte:element this={tag} {...attributes()} use:setAttrs={actions()}>
|
|
175
180
|
<RenderComponent {...renderComponentProps()} />
|
|
176
181
|
|
|
@@ -15,10 +15,10 @@
|
|
|
15
15
|
</script>
|
|
16
16
|
|
|
17
17
|
<script lang="ts">
|
|
18
|
-
import { BuilderBlock } from "../../types/builder-block.js";
|
|
18
|
+
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
19
19
|
import BlockStyles from "./block-styles.svelte";
|
|
20
20
|
import RenderBlock from "./render-block.svelte";
|
|
21
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
21
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
22
22
|
|
|
23
23
|
export let componentRef: RenderComponentProps["componentRef"];
|
|
24
24
|
export let componentOptions: RenderComponentProps["componentOptions"];
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
import { setContext } from "svelte";
|
|
20
20
|
|
|
21
21
|
import BuilderContext from "../../context/builder.context.js";
|
|
22
|
-
import { BuilderContextInterface } from "../../context/types.js";
|
|
23
|
-
import { BuilderBlock } from "../../types/builder-block";
|
|
22
|
+
import type { BuilderContextInterface } from "../../context/types.js";
|
|
23
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
24
24
|
import RenderBlock from "./render-block.svelte";
|
|
25
25
|
|
|
26
26
|
export let block: Props["block"];
|
|
@@ -28,12 +28,14 @@
|
|
|
28
28
|
|
|
29
29
|
setContext(BuilderContext.key, {
|
|
30
30
|
content: repeatContext.content,
|
|
31
|
-
|
|
32
|
-
|
|
31
|
+
localState: repeatContext.localState,
|
|
32
|
+
rootState: repeatContext.rootState,
|
|
33
|
+
rootSetState: repeatContext.rootSetState,
|
|
33
34
|
context: repeatContext.context,
|
|
34
35
|
apiKey: repeatContext.apiKey,
|
|
35
36
|
registeredComponents: repeatContext.registeredComponents,
|
|
36
37
|
inheritedStyles: repeatContext.inheritedStyles,
|
|
38
|
+
apiVersion: repeatContext.apiVersion,
|
|
37
39
|
});
|
|
38
40
|
</script>
|
|
39
41
|
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
|
|
13
13
|
import BuilderContext from "../context/builder.context.js";
|
|
14
14
|
import { isEditing } from "../functions/is-editing.js";
|
|
15
|
-
import { BuilderBlock } from "../types/builder-block.js";
|
|
15
|
+
import type { BuilderBlock } from "../types/builder-block.js";
|
|
16
16
|
import BlockStyles from "./render-block/block-styles.svelte";
|
|
17
17
|
import RenderBlock from "./render-block/render-block.svelte";
|
|
18
18
|
|