@builder.io/sdk-svelte 1.0.23 → 1.0.25
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/README.md +2 -2
- package/lib/browser/blocks/button/button.svelte +16 -15
- package/lib/browser/blocks/columns/columns.svelte +32 -24
- package/lib/browser/blocks/columns/columns.svelte.d.ts +1 -1
- package/lib/browser/blocks/columns/columns.types.d.ts +1 -1
- package/lib/browser/blocks/columns/helpers.d.ts +1 -0
- package/lib/browser/blocks/columns/helpers.js +3 -0
- package/lib/browser/blocks/image/image.svelte +1 -1
- package/lib/browser/blocks/symbol/symbol.helpers.js +1 -1
- package/lib/browser/blocks/symbol/symbol.svelte +9 -2
- package/lib/browser/blocks/tabs/component-info.d.ts +2 -0
- package/lib/browser/blocks/tabs/component-info.js +138 -0
- package/lib/browser/blocks/tabs/index.d.ts +1 -0
- package/lib/browser/blocks/tabs/index.js +1 -0
- package/lib/browser/blocks/tabs/tabs.svelte +76 -0
- package/lib/browser/blocks/tabs/tabs.svelte.d.ts +25 -0
- package/lib/browser/blocks/tabs/tabs.types.d.ts +13 -0
- package/lib/browser/blocks/tabs/tabs.types.js +1 -0
- package/lib/browser/blocks/text/text.types.d.ts +2 -1
- package/lib/browser/components/block/block.helpers.d.ts +4 -2
- package/lib/browser/components/block/block.helpers.js +6 -0
- package/lib/browser/components/block/block.svelte +4 -8
- package/lib/browser/components/block/components/interactive-element.svelte +20 -19
- package/lib/browser/components/content/components/enable-editor.svelte +13 -8
- package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/browser/components/content/components/styles.helpers.d.ts +1 -0
- package/lib/browser/components/content/components/styles.helpers.js +3 -0
- package/lib/browser/components/content/content.svelte +1 -0
- package/lib/browser/components/dynamic-div.svelte +5 -0
- package/lib/browser/constants/builder-registered-components.js +7 -1
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/evaluate/node-runtime/init.d.ts +17 -1
- package/lib/browser/functions/evaluate/node-runtime/init.js +2 -2
- package/lib/browser/functions/evaluate/node-runtime/node-runtime.d.ts +4 -1
- package/lib/browser/functions/evaluate/node-runtime/node-runtime.js +29 -18
- package/lib/browser/functions/get-class-prop-name.js +1 -0
- package/lib/browser/functions/get-style.js +1 -0
- package/lib/browser/types/targets.d.ts +1 -1
- package/lib/edge/blocks/button/button.svelte +16 -15
- package/lib/edge/blocks/columns/columns.svelte +32 -24
- package/lib/edge/blocks/columns/columns.svelte.d.ts +1 -1
- package/lib/edge/blocks/columns/columns.types.d.ts +1 -1
- package/lib/edge/blocks/columns/helpers.d.ts +1 -0
- package/lib/edge/blocks/columns/helpers.js +3 -0
- package/lib/edge/blocks/image/image.svelte +1 -1
- package/lib/edge/blocks/symbol/symbol.helpers.js +1 -1
- package/lib/edge/blocks/symbol/symbol.svelte +9 -2
- package/lib/edge/blocks/tabs/component-info.d.ts +2 -0
- package/lib/edge/blocks/tabs/component-info.js +138 -0
- package/lib/edge/blocks/tabs/index.d.ts +1 -0
- package/lib/edge/blocks/tabs/index.js +1 -0
- package/lib/edge/blocks/tabs/tabs.svelte +76 -0
- package/lib/edge/blocks/tabs/tabs.svelte.d.ts +25 -0
- package/lib/edge/blocks/tabs/tabs.types.d.ts +13 -0
- package/lib/edge/blocks/tabs/tabs.types.js +1 -0
- package/lib/edge/blocks/text/text.types.d.ts +2 -1
- package/lib/edge/components/block/block.helpers.d.ts +4 -2
- package/lib/edge/components/block/block.helpers.js +6 -0
- package/lib/edge/components/block/block.svelte +4 -8
- package/lib/edge/components/block/components/interactive-element.svelte +20 -19
- package/lib/edge/components/content/components/enable-editor.svelte +13 -8
- package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/edge/components/content/components/styles.helpers.d.ts +1 -0
- package/lib/edge/components/content/components/styles.helpers.js +3 -0
- package/lib/edge/components/content/content.svelte +1 -0
- package/lib/edge/components/dynamic-div.svelte +5 -0
- package/lib/edge/constants/builder-registered-components.js +7 -1
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/evaluate/node-runtime/init.d.ts +17 -1
- package/lib/edge/functions/evaluate/node-runtime/init.js +2 -2
- package/lib/edge/functions/evaluate/node-runtime/node-runtime.d.ts +4 -1
- package/lib/edge/functions/evaluate/node-runtime/node-runtime.js +29 -18
- package/lib/edge/functions/get-class-prop-name.js +1 -0
- package/lib/edge/functions/get-style.js +1 -0
- package/lib/edge/types/targets.d.ts +1 -1
- package/lib/node/blocks/button/button.svelte +16 -15
- package/lib/node/blocks/columns/columns.svelte +32 -24
- package/lib/node/blocks/columns/columns.svelte.d.ts +1 -1
- package/lib/node/blocks/columns/columns.types.d.ts +1 -1
- package/lib/node/blocks/columns/helpers.d.ts +1 -0
- package/lib/node/blocks/columns/helpers.js +3 -0
- package/lib/node/blocks/image/image.svelte +1 -1
- package/lib/node/blocks/symbol/symbol.helpers.js +1 -1
- package/lib/node/blocks/symbol/symbol.svelte +9 -2
- package/lib/node/blocks/tabs/component-info.d.ts +2 -0
- package/lib/node/blocks/tabs/component-info.js +138 -0
- package/lib/node/blocks/tabs/index.d.ts +1 -0
- package/lib/node/blocks/tabs/index.js +1 -0
- package/lib/node/blocks/tabs/tabs.svelte +76 -0
- package/lib/node/blocks/tabs/tabs.svelte.d.ts +25 -0
- package/lib/node/blocks/tabs/tabs.types.d.ts +13 -0
- package/lib/node/blocks/tabs/tabs.types.js +1 -0
- package/lib/node/blocks/text/text.types.d.ts +2 -1
- package/lib/node/components/block/block.helpers.d.ts +4 -2
- package/lib/node/components/block/block.helpers.js +6 -0
- package/lib/node/components/block/block.svelte +4 -8
- package/lib/node/components/block/components/interactive-element.svelte +20 -19
- package/lib/node/components/content/components/enable-editor.svelte +13 -8
- package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/node/components/content/components/styles.helpers.d.ts +1 -0
- package/lib/node/components/content/components/styles.helpers.js +3 -0
- package/lib/node/components/content/content.svelte +1 -0
- package/lib/node/components/dynamic-div.svelte +5 -0
- package/lib/node/constants/builder-registered-components.js +7 -1
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/evaluate/node-runtime/init.d.ts +17 -1
- package/lib/node/functions/evaluate/node-runtime/init.js +2 -2
- package/lib/node/functions/evaluate/node-runtime/node-runtime.d.ts +4 -1
- package/lib/node/functions/evaluate/node-runtime/node-runtime.js +29 -18
- package/lib/node/functions/get-class-prop-name.js +1 -0
- package/lib/node/functions/get-style.js +1 -0
- package/lib/node/types/targets.d.ts +1 -1
- package/package.json +1 -1
- package/src/blocks/button/button.svelte +19 -15
- package/src/blocks/columns/columns.svelte +34 -26
- package/src/blocks/columns/columns.types.ts +1 -1
- package/src/blocks/columns/helpers.ts +3 -0
- package/src/blocks/image/image.svelte +1 -1
- package/src/blocks/symbol/symbol.helpers.ts +1 -1
- package/src/blocks/symbol/symbol.svelte +9 -2
- package/src/blocks/tabs/component-info.ts +139 -0
- package/src/blocks/tabs/index.ts +1 -0
- package/src/blocks/tabs/tabs.svelte +83 -0
- package/src/blocks/tabs/tabs.types.ts +13 -0
- package/src/blocks/text/text.types.ts +2 -1
- package/src/components/block/block.helpers.ts +7 -1
- package/src/components/block/block.svelte +5 -7
- package/src/components/block/components/interactive-element.svelte +21 -19
- package/src/components/content/components/enable-editor.svelte +13 -8
- package/src/components/content/components/styles.helpers.ts +3 -0
- package/src/components/content/content.svelte +1 -0
- package/src/components/dynamic-div.svelte +19 -0
- package/src/constants/builder-registered-components.ts +7 -1
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/evaluate/node-runtime/init.ts +7 -2
- package/src/functions/evaluate/node-runtime/node-runtime.ts +34 -21
- package/src/functions/get-class-prop-name.ts +1 -0
- package/src/functions/get-style.ts +1 -0
- package/src/types/targets.ts +1 -1
|
@@ -12,9 +12,12 @@ import { componentInfo as slotComponentInfo } from '../blocks/slot/component-inf
|
|
|
12
12
|
import { default as Slot } from '../blocks/slot/index';
|
|
13
13
|
import { componentInfo as symbolComponentInfo } from '../blocks/symbol/component-info';
|
|
14
14
|
import { default as Symbol } from '../blocks/symbol/index';
|
|
15
|
+
import { componentInfo as tabsComponentInfo } from '../blocks/tabs/component-info';
|
|
16
|
+
import { default as Tabs } from '../blocks/tabs/index';
|
|
15
17
|
import { componentInfo as textComponentInfo } from '../blocks/text/component-info';
|
|
16
18
|
import { default as Text } from '../blocks/text/index';
|
|
17
19
|
import { getExtraComponents } from './extra-components';
|
|
20
|
+
import { TARGET } from './target';
|
|
18
21
|
/**
|
|
19
22
|
* Returns a list of all registered components.
|
|
20
23
|
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
@@ -43,4 +46,7 @@ export const getDefaultRegisteredComponents = () => [{
|
|
|
43
46
|
}, {
|
|
44
47
|
component: Text,
|
|
45
48
|
...textComponentInfo
|
|
46
|
-
}, ...
|
|
49
|
+
}, ...(TARGET === 'rsc' ? [] : [{
|
|
50
|
+
component: Tabs,
|
|
51
|
+
...tabsComponentInfo
|
|
52
|
+
}]), ...getExtraComponents()];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.25";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.25";
|
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This file:
|
|
3
|
+
* - imports `isolated-vm`, which can only be made from a file that never runs
|
|
4
|
+
* on the client (e.g. Next's `_document.tsx`)
|
|
5
|
+
* - stores the ivm instance in a global variable using `setIvm`
|
|
6
|
+
*
|
|
7
|
+
* This is needed for when bundlers/meta-frameworks are not able to reliably
|
|
8
|
+
* import the `isolated-vm` package using our `safeDynamicRequire` trick.
|
|
9
|
+
*
|
|
10
|
+
* The `isolated-vm` import must exist in this separate file, or it will end up
|
|
11
|
+
* in the SDK's main entry point, causing errors for users.
|
|
12
|
+
*/
|
|
13
|
+
import ivm from 'isolated-vm';
|
|
14
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
15
|
/**
|
|
2
16
|
* This function initializes the SDK on a Node server. It handles importing the
|
|
3
17
|
* `isolated-vm` package which is needed for dynamic bindings.
|
|
@@ -7,4 +21,6 @@
|
|
|
7
21
|
* - The NextJS Pages router's `_document.tsx`
|
|
8
22
|
* - Your Remix route's `loader`
|
|
9
23
|
*/
|
|
10
|
-
export declare const initializeNodeRuntime: (
|
|
24
|
+
export declare const initializeNodeRuntime: ({ ivmIsolateOptions }: {
|
|
25
|
+
ivmIsolateOptions?: ivm.IsolateOptions | undefined;
|
|
26
|
+
}) => void;
|
|
@@ -21,6 +21,6 @@ import { setIvm } from './node-runtime';
|
|
|
21
21
|
* - The NextJS Pages router's `_document.tsx`
|
|
22
22
|
* - Your Remix route's `loader`
|
|
23
23
|
*/
|
|
24
|
-
export const initializeNodeRuntime = () => {
|
|
25
|
-
setIvm(ivm);
|
|
24
|
+
export const initializeNodeRuntime = ({ ivmIsolateOptions }) => {
|
|
25
|
+
setIvm(ivm, ivmIsolateOptions);
|
|
26
26
|
};
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
1
2
|
import type { ExecutorArgs } from '../helpers';
|
|
3
|
+
type IsolatedVMImport = typeof import('isolated-vm');
|
|
2
4
|
/**
|
|
3
5
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
4
6
|
* This is useful for environments that are not able to rely on our
|
|
5
7
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
6
8
|
*/
|
|
7
|
-
export declare const setIvm: (ivm:
|
|
9
|
+
export declare const setIvm: (ivm: IsolatedVMImport, options?: IsolateOptions) => void;
|
|
8
10
|
export declare const runInNode: ({ code, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
11
|
+
export {};
|
|
@@ -45,23 +45,25 @@ function theFunction() {
|
|
|
45
45
|
${code}
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
|
|
48
|
+
const output = theFunction()
|
|
49
49
|
|
|
50
50
|
if (typeof output === 'object' && output !== null) {
|
|
51
|
-
|
|
51
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
52
|
+
} else {
|
|
53
|
+
return output;
|
|
52
54
|
}
|
|
53
|
-
|
|
54
|
-
output;
|
|
55
55
|
`;
|
|
56
56
|
};
|
|
57
57
|
let IVM_INSTANCE = null;
|
|
58
|
+
let IVM_CONTEXT = null;
|
|
58
59
|
/**
|
|
59
60
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
60
61
|
* This is useful for environments that are not able to rely on our
|
|
61
62
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
62
63
|
*/
|
|
63
|
-
export const setIvm = (ivm) => {
|
|
64
|
+
export const setIvm = (ivm, options = {}) => {
|
|
64
65
|
IVM_INSTANCE = ivm;
|
|
66
|
+
setIsolateContext(options);
|
|
65
67
|
};
|
|
66
68
|
const getIvm = () => {
|
|
67
69
|
try {
|
|
@@ -83,12 +85,29 @@ const getIvm = () => {
|
|
|
83
85
|
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
84
86
|
`);
|
|
85
87
|
};
|
|
86
|
-
|
|
88
|
+
function setIsolateContext(options = {
|
|
89
|
+
memoryLimit: 128
|
|
90
|
+
}) {
|
|
87
91
|
const ivm = getIvm();
|
|
88
|
-
const isolate = new ivm.Isolate(
|
|
89
|
-
|
|
92
|
+
const isolate = new ivm.Isolate(options);
|
|
93
|
+
const context = isolate.createContextSync();
|
|
94
|
+
const jail = context.global;
|
|
95
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
96
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
97
|
+
jail.setSync('global', jail.derefInto());
|
|
98
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
99
|
+
jail.setSync('log', function (...logArgs) {
|
|
100
|
+
console.log(...logArgs);
|
|
90
101
|
});
|
|
91
|
-
|
|
102
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
103
|
+
IVM_CONTEXT = context;
|
|
104
|
+
return context;
|
|
105
|
+
}
|
|
106
|
+
const getIsolateContext = () => {
|
|
107
|
+
if (IVM_CONTEXT)
|
|
108
|
+
return IVM_CONTEXT;
|
|
109
|
+
const context = setIsolateContext();
|
|
110
|
+
return context;
|
|
92
111
|
};
|
|
93
112
|
export const runInNode = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
94
113
|
const ivm = getIvm();
|
|
@@ -104,13 +123,6 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
104
123
|
});
|
|
105
124
|
const isolateContext = getIsolateContext();
|
|
106
125
|
const jail = isolateContext.global;
|
|
107
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
108
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
109
|
-
jail.setSync('global', jail.derefInto());
|
|
110
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
111
|
-
jail.setSync('log', function (...logArgs) {
|
|
112
|
-
console.log(...logArgs);
|
|
113
|
-
});
|
|
114
126
|
/**
|
|
115
127
|
* Propagate state changes back to the reactive root state.
|
|
116
128
|
*/
|
|
@@ -130,12 +142,11 @@ export const runInNode = ({ code, builder, context, event, localState, rootSetSt
|
|
|
130
142
|
} : arg) : null;
|
|
131
143
|
jail.setSync(getSyncValName(key), val);
|
|
132
144
|
});
|
|
133
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
134
145
|
const evalStr = processCode({
|
|
135
146
|
code,
|
|
136
147
|
args
|
|
137
148
|
});
|
|
138
|
-
const resultStr = isolateContext.
|
|
149
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
139
150
|
try {
|
|
140
151
|
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
141
152
|
const res = JSON.parse(resultStr);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type Target = 'vue' | 'reactNative' | 'svelte' | 'qwik' | 'react' | 'solid' | 'rsc';
|
|
1
|
+
export type Target = 'vue' | 'reactNative' | 'svelte' | 'qwik' | 'react' | 'solid' | 'rsc' | 'angular';
|
package/package.json
CHANGED
|
@@ -10,24 +10,28 @@
|
|
|
10
10
|
export let builderLinkComponent: ButtonProps["builderLinkComponent"] =
|
|
11
11
|
undefined;
|
|
12
12
|
export let text: ButtonProps["text"] = undefined;
|
|
13
|
+
|
|
14
|
+
function attrs() {
|
|
15
|
+
return {
|
|
16
|
+
...filterAttrs(attributes, "on:", false),
|
|
17
|
+
[getClassPropName()]: `${link ? "" : "builder-button"} ${
|
|
18
|
+
attributes[getClassPropName()] || ""
|
|
19
|
+
}`,
|
|
20
|
+
...(link
|
|
21
|
+
? {
|
|
22
|
+
href: link,
|
|
23
|
+
target: openLinkInNewTab ? "_blank" : undefined,
|
|
24
|
+
role: "link",
|
|
25
|
+
}
|
|
26
|
+
: {
|
|
27
|
+
role: "button",
|
|
28
|
+
}),
|
|
29
|
+
};
|
|
30
|
+
}
|
|
13
31
|
</script>
|
|
14
32
|
|
|
15
33
|
<DynamicRenderer
|
|
16
|
-
attributes={
|
|
17
|
-
...filterAttrs(attributes, "on:", false),
|
|
18
|
-
[getClassPropName()]: `${link ? "" : "builder-button"} ${
|
|
19
|
-
attributes[getClassPropName()] || ""
|
|
20
|
-
}`,
|
|
21
|
-
...(link
|
|
22
|
-
? {
|
|
23
|
-
href: link,
|
|
24
|
-
target: openLinkInNewTab ? "_blank" : undefined,
|
|
25
|
-
role: "link",
|
|
26
|
-
}
|
|
27
|
-
: {
|
|
28
|
-
role: "button",
|
|
29
|
-
}),
|
|
30
|
-
}}
|
|
34
|
+
attributes={attrs()}
|
|
31
35
|
TagName={link ? builderLinkComponent || "a" : "button"}
|
|
32
36
|
actionAttributes={filterAttrs(attributes, "on:", true)}
|
|
33
37
|
>{text}</DynamicRenderer
|
|
@@ -13,17 +13,19 @@
|
|
|
13
13
|
import { getClassPropName } from "../../functions/get-class-prop-name";
|
|
14
14
|
import { mapStyleObjToStrIfNeeded } from "../../functions/get-style";
|
|
15
15
|
import type { Dictionary } from "../../types/typescript";
|
|
16
|
-
import type { ColumnProps } from "./columns.types";
|
|
16
|
+
import type { Column, ColumnProps } from "./columns.types";
|
|
17
|
+
import { getColumnsClass } from "./helpers";
|
|
18
|
+
import DynamicDiv from "../../components/dynamic-div.svelte";
|
|
17
19
|
|
|
18
20
|
export let space: ColumnProps["space"] = undefined;
|
|
19
21
|
export let columns: ColumnProps["columns"] = undefined;
|
|
20
22
|
export let stackColumnsAt: ColumnProps["stackColumnsAt"] = undefined;
|
|
23
|
+
export let builderLinkComponent: ColumnProps["builderLinkComponent"] =
|
|
24
|
+
undefined;
|
|
21
25
|
export let reverseColumnsWhenStacked: ColumnProps["reverseColumnsWhenStacked"] =
|
|
22
26
|
undefined;
|
|
23
27
|
export let builderContext: ColumnProps["builderContext"];
|
|
24
28
|
export let builderBlock: ColumnProps["builderBlock"];
|
|
25
|
-
export let builderLinkComponent: ColumnProps["builderLinkComponent"] =
|
|
26
|
-
undefined;
|
|
27
29
|
export let builderComponents: ColumnProps["builderComponents"];
|
|
28
30
|
function stringifyStyles(stylesObj) {
|
|
29
31
|
let styles = "";
|
|
@@ -36,6 +38,9 @@
|
|
|
36
38
|
return styles;
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
function getTagName(column: Column) {
|
|
42
|
+
return column.link ? builderLinkComponent || "a" : "div";
|
|
43
|
+
}
|
|
39
44
|
function getWidth(index: number) {
|
|
40
45
|
return cols[index]?.width || 100 / cols.length;
|
|
41
46
|
}
|
|
@@ -61,6 +66,15 @@
|
|
|
61
66
|
}) {
|
|
62
67
|
return stackAt === "never" ? desktopStyle : stackedStyle;
|
|
63
68
|
}
|
|
69
|
+
function columnsCssVars() {
|
|
70
|
+
return {
|
|
71
|
+
"--flex-dir": flexDir,
|
|
72
|
+
"--flex-dir-tablet": getTabletStyle({
|
|
73
|
+
stackedStyle: flexDir,
|
|
74
|
+
desktopStyle: "row",
|
|
75
|
+
}),
|
|
76
|
+
} as Dictionary<string>;
|
|
77
|
+
}
|
|
64
78
|
function columnCssVars(index: number) {
|
|
65
79
|
const gutter = index === 0 ? 0 : gutterSize;
|
|
66
80
|
const width = getColumnCssWidth(index);
|
|
@@ -101,16 +115,7 @@
|
|
|
101
115
|
);
|
|
102
116
|
return breakpointSizes[size].max;
|
|
103
117
|
}
|
|
104
|
-
|
|
105
|
-
return {
|
|
106
|
-
"--flex-dir": flexDir,
|
|
107
|
-
"--flex-dir-tablet": getTabletStyle({
|
|
108
|
-
stackedStyle: flexDir,
|
|
109
|
-
desktopStyle: "row",
|
|
110
|
-
}),
|
|
111
|
-
} as Dictionary<string>;
|
|
112
|
-
};
|
|
113
|
-
$: columnsStyles = () => {
|
|
118
|
+
function columnsStyles() {
|
|
114
119
|
return `
|
|
115
120
|
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
116
121
|
.${builderBlock.id}-breakpoints {
|
|
@@ -136,7 +141,19 @@
|
|
|
136
141
|
}
|
|
137
142
|
},
|
|
138
143
|
`;
|
|
139
|
-
}
|
|
144
|
+
}
|
|
145
|
+
function getAttributes(column: any, index: number) {
|
|
146
|
+
return {
|
|
147
|
+
...{},
|
|
148
|
+
...(column.link
|
|
149
|
+
? {
|
|
150
|
+
href: column.link,
|
|
151
|
+
}
|
|
152
|
+
: {}),
|
|
153
|
+
[getClassPropName()]: "builder-column",
|
|
154
|
+
style: mapStyleObjToStrIfNeeded(columnCssVars(index)),
|
|
155
|
+
};
|
|
156
|
+
}
|
|
140
157
|
|
|
141
158
|
let gutterSize = typeof space === "number" ? space || 0 : 20;
|
|
142
159
|
let cols = columns || [];
|
|
@@ -151,7 +168,7 @@
|
|
|
151
168
|
|
|
152
169
|
<div
|
|
153
170
|
style={stringifyStyles(columnsCssVars())}
|
|
154
|
-
class={
|
|
171
|
+
class={getColumnsClass(builderBlock?.id) + " div"}
|
|
155
172
|
{...{}}
|
|
156
173
|
>
|
|
157
174
|
{#if TARGET !== "reactNative"}
|
|
@@ -159,18 +176,9 @@
|
|
|
159
176
|
{/if}
|
|
160
177
|
{#each columns as column, index (index)}
|
|
161
178
|
<DynamicRenderer
|
|
162
|
-
TagName={column
|
|
179
|
+
TagName={getTagName(column)}
|
|
163
180
|
actionAttributes={{}}
|
|
164
|
-
attributes={
|
|
165
|
-
...{},
|
|
166
|
-
...(column.link
|
|
167
|
-
? {
|
|
168
|
-
href: column.link,
|
|
169
|
-
}
|
|
170
|
-
: {}),
|
|
171
|
-
[getClassPropName()]: "builder-column",
|
|
172
|
-
style: mapStyleObjToStrIfNeeded(columnCssVars(index)),
|
|
173
|
-
}}
|
|
181
|
+
attributes={getAttributes(column, index)}
|
|
174
182
|
><Blocks
|
|
175
183
|
path={`component.options.columns.${index}.blocks`}
|
|
176
184
|
parent={builderBlock.id}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
2
2
|
import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
|
|
3
|
-
type Column = {
|
|
3
|
+
export type Column = {
|
|
4
4
|
blocks: BuilderBlock[];
|
|
5
5
|
width?: number;
|
|
6
6
|
link?: string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../../context/types';
|
|
2
|
+
import { fetchOneEntry } from '../../functions/get-content/index';
|
|
2
3
|
import { logger } from '../../helpers/logger';
|
|
3
|
-
import { fetchOneEntry } from '../../index';
|
|
4
4
|
import type { BuilderContent } from '../../types/builder-content';
|
|
5
5
|
export interface SymbolInfo {
|
|
6
6
|
model?: string;
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
import { setAttrs } from "../helpers";
|
|
10
10
|
import { fetchSymbolContent } from "./symbol.helpers";
|
|
11
11
|
import type { SymbolProps } from "./symbol.types";
|
|
12
|
+
import DynamicDiv from "../../components/dynamic-div.svelte";
|
|
12
13
|
|
|
13
14
|
export let symbol: SymbolProps["symbol"] = undefined;
|
|
14
15
|
export let attributes: SymbolProps["attributes"] = undefined;
|
|
@@ -30,6 +31,12 @@
|
|
|
30
31
|
}
|
|
31
32
|
});
|
|
32
33
|
}
|
|
34
|
+
$: blocksWrapper = () => {
|
|
35
|
+
return "div";
|
|
36
|
+
};
|
|
37
|
+
$: contentWrapper = () => {
|
|
38
|
+
return "div";
|
|
39
|
+
};
|
|
33
40
|
$: className = () => {
|
|
34
41
|
return [
|
|
35
42
|
...[attributes[getClassPropName()]],
|
|
@@ -77,7 +84,7 @@
|
|
|
77
84
|
model={symbol?.model}
|
|
78
85
|
content={contentToUse}
|
|
79
86
|
linkComponent={builderLinkComponent}
|
|
80
|
-
blocksWrapper={
|
|
81
|
-
contentWrapper={
|
|
87
|
+
blocksWrapper={blocksWrapper()}
|
|
88
|
+
contentWrapper={contentWrapper()}
|
|
82
89
|
/>
|
|
83
90
|
</div>
|
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import type { ComponentInfo } from '../../types/components';
|
|
2
|
+
const defaultTab = {
|
|
3
|
+
'@type': '@builder.io/sdk:Element',
|
|
4
|
+
responsiveStyles: {
|
|
5
|
+
large: {
|
|
6
|
+
paddingLeft: '20px',
|
|
7
|
+
paddingRight: '20px',
|
|
8
|
+
paddingTop: '10px',
|
|
9
|
+
paddingBottom: '10px',
|
|
10
|
+
minWidth: '100px',
|
|
11
|
+
textAlign: 'center',
|
|
12
|
+
display: 'flex',
|
|
13
|
+
flexDirection: 'column',
|
|
14
|
+
cursor: 'pointer',
|
|
15
|
+
userSelect: 'none'
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
component: {
|
|
19
|
+
name: 'Text',
|
|
20
|
+
options: {
|
|
21
|
+
text: 'New tab'
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
const defaultElement = {
|
|
26
|
+
'@type': '@builder.io/sdk:Element',
|
|
27
|
+
responsiveStyles: {
|
|
28
|
+
large: {
|
|
29
|
+
height: '200px',
|
|
30
|
+
display: 'flex',
|
|
31
|
+
marginTop: '20px',
|
|
32
|
+
flexDirection: 'column'
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
component: {
|
|
36
|
+
name: 'Text',
|
|
37
|
+
options: {
|
|
38
|
+
text: 'New tab content '
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
export const componentInfo: ComponentInfo = {
|
|
43
|
+
name: 'Builder: Tabs',
|
|
44
|
+
inputs: [{
|
|
45
|
+
name: 'tabs',
|
|
46
|
+
type: 'list',
|
|
47
|
+
broadcast: true,
|
|
48
|
+
subFields: [{
|
|
49
|
+
name: 'label',
|
|
50
|
+
type: 'uiBlocks',
|
|
51
|
+
hideFromUI: true,
|
|
52
|
+
defaultValue: [defaultTab]
|
|
53
|
+
}, {
|
|
54
|
+
name: 'content',
|
|
55
|
+
type: 'uiBlocks',
|
|
56
|
+
hideFromUI: true,
|
|
57
|
+
defaultValue: [defaultElement]
|
|
58
|
+
}],
|
|
59
|
+
defaultValue: [{
|
|
60
|
+
label: [{
|
|
61
|
+
...defaultTab,
|
|
62
|
+
component: {
|
|
63
|
+
name: 'Text',
|
|
64
|
+
options: {
|
|
65
|
+
text: 'Tab 1'
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
}],
|
|
69
|
+
content: [{
|
|
70
|
+
...defaultElement,
|
|
71
|
+
component: {
|
|
72
|
+
name: 'Text',
|
|
73
|
+
options: {
|
|
74
|
+
text: 'Tab 1 content'
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}]
|
|
78
|
+
}, {
|
|
79
|
+
label: [{
|
|
80
|
+
...defaultTab,
|
|
81
|
+
component: {
|
|
82
|
+
name: 'Text',
|
|
83
|
+
options: {
|
|
84
|
+
text: 'Tab 2'
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}],
|
|
88
|
+
content: [{
|
|
89
|
+
...defaultElement,
|
|
90
|
+
component: {
|
|
91
|
+
name: 'Text',
|
|
92
|
+
options: {
|
|
93
|
+
text: 'Tab 2 content'
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}]
|
|
97
|
+
}]
|
|
98
|
+
}, {
|
|
99
|
+
name: 'activeTabStyle',
|
|
100
|
+
type: 'uiStyle',
|
|
101
|
+
helperText: 'CSS styles for the active tab',
|
|
102
|
+
defaultValue: {
|
|
103
|
+
backgroundColor: 'rgba(0, 0, 0, 0.1)'
|
|
104
|
+
}
|
|
105
|
+
}, {
|
|
106
|
+
name: 'defaultActiveTab',
|
|
107
|
+
type: 'number',
|
|
108
|
+
helperText: 'Default tab to open to. Set to "1" for the first tab, "2" for the second, or choose "0" for none',
|
|
109
|
+
defaultValue: 1,
|
|
110
|
+
advanced: true
|
|
111
|
+
}, {
|
|
112
|
+
name: 'collapsible',
|
|
113
|
+
type: 'boolean',
|
|
114
|
+
helperText: 'If on, clicking an open tab closes it so no tabs are active',
|
|
115
|
+
defaultValue: false,
|
|
116
|
+
advanced: true
|
|
117
|
+
}, {
|
|
118
|
+
name: 'tabHeaderLayout',
|
|
119
|
+
type: 'enum',
|
|
120
|
+
helperText: 'Change the layout of the tab headers (uses justify-content)',
|
|
121
|
+
defaultValue: 'flex-start',
|
|
122
|
+
enum: [{
|
|
123
|
+
label: 'Center',
|
|
124
|
+
value: 'center'
|
|
125
|
+
}, {
|
|
126
|
+
label: 'Space between',
|
|
127
|
+
value: 'space-between'
|
|
128
|
+
}, {
|
|
129
|
+
label: 'Space around',
|
|
130
|
+
value: 'space-around'
|
|
131
|
+
}, {
|
|
132
|
+
label: 'Left',
|
|
133
|
+
value: 'flex-start'
|
|
134
|
+
}, {
|
|
135
|
+
label: 'Right',
|
|
136
|
+
value: 'flex-end'
|
|
137
|
+
}]
|
|
138
|
+
}]
|
|
139
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './tabs.svelte'
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import Blocks from "../../components/blocks/blocks.svelte";
|
|
3
|
+
import type { BuilderBlock } from "../../types/builder-block";
|
|
4
|
+
import type { TabsProps } from "./tabs.types";
|
|
5
|
+
|
|
6
|
+
export let defaultActiveTab: TabsProps["defaultActiveTab"] = undefined;
|
|
7
|
+
export let tabs: TabsProps["tabs"];
|
|
8
|
+
export let activeTabStyle: TabsProps["activeTabStyle"] = undefined;
|
|
9
|
+
export let tabHeaderLayout: TabsProps["tabHeaderLayout"] = undefined;
|
|
10
|
+
export let collapsible: TabsProps["collapsible"] = undefined;
|
|
11
|
+
export let builderBlock: TabsProps["builderBlock"];
|
|
12
|
+
export let builderContext: TabsProps["builderContext"];
|
|
13
|
+
export let builderComponents: TabsProps["builderComponents"];
|
|
14
|
+
export let builderLinkComponent: TabsProps["builderLinkComponent"] =
|
|
15
|
+
undefined;
|
|
16
|
+
function stringifyStyles(stylesObj) {
|
|
17
|
+
let styles = "";
|
|
18
|
+
for (let key in stylesObj) {
|
|
19
|
+
const dashedKey = key.replace(/[A-Z]/g, function (match) {
|
|
20
|
+
return "-" + match.toLowerCase();
|
|
21
|
+
});
|
|
22
|
+
styles += dashedKey + ":" + stylesObj[key] + ";";
|
|
23
|
+
}
|
|
24
|
+
return styles;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function activeTabContent(active: number) {
|
|
28
|
+
return tabs && tabs[active].content;
|
|
29
|
+
}
|
|
30
|
+
function getActiveTabStyle(index: number) {
|
|
31
|
+
return activeTab === index ? activeTabStyle : {};
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
let activeTab = defaultActiveTab ? defaultActiveTab - 1 : 0;
|
|
35
|
+
</script>
|
|
36
|
+
|
|
37
|
+
<div>
|
|
38
|
+
<div
|
|
39
|
+
style={stringifyStyles({
|
|
40
|
+
display: "flex",
|
|
41
|
+
flexDirection: "row",
|
|
42
|
+
justifyContent: tabHeaderLayout || "flex-start",
|
|
43
|
+
overflow: "auto",
|
|
44
|
+
})}
|
|
45
|
+
class="builder-tabs-wrap"
|
|
46
|
+
>
|
|
47
|
+
{#each tabs as tab, index (index)}
|
|
48
|
+
<span
|
|
49
|
+
style={stringifyStyles(getActiveTabStyle(index))}
|
|
50
|
+
class={`builder-tab-wrap ${
|
|
51
|
+
activeTab === index ? "builder-tab-active" : ""
|
|
52
|
+
}`}
|
|
53
|
+
on:click={(event) => {
|
|
54
|
+
if (index === activeTab && collapsible) {
|
|
55
|
+
activeTab = -1;
|
|
56
|
+
} else {
|
|
57
|
+
activeTab = index;
|
|
58
|
+
}
|
|
59
|
+
}}
|
|
60
|
+
><Blocks
|
|
61
|
+
parent={builderBlock.id}
|
|
62
|
+
path={`component.options.tabs.${index}.label`}
|
|
63
|
+
blocks={tab.label}
|
|
64
|
+
context={builderContext}
|
|
65
|
+
registeredComponents={builderComponents}
|
|
66
|
+
linkComponent={builderLinkComponent}
|
|
67
|
+
/></span
|
|
68
|
+
>
|
|
69
|
+
{/each}
|
|
70
|
+
</div>
|
|
71
|
+
{#if activeTabContent(activeTab)}
|
|
72
|
+
<div>
|
|
73
|
+
<Blocks
|
|
74
|
+
parent={builderBlock.id}
|
|
75
|
+
path={`component.options.tabs.${activeTab}.content`}
|
|
76
|
+
blocks={activeTabContent(activeTab)}
|
|
77
|
+
context={builderContext}
|
|
78
|
+
registeredComponents={builderComponents}
|
|
79
|
+
linkComponent={builderLinkComponent}
|
|
80
|
+
/>
|
|
81
|
+
</div>
|
|
82
|
+
{/if}
|
|
83
|
+
</div>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { BuilderBlock } from '../../types/builder-block';
|
|
2
|
+
import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
|
|
3
|
+
export interface TabsProps extends BuilderComponentsProp, BuilderLinkComponentProp, BuilderDataProps {
|
|
4
|
+
tabs: {
|
|
5
|
+
label: BuilderBlock[];
|
|
6
|
+
content: BuilderBlock[];
|
|
7
|
+
}[];
|
|
8
|
+
builderBlock: BuilderBlock;
|
|
9
|
+
defaultActiveTab?: number;
|
|
10
|
+
collapsible?: boolean;
|
|
11
|
+
tabHeaderLayout?: 'center' | 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly';
|
|
12
|
+
activeTabStyle?: any;
|
|
13
|
+
}
|