@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
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
1
|
+
import type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import { evaluate } from '../../functions/evaluate/index';
|
|
3
3
|
import { extractTextStyles } from '../../functions/extract-text-styles';
|
|
4
4
|
import { getProcessedBlock } from '../../functions/get-processed-block';
|
|
@@ -97,4 +97,10 @@ export const getInheritedStyles = ({
|
|
|
97
97
|
return {};
|
|
98
98
|
}
|
|
99
99
|
return extractTextStyles(style);
|
|
100
|
+
};
|
|
101
|
+
export const shouldPassLinkComponent = (block: RegisteredComponent | null | undefined) => {
|
|
102
|
+
return block && (block.isRSC || ['Core:Button', 'Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
103
|
+
};
|
|
104
|
+
export const shouldPassRegisteredComponents = (block: RegisteredComponent | null | undefined) => {
|
|
105
|
+
return block && (block.isRSC || ['Symbol', 'Columns', 'Form:Form', 'Builder: Tabs'].includes(block.name));
|
|
100
106
|
}
|
|
@@ -22,12 +22,15 @@
|
|
|
22
22
|
getComponent,
|
|
23
23
|
getInheritedStyles,
|
|
24
24
|
getRepeatItemData,
|
|
25
|
+
shouldPassLinkComponent,
|
|
26
|
+
shouldPassRegisteredComponents,
|
|
25
27
|
} from "./block.helpers";
|
|
26
28
|
import BlockStyles from "./components/block-styles.svelte";
|
|
27
29
|
import BlockWrapper from "./components/block-wrapper.svelte";
|
|
28
30
|
import type { ComponentProps } from "./components/component-ref/component-ref.helpers";
|
|
29
31
|
import ComponentRef from "./components/component-ref/component-ref.svelte";
|
|
30
32
|
import RepeatedBlock from "./components/repeated-block.svelte";
|
|
33
|
+
import DynamicDiv from "../dynamic-div.svelte";
|
|
31
34
|
import type { Writable } from "svelte/store";
|
|
32
35
|
|
|
33
36
|
export let block: BlockProps["block"];
|
|
@@ -101,17 +104,12 @@
|
|
|
101
104
|
componentOptions: {
|
|
102
105
|
...getBlockComponentOptions(processedBlock()),
|
|
103
106
|
builderContext: context,
|
|
104
|
-
...(blockComponent
|
|
105
|
-
blockComponent?.()?.name === "Symbol" ||
|
|
106
|
-
blockComponent?.()?.name === "Columns" ||
|
|
107
|
-
blockComponent?.()?.name === "Form:Form"
|
|
107
|
+
...(shouldPassLinkComponent(blockComponent())
|
|
108
108
|
? {
|
|
109
109
|
builderLinkComponent: linkComponent,
|
|
110
110
|
}
|
|
111
111
|
: {}),
|
|
112
|
-
...(blockComponent
|
|
113
|
-
blockComponent?.()?.name === "Columns" ||
|
|
114
|
-
blockComponent?.()?.name === "Form:Form"
|
|
112
|
+
...(shouldPassRegisteredComponents(blockComponent())
|
|
115
113
|
? {
|
|
116
114
|
builderComponents: registeredComponents,
|
|
117
115
|
}
|
|
@@ -17,29 +17,31 @@
|
|
|
17
17
|
import type { Dictionary } from "../../../types/typescript";
|
|
18
18
|
import type { Writable } from "svelte/store";
|
|
19
19
|
|
|
20
|
-
export let wrapperProps: InteractiveElementProps["wrapperProps"];
|
|
21
20
|
export let includeBlockProps: InteractiveElementProps["includeBlockProps"];
|
|
22
21
|
export let block: InteractiveElementProps["block"];
|
|
23
22
|
export let context: InteractiveElementProps["context"];
|
|
23
|
+
export let wrapperProps: InteractiveElementProps["wrapperProps"];
|
|
24
24
|
export let Wrapper: InteractiveElementProps["Wrapper"];
|
|
25
|
+
|
|
26
|
+
$: attributes = () => {
|
|
27
|
+
return includeBlockProps
|
|
28
|
+
? {
|
|
29
|
+
...getBlockProperties({
|
|
30
|
+
block: block,
|
|
31
|
+
context: $context,
|
|
32
|
+
}),
|
|
33
|
+
...getBlockActions({
|
|
34
|
+
block: block,
|
|
35
|
+
rootState: $context.rootState,
|
|
36
|
+
rootSetState: $context.rootSetState,
|
|
37
|
+
localState: $context.localState,
|
|
38
|
+
context: $context.context,
|
|
39
|
+
}),
|
|
40
|
+
}
|
|
41
|
+
: {};
|
|
42
|
+
};
|
|
25
43
|
</script>
|
|
26
44
|
|
|
27
|
-
<svelte:component
|
|
28
|
-
|
|
29
|
-
{...wrapperProps}
|
|
30
|
-
attributes={includeBlockProps
|
|
31
|
-
? {
|
|
32
|
-
...getBlockProperties({
|
|
33
|
-
block: block,
|
|
34
|
-
context: $context,
|
|
35
|
-
}),
|
|
36
|
-
...getBlockActions({
|
|
37
|
-
block: block,
|
|
38
|
-
rootState: $context.rootState,
|
|
39
|
-
rootSetState: $context.rootSetState,
|
|
40
|
-
localState: $context.localState,
|
|
41
|
-
context: $context.context,
|
|
42
|
-
}),
|
|
43
|
-
}
|
|
44
|
-
: {}}><slot /></svelte:component
|
|
45
|
+
<svelte:component this={Wrapper} {...wrapperProps} attributes={attributes()}
|
|
46
|
+
><slot /></svelte:component
|
|
45
47
|
>
|
|
@@ -45,6 +45,8 @@
|
|
|
45
45
|
BuilderComponentStateChange,
|
|
46
46
|
ContentProps,
|
|
47
47
|
} from "../content.types";
|
|
48
|
+
import { getWrapperClassName } from "./styles.helpers";
|
|
49
|
+
import DynamicDiv from "../../dynamic-div.svelte";
|
|
48
50
|
import type { Writable } from "svelte/store";
|
|
49
51
|
|
|
50
52
|
export let builderContextSignal: BuilderEditorProps["builderContextSignal"];
|
|
@@ -56,9 +58,9 @@
|
|
|
56
58
|
export let model: BuilderEditorProps["model"] = undefined;
|
|
57
59
|
export let content: BuilderEditorProps["content"] = undefined;
|
|
58
60
|
export let data: BuilderEditorProps["data"] = undefined;
|
|
61
|
+
export let showContent: BuilderEditorProps["showContent"];
|
|
59
62
|
export let contentWrapper: BuilderEditorProps["contentWrapper"] = undefined;
|
|
60
63
|
export let context: BuilderEditorProps["context"] = undefined;
|
|
61
|
-
export let showContent: BuilderEditorProps["showContent"];
|
|
62
64
|
export let contentWrapperProps: BuilderEditorProps["contentWrapperProps"] =
|
|
63
65
|
undefined;
|
|
64
66
|
|
|
@@ -276,6 +278,14 @@
|
|
|
276
278
|
});
|
|
277
279
|
}
|
|
278
280
|
}
|
|
281
|
+
$: showContentProps = () => {
|
|
282
|
+
return showContent
|
|
283
|
+
? {}
|
|
284
|
+
: {
|
|
285
|
+
hidden: true,
|
|
286
|
+
"aria-hidden": true,
|
|
287
|
+
};
|
|
288
|
+
};
|
|
279
289
|
|
|
280
290
|
let elementRef;
|
|
281
291
|
|
|
@@ -401,14 +411,9 @@
|
|
|
401
411
|
builder-content-id={$builderContextSignal.content?.id}
|
|
402
412
|
builder-model={model}
|
|
403
413
|
{...{}}
|
|
404
|
-
{...
|
|
405
|
-
? {}
|
|
406
|
-
: {
|
|
407
|
-
hidden: true,
|
|
408
|
-
"aria-hidden": true,
|
|
409
|
-
}}
|
|
414
|
+
{...showContentProps()}
|
|
410
415
|
{...contentWrapperProps}
|
|
411
|
-
class={
|
|
416
|
+
class={getWrapperClassName(content?.testVariationId || content?.id)}
|
|
412
417
|
on:initeditingbldr={(event) => {
|
|
413
418
|
elementRef_onIniteditingbldr(event);
|
|
414
419
|
}}
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
} from "./content.helpers";
|
|
25
25
|
import type { ContentProps } from "./content.types";
|
|
26
26
|
import { wrapComponentRef } from "./wrap-component-ref";
|
|
27
|
+
import DynamicDiv from "../dynamic-div.svelte";
|
|
27
28
|
|
|
28
29
|
export let content: ContentProps["content"] = undefined;
|
|
29
30
|
export let customComponents: ContentProps["customComponents"] = undefined;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script context="module" lang="ts">
|
|
2
|
+
export interface DynamicDivProps {
|
|
3
|
+
children?: any;
|
|
4
|
+
attributes: any;
|
|
5
|
+
actionAttributes: any;
|
|
6
|
+
BlockWrapperProps: any;
|
|
7
|
+
builderPath: any;
|
|
8
|
+
builderParentId: any;
|
|
9
|
+
BlocksWrapperProps: any;
|
|
10
|
+
contentWrapperProps: any;
|
|
11
|
+
builderModel: any;
|
|
12
|
+
ref: any;
|
|
13
|
+
}
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<script lang="ts">
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<div><slot /></div>
|
|
@@ -12,10 +12,13 @@ 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 type { RegisteredComponent } from '../context/types';
|
|
18
20
|
import { getExtraComponents } from './extra-components';
|
|
21
|
+
import { TARGET } from './target';
|
|
19
22
|
|
|
20
23
|
/**
|
|
21
24
|
* Returns a list of all registered components.
|
|
@@ -45,4 +48,7 @@ export const getDefaultRegisteredComponents: () => RegisteredComponent[] = () =>
|
|
|
45
48
|
}, {
|
|
46
49
|
component: Text,
|
|
47
50
|
...textComponentInfo
|
|
48
|
-
}, ...
|
|
51
|
+
}, ...(TARGET === 'rsc' ? [] : [{
|
|
52
|
+
component: Tabs,
|
|
53
|
+
...tabsComponentInfo
|
|
54
|
+
}]), ...getExtraComponents()]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.25"
|
|
@@ -12,6 +12,7 @@
|
|
|
12
12
|
*/
|
|
13
13
|
import ivm from 'isolated-vm';
|
|
14
14
|
import { setIvm } from './node-runtime';
|
|
15
|
+
import type { IsolateOptions } from 'isolated-vm';
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* This function initializes the SDK on a Node server. It handles importing the
|
|
@@ -22,6 +23,10 @@ import { setIvm } from './node-runtime';
|
|
|
22
23
|
* - The NextJS Pages router's `_document.tsx`
|
|
23
24
|
* - Your Remix route's `loader`
|
|
24
25
|
*/
|
|
25
|
-
export const initializeNodeRuntime = (
|
|
26
|
-
|
|
26
|
+
export const initializeNodeRuntime = ({
|
|
27
|
+
ivmIsolateOptions
|
|
28
|
+
}: {
|
|
29
|
+
ivmIsolateOptions?: IsolateOptions;
|
|
30
|
+
}) => {
|
|
31
|
+
setIvm(ivm, ivmIsolateOptions);
|
|
27
32
|
}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { Context, IsolateOptions } from 'isolated-vm';
|
|
1
2
|
import { MSG_PREFIX, logger } from '../../../helpers/logger';
|
|
2
3
|
import { fastClone } from '../../fast-clone';
|
|
3
4
|
import { set } from '../../set';
|
|
@@ -54,26 +55,29 @@ function theFunction() {
|
|
|
54
55
|
${code}
|
|
55
56
|
}
|
|
56
57
|
|
|
57
|
-
|
|
58
|
+
const output = theFunction()
|
|
58
59
|
|
|
59
60
|
if (typeof output === 'object' && output !== null) {
|
|
60
|
-
|
|
61
|
+
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
62
|
+
} else {
|
|
63
|
+
return output;
|
|
61
64
|
}
|
|
62
|
-
|
|
63
|
-
output;
|
|
64
65
|
`;
|
|
65
66
|
};
|
|
66
|
-
|
|
67
|
+
type IsolatedVMImport = typeof import('isolated-vm');
|
|
68
|
+
let IVM_INSTANCE: IsolatedVMImport | null = null;
|
|
69
|
+
let IVM_CONTEXT: Context | null = null;
|
|
67
70
|
|
|
68
71
|
/**
|
|
69
72
|
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
70
73
|
* This is useful for environments that are not able to rely on our
|
|
71
74
|
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
72
75
|
*/
|
|
73
|
-
export const setIvm = (ivm:
|
|
76
|
+
export const setIvm = (ivm: IsolatedVMImport, options: IsolateOptions = {}) => {
|
|
74
77
|
IVM_INSTANCE = ivm;
|
|
78
|
+
setIsolateContext(options);
|
|
75
79
|
};
|
|
76
|
-
const getIvm = ():
|
|
80
|
+
const getIvm = (): IsolatedVMImport => {
|
|
77
81
|
try {
|
|
78
82
|
if (IVM_INSTANCE) return IVM_INSTANCE;
|
|
79
83
|
const dynRequiredIvm = safeDynamicRequire('isolated-vm');
|
|
@@ -90,12 +94,30 @@ const getIvm = (): typeof import('isolated-vm') => {
|
|
|
90
94
|
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
91
95
|
`);
|
|
92
96
|
};
|
|
93
|
-
|
|
97
|
+
function setIsolateContext(options: IsolateOptions = {
|
|
98
|
+
memoryLimit: 128
|
|
99
|
+
}) {
|
|
94
100
|
const ivm = getIvm();
|
|
95
|
-
const isolate = new ivm.Isolate(
|
|
96
|
-
|
|
101
|
+
const isolate = new ivm.Isolate(options);
|
|
102
|
+
const context = isolate.createContextSync();
|
|
103
|
+
const jail = context.global;
|
|
104
|
+
|
|
105
|
+
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
106
|
+
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
107
|
+
jail.setSync('global', jail.derefInto());
|
|
108
|
+
|
|
109
|
+
// We will create a basic `log` function for the new isolate to use.
|
|
110
|
+
jail.setSync('log', function (...logArgs: any[]) {
|
|
111
|
+
console.log(...logArgs);
|
|
97
112
|
});
|
|
98
|
-
|
|
113
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
114
|
+
IVM_CONTEXT = context;
|
|
115
|
+
return context;
|
|
116
|
+
}
|
|
117
|
+
const getIsolateContext = () => {
|
|
118
|
+
if (IVM_CONTEXT) return IVM_CONTEXT;
|
|
119
|
+
const context = setIsolateContext();
|
|
120
|
+
return context;
|
|
99
121
|
};
|
|
100
122
|
export const runInNode = ({
|
|
101
123
|
code,
|
|
@@ -119,14 +141,6 @@ export const runInNode = ({
|
|
|
119
141
|
});
|
|
120
142
|
const isolateContext = getIsolateContext();
|
|
121
143
|
const jail = isolateContext.global;
|
|
122
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
123
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
124
|
-
jail.setSync('global', jail.derefInto());
|
|
125
|
-
|
|
126
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
127
|
-
jail.setSync('log', function (...logArgs: any[]) {
|
|
128
|
-
console.log(...logArgs);
|
|
129
|
-
});
|
|
130
144
|
|
|
131
145
|
/**
|
|
132
146
|
* Propagate state changes back to the reactive root state.
|
|
@@ -147,12 +161,11 @@ export const runInNode = ({
|
|
|
147
161
|
} : arg) : null;
|
|
148
162
|
jail.setSync(getSyncValName(key), val);
|
|
149
163
|
});
|
|
150
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
151
164
|
const evalStr = processCode({
|
|
152
165
|
code,
|
|
153
166
|
args
|
|
154
167
|
});
|
|
155
|
-
const resultStr = isolateContext.
|
|
168
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
156
169
|
try {
|
|
157
170
|
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
158
171
|
const res = JSON.parse(resultStr);
|
package/src/types/targets.ts
CHANGED
|
@@ -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'
|