@builder.io/sdk-svelte 2.0.15 → 2.0.18
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/components/awaiter.svelte +19 -0
- package/lib/browser/components/awaiter.svelte.d.ts +21 -0
- package/lib/browser/components/block/components/interactive-element.svelte +14 -4
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/context/component-reference-types.d.ts +15 -0
- package/lib/browser/context/component-reference-types.js +1 -0
- package/lib/browser/context/types.d.ts +2 -1
- package/lib/browser/functions/evaluate/choose-eval.js +3 -1
- package/lib/browser/functions/evaluate/node-runtime/init.js +9 -0
- package/lib/browser/functions/evaluate/node-runtime/node-runtime.js +1 -1
- package/lib/browser/functions/evaluate/should-force-browser-runtime-in-node.d.ts +3 -1
- package/lib/browser/functions/evaluate/should-force-browser-runtime-in-node.js +4 -2
- package/lib/edge/components/awaiter.svelte +19 -0
- package/lib/edge/components/awaiter.svelte.d.ts +21 -0
- package/lib/edge/components/block/components/interactive-element.svelte +14 -4
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/context/component-reference-types.d.ts +15 -0
- package/lib/edge/context/component-reference-types.js +1 -0
- package/lib/edge/context/types.d.ts +2 -1
- package/lib/edge/functions/evaluate/choose-eval.js +3 -1
- package/lib/edge/functions/evaluate/node-runtime/init.js +9 -0
- package/lib/edge/functions/evaluate/node-runtime/node-runtime.js +1 -1
- package/lib/edge/functions/evaluate/should-force-browser-runtime-in-node.d.ts +3 -1
- package/lib/edge/functions/evaluate/should-force-browser-runtime-in-node.js +4 -2
- package/lib/node/components/awaiter.svelte +19 -0
- package/lib/node/components/awaiter.svelte.d.ts +21 -0
- package/lib/node/components/block/components/interactive-element.svelte +14 -4
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/context/component-reference-types.d.ts +15 -0
- package/lib/node/context/component-reference-types.js +1 -0
- package/lib/node/context/types.d.ts +2 -1
- package/lib/node/functions/evaluate/choose-eval.js +3 -1
- package/lib/node/functions/evaluate/node-runtime/init.js +9 -0
- package/lib/node/functions/evaluate/node-runtime/node-runtime.js +1 -1
- package/lib/node/functions/evaluate/should-force-browser-runtime-in-node.d.ts +3 -1
- package/lib/node/functions/evaluate/should-force-browser-runtime-in-node.js +4 -2
- package/package.json +1 -1
- package/src/components/awaiter.svelte +20 -0
- package/src/components/block/components/interactive-element.svelte +14 -4
- package/src/constants/sdk-version.ts +1 -1
- package/src/context/component-reference-types.ts +16 -0
- package/src/context/types.ts +2 -1
- package/src/functions/evaluate/choose-eval.ts +3 -1
- package/src/functions/evaluate/node-runtime/init.ts +9 -0
- package/src/functions/evaluate/node-runtime/node-runtime.ts +1 -1
- package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +8 -2
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script>export let load;
|
|
2
|
+
export let fallback;
|
|
3
|
+
export let props;
|
|
4
|
+
export let attributes;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#await load()}
|
|
8
|
+
{#if fallback}
|
|
9
|
+
<svelte:component this={fallback} />
|
|
10
|
+
{/if}
|
|
11
|
+
{:then { default: Component }}
|
|
12
|
+
<svelte:component
|
|
13
|
+
this={Component}
|
|
14
|
+
{...props}
|
|
15
|
+
attributes={attributes}
|
|
16
|
+
>
|
|
17
|
+
<slot />
|
|
18
|
+
</svelte:component>
|
|
19
|
+
{/await}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
load: () => Promise<any>;
|
|
5
|
+
fallback: any;
|
|
6
|
+
props: any;
|
|
7
|
+
attributes: any;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type AwaiterProps = typeof __propDef.props;
|
|
17
|
+
export type AwaiterEvents = typeof __propDef.events;
|
|
18
|
+
export type AwaiterSlots = typeof __propDef.slots;
|
|
19
|
+
export default class Awaiter extends SvelteComponent<AwaiterProps, AwaiterEvents, AwaiterSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import { getBlockActions } from "../../../functions/get-block-actions";
|
|
4
4
|
import { getBlockProperties } from "../../../functions/get-block-properties";
|
|
5
|
+
import Awaiter from "../../awaiter.svelte";
|
|
5
6
|
export let includeBlockProps;
|
|
6
7
|
export let block;
|
|
7
8
|
export let context;
|
|
8
|
-
export let wrapperProps;
|
|
9
9
|
export let Wrapper;
|
|
10
|
+
export let wrapperProps;
|
|
10
11
|
$: attributes = () => {
|
|
11
12
|
return includeBlockProps
|
|
12
13
|
? {
|
|
@@ -26,6 +27,15 @@ $: attributes = () => {
|
|
|
26
27
|
};
|
|
27
28
|
</script>
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
{#if Wrapper.load}
|
|
31
|
+
<Awaiter
|
|
32
|
+
load={Wrapper.load}
|
|
33
|
+
fallback={Wrapper.fallback}
|
|
34
|
+
props={wrapperProps}
|
|
35
|
+
attributes={attributes()}><slot /></Awaiter
|
|
36
|
+
>
|
|
37
|
+
{:else}
|
|
38
|
+
<svelte:component this={Wrapper} {...wrapperProps} attributes={attributes()}
|
|
39
|
+
><slot /></svelte:component
|
|
40
|
+
>
|
|
41
|
+
{/if}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.18";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.18";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SvelteComponent } from 'svelte';
|
|
2
|
+
export type ComponentReference = {
|
|
3
|
+
/**
|
|
4
|
+
* A dynamic import function pointing to the component.
|
|
5
|
+
* Example: `() => import('../components/my-component.svelte')`
|
|
6
|
+
* @returns A Promise that resolves to the loaded component.
|
|
7
|
+
*/
|
|
8
|
+
load: () => Promise<{
|
|
9
|
+
default: typeof SvelteComponent<any>;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* An optional fallback component to render while the dynamic component is loading.
|
|
13
|
+
*/
|
|
14
|
+
fallback?: typeof SvelteComponent<any>;
|
|
15
|
+
} | typeof SvelteComponent<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,9 +3,10 @@ import type { ApiVersion } from '../types/api-version';
|
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content';
|
|
4
4
|
import type { ComponentInfo } from '../types/components';
|
|
5
5
|
import type { Dictionary, Nullable } from '../types/typescript';
|
|
6
|
+
import type { ComponentReference } from './component-reference-types';
|
|
6
7
|
import type { ExtraContextTypes } from './extra-context-types';
|
|
7
8
|
export type RegisteredComponent = ComponentInfo & {
|
|
8
|
-
component:
|
|
9
|
+
component: ComponentReference;
|
|
9
10
|
};
|
|
10
11
|
export type RegisteredComponents = Dictionary<RegisteredComponent>;
|
|
11
12
|
export type BuilderRenderState = Record<string, unknown>;
|
|
@@ -21,4 +21,6 @@ import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-
|
|
|
21
21
|
* Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
|
|
22
22
|
* end up sending the server runtime code to the browser (most notably in dev mode).
|
|
23
23
|
*/
|
|
24
|
-
export const chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode(
|
|
24
|
+
export const chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
|
|
25
|
+
shouldLogWarning: true
|
|
26
|
+
}) ? runInBrowser(args) : evaluator(args);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { shouldForceBrowserRuntimeInNode } from '../should-force-browser-runtime-in-node';
|
|
1
2
|
/**
|
|
2
3
|
* This file:
|
|
3
4
|
* - imports `isolated-vm`, which can only be made from a file that never runs
|
|
@@ -23,6 +24,14 @@ import { setIvm } from './node-runtime';
|
|
|
23
24
|
* - Qwik's `entry.ssr.tsx` file
|
|
24
25
|
*/
|
|
25
26
|
export const initializeNodeRuntime = (args) => {
|
|
27
|
+
/**
|
|
28
|
+
* skip initialization if we are on an arm64 machine and running node 20
|
|
29
|
+
*/
|
|
30
|
+
if (shouldForceBrowserRuntimeInNode({
|
|
31
|
+
shouldLogWarning: true
|
|
32
|
+
})) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
26
35
|
const { ivmIsolateOptions } = args || {};
|
|
27
36
|
setIvm(ivm, ivmIsolateOptions);
|
|
28
37
|
};
|
|
@@ -67,7 +67,7 @@ export const setIvm = (ivm, options = {}) => {
|
|
|
67
67
|
setIsolateContext(options);
|
|
68
68
|
};
|
|
69
69
|
// only mention the script for SDKs that have it.
|
|
70
|
-
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik';
|
|
70
|
+
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik' || SDK_NAME === '@builder.io/sdk-vue';
|
|
71
71
|
const getIvm = () => {
|
|
72
72
|
try {
|
|
73
73
|
if (IVM_INSTANCE)
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { logger } from '../../helpers/logger';
|
|
2
2
|
import { isNodeRuntime } from '../is-node-runtime';
|
|
3
|
-
export const shouldForceBrowserRuntimeInNode = () => {
|
|
3
|
+
export const shouldForceBrowserRuntimeInNode = ({ shouldLogWarning }) => {
|
|
4
4
|
if (!isNodeRuntime())
|
|
5
5
|
return false;
|
|
6
6
|
const isArm64 = process.arch === 'arm64';
|
|
7
7
|
const isNode20 = process.version.startsWith('v20');
|
|
8
8
|
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes('--no-node-snapshot');
|
|
9
9
|
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
10
|
-
|
|
10
|
+
if (shouldLogWarning) {
|
|
11
|
+
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
11
12
|
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
12
13
|
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
13
14
|
`);
|
|
15
|
+
}
|
|
14
16
|
return true;
|
|
15
17
|
}
|
|
16
18
|
return false;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script>export let load;
|
|
2
|
+
export let fallback;
|
|
3
|
+
export let props;
|
|
4
|
+
export let attributes;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#await load()}
|
|
8
|
+
{#if fallback}
|
|
9
|
+
<svelte:component this={fallback} />
|
|
10
|
+
{/if}
|
|
11
|
+
{:then { default: Component }}
|
|
12
|
+
<svelte:component
|
|
13
|
+
this={Component}
|
|
14
|
+
{...props}
|
|
15
|
+
attributes={attributes}
|
|
16
|
+
>
|
|
17
|
+
<slot />
|
|
18
|
+
</svelte:component>
|
|
19
|
+
{/await}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
load: () => Promise<any>;
|
|
5
|
+
fallback: any;
|
|
6
|
+
props: any;
|
|
7
|
+
attributes: any;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type AwaiterProps = typeof __propDef.props;
|
|
17
|
+
export type AwaiterEvents = typeof __propDef.events;
|
|
18
|
+
export type AwaiterSlots = typeof __propDef.slots;
|
|
19
|
+
export default class Awaiter extends SvelteComponent<AwaiterProps, AwaiterEvents, AwaiterSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import { getBlockActions } from "../../../functions/get-block-actions";
|
|
4
4
|
import { getBlockProperties } from "../../../functions/get-block-properties";
|
|
5
|
+
import Awaiter from "../../awaiter.svelte";
|
|
5
6
|
export let includeBlockProps;
|
|
6
7
|
export let block;
|
|
7
8
|
export let context;
|
|
8
|
-
export let wrapperProps;
|
|
9
9
|
export let Wrapper;
|
|
10
|
+
export let wrapperProps;
|
|
10
11
|
$: attributes = () => {
|
|
11
12
|
return includeBlockProps
|
|
12
13
|
? {
|
|
@@ -26,6 +27,15 @@ $: attributes = () => {
|
|
|
26
27
|
};
|
|
27
28
|
</script>
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
{#if Wrapper.load}
|
|
31
|
+
<Awaiter
|
|
32
|
+
load={Wrapper.load}
|
|
33
|
+
fallback={Wrapper.fallback}
|
|
34
|
+
props={wrapperProps}
|
|
35
|
+
attributes={attributes()}><slot /></Awaiter
|
|
36
|
+
>
|
|
37
|
+
{:else}
|
|
38
|
+
<svelte:component this={Wrapper} {...wrapperProps} attributes={attributes()}
|
|
39
|
+
><slot /></svelte:component
|
|
40
|
+
>
|
|
41
|
+
{/if}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.18";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.18";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SvelteComponent } from 'svelte';
|
|
2
|
+
export type ComponentReference = {
|
|
3
|
+
/**
|
|
4
|
+
* A dynamic import function pointing to the component.
|
|
5
|
+
* Example: `() => import('../components/my-component.svelte')`
|
|
6
|
+
* @returns A Promise that resolves to the loaded component.
|
|
7
|
+
*/
|
|
8
|
+
load: () => Promise<{
|
|
9
|
+
default: typeof SvelteComponent<any>;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* An optional fallback component to render while the dynamic component is loading.
|
|
13
|
+
*/
|
|
14
|
+
fallback?: typeof SvelteComponent<any>;
|
|
15
|
+
} | typeof SvelteComponent<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,9 +3,10 @@ import type { ApiVersion } from '../types/api-version';
|
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content';
|
|
4
4
|
import type { ComponentInfo } from '../types/components';
|
|
5
5
|
import type { Dictionary, Nullable } from '../types/typescript';
|
|
6
|
+
import type { ComponentReference } from './component-reference-types';
|
|
6
7
|
import type { ExtraContextTypes } from './extra-context-types';
|
|
7
8
|
export type RegisteredComponent = ComponentInfo & {
|
|
8
|
-
component:
|
|
9
|
+
component: ComponentReference;
|
|
9
10
|
};
|
|
10
11
|
export type RegisteredComponents = Dictionary<RegisteredComponent>;
|
|
11
12
|
export type BuilderRenderState = Record<string, unknown>;
|
|
@@ -21,4 +21,6 @@ import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-
|
|
|
21
21
|
* Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
|
|
22
22
|
* end up sending the server runtime code to the browser (most notably in dev mode).
|
|
23
23
|
*/
|
|
24
|
-
export const chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode(
|
|
24
|
+
export const chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
|
|
25
|
+
shouldLogWarning: true
|
|
26
|
+
}) ? runInBrowser(args) : evaluator(args);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { shouldForceBrowserRuntimeInNode } from '../should-force-browser-runtime-in-node';
|
|
1
2
|
/**
|
|
2
3
|
* This file:
|
|
3
4
|
* - imports `isolated-vm`, which can only be made from a file that never runs
|
|
@@ -23,6 +24,14 @@ import { setIvm } from './node-runtime';
|
|
|
23
24
|
* - Qwik's `entry.ssr.tsx` file
|
|
24
25
|
*/
|
|
25
26
|
export const initializeNodeRuntime = (args) => {
|
|
27
|
+
/**
|
|
28
|
+
* skip initialization if we are on an arm64 machine and running node 20
|
|
29
|
+
*/
|
|
30
|
+
if (shouldForceBrowserRuntimeInNode({
|
|
31
|
+
shouldLogWarning: true
|
|
32
|
+
})) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
26
35
|
const { ivmIsolateOptions } = args || {};
|
|
27
36
|
setIvm(ivm, ivmIsolateOptions);
|
|
28
37
|
};
|
|
@@ -67,7 +67,7 @@ export const setIvm = (ivm, options = {}) => {
|
|
|
67
67
|
setIsolateContext(options);
|
|
68
68
|
};
|
|
69
69
|
// only mention the script for SDKs that have it.
|
|
70
|
-
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik';
|
|
70
|
+
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik' || SDK_NAME === '@builder.io/sdk-vue';
|
|
71
71
|
const getIvm = () => {
|
|
72
72
|
try {
|
|
73
73
|
if (IVM_INSTANCE)
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { logger } from '../../helpers/logger';
|
|
2
2
|
import { isNodeRuntime } from '../is-node-runtime';
|
|
3
|
-
export const shouldForceBrowserRuntimeInNode = () => {
|
|
3
|
+
export const shouldForceBrowserRuntimeInNode = ({ shouldLogWarning }) => {
|
|
4
4
|
if (!isNodeRuntime())
|
|
5
5
|
return false;
|
|
6
6
|
const isArm64 = process.arch === 'arm64';
|
|
7
7
|
const isNode20 = process.version.startsWith('v20');
|
|
8
8
|
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes('--no-node-snapshot');
|
|
9
9
|
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
10
|
-
|
|
10
|
+
if (shouldLogWarning) {
|
|
11
|
+
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
11
12
|
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
12
13
|
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
13
14
|
`);
|
|
15
|
+
}
|
|
14
16
|
return true;
|
|
15
17
|
}
|
|
16
18
|
return false;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
<script>export let load;
|
|
2
|
+
export let fallback;
|
|
3
|
+
export let props;
|
|
4
|
+
export let attributes;
|
|
5
|
+
</script>
|
|
6
|
+
|
|
7
|
+
{#await load()}
|
|
8
|
+
{#if fallback}
|
|
9
|
+
<svelte:component this={fallback} />
|
|
10
|
+
{/if}
|
|
11
|
+
{:then { default: Component }}
|
|
12
|
+
<svelte:component
|
|
13
|
+
this={Component}
|
|
14
|
+
{...props}
|
|
15
|
+
attributes={attributes}
|
|
16
|
+
>
|
|
17
|
+
<slot />
|
|
18
|
+
</svelte:component>
|
|
19
|
+
{/await}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
|
2
|
+
declare const __propDef: {
|
|
3
|
+
props: {
|
|
4
|
+
load: () => Promise<any>;
|
|
5
|
+
fallback: any;
|
|
6
|
+
props: any;
|
|
7
|
+
attributes: any;
|
|
8
|
+
};
|
|
9
|
+
events: {
|
|
10
|
+
[evt: string]: CustomEvent<any>;
|
|
11
|
+
};
|
|
12
|
+
slots: {
|
|
13
|
+
default: {};
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export type AwaiterProps = typeof __propDef.props;
|
|
17
|
+
export type AwaiterEvents = typeof __propDef.events;
|
|
18
|
+
export type AwaiterSlots = typeof __propDef.slots;
|
|
19
|
+
export default class Awaiter extends SvelteComponent<AwaiterProps, AwaiterEvents, AwaiterSlots> {
|
|
20
|
+
}
|
|
21
|
+
export {};
|
|
@@ -2,11 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
<script>import { getBlockActions } from "../../../functions/get-block-actions";
|
|
4
4
|
import { getBlockProperties } from "../../../functions/get-block-properties";
|
|
5
|
+
import Awaiter from "../../awaiter.svelte";
|
|
5
6
|
export let includeBlockProps;
|
|
6
7
|
export let block;
|
|
7
8
|
export let context;
|
|
8
|
-
export let wrapperProps;
|
|
9
9
|
export let Wrapper;
|
|
10
|
+
export let wrapperProps;
|
|
10
11
|
$: attributes = () => {
|
|
11
12
|
return includeBlockProps
|
|
12
13
|
? {
|
|
@@ -26,6 +27,15 @@ $: attributes = () => {
|
|
|
26
27
|
};
|
|
27
28
|
</script>
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
{#if Wrapper.load}
|
|
31
|
+
<Awaiter
|
|
32
|
+
load={Wrapper.load}
|
|
33
|
+
fallback={Wrapper.fallback}
|
|
34
|
+
props={wrapperProps}
|
|
35
|
+
attributes={attributes()}><slot /></Awaiter
|
|
36
|
+
>
|
|
37
|
+
{:else}
|
|
38
|
+
<svelte:component this={Wrapper} {...wrapperProps} attributes={attributes()}
|
|
39
|
+
><slot /></svelte:component
|
|
40
|
+
>
|
|
41
|
+
{/if}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "2.0.
|
|
1
|
+
export declare const SDK_VERSION = "2.0.18";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.18";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { SvelteComponent } from 'svelte';
|
|
2
|
+
export type ComponentReference = {
|
|
3
|
+
/**
|
|
4
|
+
* A dynamic import function pointing to the component.
|
|
5
|
+
* Example: `() => import('../components/my-component.svelte')`
|
|
6
|
+
* @returns A Promise that resolves to the loaded component.
|
|
7
|
+
*/
|
|
8
|
+
load: () => Promise<{
|
|
9
|
+
default: typeof SvelteComponent<any>;
|
|
10
|
+
}>;
|
|
11
|
+
/**
|
|
12
|
+
* An optional fallback component to render while the dynamic component is loading.
|
|
13
|
+
*/
|
|
14
|
+
fallback?: typeof SvelteComponent<any>;
|
|
15
|
+
} | typeof SvelteComponent<any>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -3,9 +3,10 @@ import type { ApiVersion } from '../types/api-version';
|
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content';
|
|
4
4
|
import type { ComponentInfo } from '../types/components';
|
|
5
5
|
import type { Dictionary, Nullable } from '../types/typescript';
|
|
6
|
+
import type { ComponentReference } from './component-reference-types';
|
|
6
7
|
import type { ExtraContextTypes } from './extra-context-types';
|
|
7
8
|
export type RegisteredComponent = ComponentInfo & {
|
|
8
|
-
component:
|
|
9
|
+
component: ComponentReference;
|
|
9
10
|
};
|
|
10
11
|
export type RegisteredComponents = Dictionary<RegisteredComponent>;
|
|
11
12
|
export type BuilderRenderState = Record<string, unknown>;
|
|
@@ -21,4 +21,6 @@ import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-
|
|
|
21
21
|
* Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
|
|
22
22
|
* end up sending the server runtime code to the browser (most notably in dev mode).
|
|
23
23
|
*/
|
|
24
|
-
export const chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode(
|
|
24
|
+
export const chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
|
|
25
|
+
shouldLogWarning: true
|
|
26
|
+
}) ? runInBrowser(args) : evaluator(args);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { shouldForceBrowserRuntimeInNode } from '../should-force-browser-runtime-in-node';
|
|
1
2
|
/**
|
|
2
3
|
* This file:
|
|
3
4
|
* - imports `isolated-vm`, which can only be made from a file that never runs
|
|
@@ -23,6 +24,14 @@ import { setIvm } from './node-runtime';
|
|
|
23
24
|
* - Qwik's `entry.ssr.tsx` file
|
|
24
25
|
*/
|
|
25
26
|
export const initializeNodeRuntime = (args) => {
|
|
27
|
+
/**
|
|
28
|
+
* skip initialization if we are on an arm64 machine and running node 20
|
|
29
|
+
*/
|
|
30
|
+
if (shouldForceBrowserRuntimeInNode({
|
|
31
|
+
shouldLogWarning: true
|
|
32
|
+
})) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
26
35
|
const { ivmIsolateOptions } = args || {};
|
|
27
36
|
setIvm(ivm, ivmIsolateOptions);
|
|
28
37
|
};
|
|
@@ -67,7 +67,7 @@ export const setIvm = (ivm, options = {}) => {
|
|
|
67
67
|
setIsolateContext(options);
|
|
68
68
|
};
|
|
69
69
|
// only mention the script for SDKs that have it.
|
|
70
|
-
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik';
|
|
70
|
+
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik' || SDK_NAME === '@builder.io/sdk-vue';
|
|
71
71
|
const getIvm = () => {
|
|
72
72
|
try {
|
|
73
73
|
if (IVM_INSTANCE)
|
|
@@ -1,16 +1,18 @@
|
|
|
1
1
|
import { logger } from '../../helpers/logger';
|
|
2
2
|
import { isNodeRuntime } from '../is-node-runtime';
|
|
3
|
-
export const shouldForceBrowserRuntimeInNode = () => {
|
|
3
|
+
export const shouldForceBrowserRuntimeInNode = ({ shouldLogWarning }) => {
|
|
4
4
|
if (!isNodeRuntime())
|
|
5
5
|
return false;
|
|
6
6
|
const isArm64 = process.arch === 'arm64';
|
|
7
7
|
const isNode20 = process.version.startsWith('v20');
|
|
8
8
|
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes('--no-node-snapshot');
|
|
9
9
|
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
10
|
-
|
|
10
|
+
if (shouldLogWarning) {
|
|
11
|
+
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
11
12
|
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
12
13
|
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
13
14
|
`);
|
|
15
|
+
}
|
|
14
16
|
return true;
|
|
15
17
|
}
|
|
16
18
|
return false;
|
package/package.json
CHANGED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
export let load: () => Promise<any>;
|
|
3
|
+
export let fallback: any;
|
|
4
|
+
export let props: any;
|
|
5
|
+
export let attributes: any;
|
|
6
|
+
</script>
|
|
7
|
+
|
|
8
|
+
{#await load()}
|
|
9
|
+
{#if fallback}
|
|
10
|
+
<svelte:component this={fallback} />
|
|
11
|
+
{/if}
|
|
12
|
+
{:then { default: Component }}
|
|
13
|
+
<svelte:component
|
|
14
|
+
this={Component}
|
|
15
|
+
{...props}
|
|
16
|
+
attributes={attributes}
|
|
17
|
+
>
|
|
18
|
+
<slot />
|
|
19
|
+
</svelte:component>
|
|
20
|
+
{/await}
|
|
@@ -15,13 +15,14 @@
|
|
|
15
15
|
import { getBlockProperties } from "../../../functions/get-block-properties";
|
|
16
16
|
import type { BuilderBlock } from "../../../types/builder-block";
|
|
17
17
|
import type { Dictionary } from "../../../types/typescript";
|
|
18
|
+
import Awaiter from "../../awaiter.svelte";
|
|
18
19
|
import type { Writable } from "svelte/store";
|
|
19
20
|
|
|
20
21
|
export let includeBlockProps: InteractiveElementProps["includeBlockProps"];
|
|
21
22
|
export let block: InteractiveElementProps["block"];
|
|
22
23
|
export let context: InteractiveElementProps["context"];
|
|
23
|
-
export let wrapperProps: InteractiveElementProps["wrapperProps"];
|
|
24
24
|
export let Wrapper: InteractiveElementProps["Wrapper"];
|
|
25
|
+
export let wrapperProps: InteractiveElementProps["wrapperProps"];
|
|
25
26
|
|
|
26
27
|
$: attributes = () => {
|
|
27
28
|
return includeBlockProps
|
|
@@ -42,6 +43,15 @@
|
|
|
42
43
|
};
|
|
43
44
|
</script>
|
|
44
45
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
{#if Wrapper.load}
|
|
47
|
+
<Awaiter
|
|
48
|
+
load={Wrapper.load}
|
|
49
|
+
fallback={Wrapper.fallback}
|
|
50
|
+
props={wrapperProps}
|
|
51
|
+
attributes={attributes()}><slot /></Awaiter
|
|
52
|
+
>
|
|
53
|
+
{:else}
|
|
54
|
+
<svelte:component this={Wrapper} {...wrapperProps} attributes={attributes()}
|
|
55
|
+
><slot /></svelte:component
|
|
56
|
+
>
|
|
57
|
+
{/if}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "2.0.
|
|
1
|
+
export const SDK_VERSION = "2.0.18"
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { SvelteComponent } from 'svelte';
|
|
2
|
+
|
|
3
|
+
export type ComponentReference =
|
|
4
|
+
| {
|
|
5
|
+
/**
|
|
6
|
+
* A dynamic import function pointing to the component.
|
|
7
|
+
* Example: `() => import('../components/my-component.svelte')`
|
|
8
|
+
* @returns A Promise that resolves to the loaded component.
|
|
9
|
+
*/
|
|
10
|
+
load: () => Promise<{ default: typeof SvelteComponent<any> }>;
|
|
11
|
+
/**
|
|
12
|
+
* An optional fallback component to render while the dynamic component is loading.
|
|
13
|
+
*/
|
|
14
|
+
fallback?: typeof SvelteComponent<any>;
|
|
15
|
+
}
|
|
16
|
+
| typeof SvelteComponent<any>;
|
package/src/context/types.ts
CHANGED
|
@@ -3,9 +3,10 @@ import type { ApiVersion } from '../types/api-version';
|
|
|
3
3
|
import type { BuilderContent } from '../types/builder-content';
|
|
4
4
|
import type { ComponentInfo } from '../types/components';
|
|
5
5
|
import type { Dictionary, Nullable } from '../types/typescript';
|
|
6
|
+
import type { ComponentReference } from './component-reference-types';
|
|
6
7
|
import type { ExtraContextTypes } from './extra-context-types';
|
|
7
8
|
export type RegisteredComponent = ComponentInfo & {
|
|
8
|
-
component:
|
|
9
|
+
component: ComponentReference;
|
|
9
10
|
};
|
|
10
11
|
export type RegisteredComponents = Dictionary<RegisteredComponent>;
|
|
11
12
|
export type BuilderRenderState = Record<string, unknown>;
|
|
@@ -24,4 +24,6 @@ import { shouldForceBrowserRuntimeInNode } from './should-force-browser-runtime-
|
|
|
24
24
|
* Even though we have separate runtimes for browser/node/edge, sometimes frameworks will
|
|
25
25
|
* end up sending the server runtime code to the browser (most notably in dev mode).
|
|
26
26
|
*/
|
|
27
|
-
export const chooseBrowserOrServerEval = (args: ExecutorArgs) => isBrowser() || shouldForceBrowserRuntimeInNode(
|
|
27
|
+
export const chooseBrowserOrServerEval = (args: ExecutorArgs) => isBrowser() || shouldForceBrowserRuntimeInNode({
|
|
28
|
+
shouldLogWarning: true
|
|
29
|
+
}) ? runInBrowser(args) : evaluator(args)
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { shouldForceBrowserRuntimeInNode } from '../should-force-browser-runtime-in-node';
|
|
1
2
|
/**
|
|
2
3
|
* This file:
|
|
3
4
|
* - imports `isolated-vm`, which can only be made from a file that never runs
|
|
@@ -27,6 +28,14 @@ import type { IsolateOptions } from 'isolated-vm';
|
|
|
27
28
|
export const initializeNodeRuntime = (args?: {
|
|
28
29
|
ivmIsolateOptions?: IsolateOptions;
|
|
29
30
|
}) => {
|
|
31
|
+
/**
|
|
32
|
+
* skip initialization if we are on an arm64 machine and running node 20
|
|
33
|
+
*/
|
|
34
|
+
if (shouldForceBrowserRuntimeInNode({
|
|
35
|
+
shouldLogWarning: true
|
|
36
|
+
})) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
30
39
|
const {
|
|
31
40
|
ivmIsolateOptions
|
|
32
41
|
} = args || {};
|
|
@@ -80,7 +80,7 @@ export const setIvm = (ivm: IsolatedVMImport, options: IsolateOptions = {}) => {
|
|
|
80
80
|
};
|
|
81
81
|
|
|
82
82
|
// only mention the script for SDKs that have it.
|
|
83
|
-
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik';
|
|
83
|
+
const SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === '@builder.io/sdk-react-nextjs' || SDK_NAME === '@builder.io/sdk-react' || SDK_NAME === '@builder.io/sdk-qwik' || SDK_NAME === '@builder.io/sdk-vue';
|
|
84
84
|
const getIvm = (): IsolatedVMImport => {
|
|
85
85
|
try {
|
|
86
86
|
if (IVM_INSTANCE) return IVM_INSTANCE;
|
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
import { logger } from '../../helpers/logger';
|
|
2
2
|
import { isNodeRuntime } from '../is-node-runtime';
|
|
3
|
-
export const shouldForceBrowserRuntimeInNode = (
|
|
3
|
+
export const shouldForceBrowserRuntimeInNode = ({
|
|
4
|
+
shouldLogWarning
|
|
5
|
+
}: {
|
|
6
|
+
shouldLogWarning: boolean;
|
|
7
|
+
}) => {
|
|
4
8
|
if (!isNodeRuntime()) return false;
|
|
5
9
|
const isArm64 = process.arch === 'arm64';
|
|
6
10
|
const isNode20 = process.version.startsWith('v20');
|
|
7
11
|
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes('--no-node-snapshot');
|
|
8
12
|
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
9
|
-
|
|
13
|
+
if (shouldLogWarning) {
|
|
14
|
+
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
10
15
|
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
11
16
|
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
12
17
|
`);
|
|
18
|
+
}
|
|
13
19
|
return true;
|
|
14
20
|
}
|
|
15
21
|
return false;
|