@webstudio-is/react-sdk 0.96.0 → 0.97.0
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/index.js
CHANGED
|
@@ -23,8 +23,9 @@ import {
|
|
|
23
23
|
import { atom } from "nanostores";
|
|
24
24
|
import { createContext } from "react";
|
|
25
25
|
var ReactSdkContext = createContext({
|
|
26
|
-
imageBaseUrl: "/",
|
|
27
26
|
assetBaseUrl: "/",
|
|
27
|
+
imageBaseUrl: "/",
|
|
28
|
+
imageLoader: ({ src }) => src,
|
|
28
29
|
propsByInstanceIdStore: atom(/* @__PURE__ */ new Map()),
|
|
29
30
|
assetsStore: atom(/* @__PURE__ */ new Map()),
|
|
30
31
|
pagesStore: atom(/* @__PURE__ */ new Map()),
|
|
@@ -45,8 +46,9 @@ var ReactSdkContext = createContext({
|
|
|
45
46
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
46
47
|
var createElementsTree = ({
|
|
47
48
|
renderer,
|
|
48
|
-
imageBaseUrl,
|
|
49
49
|
assetBaseUrl,
|
|
50
|
+
imageBaseUrl,
|
|
51
|
+
imageLoader,
|
|
50
52
|
instances,
|
|
51
53
|
rootInstanceId,
|
|
52
54
|
propsByInstanceIdStore,
|
|
@@ -93,8 +95,9 @@ var createElementsTree = ({
|
|
|
93
95
|
pagesStore,
|
|
94
96
|
dataSourceValuesStore,
|
|
95
97
|
renderer,
|
|
96
|
-
|
|
98
|
+
imageLoader,
|
|
97
99
|
assetBaseUrl,
|
|
100
|
+
imageBaseUrl,
|
|
98
101
|
indexesWithinAncestors,
|
|
99
102
|
executeEffectfulExpression: executeEffectfulExpression2,
|
|
100
103
|
setDataSourceValues: onDataSourceUpdate,
|
|
@@ -424,7 +427,8 @@ var InstanceRoot = ({
|
|
|
424
427
|
utils,
|
|
425
428
|
Component,
|
|
426
429
|
components,
|
|
427
|
-
scripts
|
|
430
|
+
scripts,
|
|
431
|
+
imageLoader
|
|
428
432
|
}) => {
|
|
429
433
|
const {
|
|
430
434
|
indexesWithinAncestors,
|
|
@@ -472,6 +476,7 @@ var InstanceRoot = ({
|
|
|
472
476
|
[dataSourceVariablesStore]
|
|
473
477
|
);
|
|
474
478
|
return createElementsTree({
|
|
479
|
+
imageLoader,
|
|
475
480
|
imageBaseUrl: data.params?.imageBaseUrl ?? "/",
|
|
476
481
|
assetBaseUrl: data.params?.assetBaseUrl ?? "/",
|
|
477
482
|
instances: new Map(data.build.instances),
|
|
@@ -1571,7 +1576,8 @@ var renderComponentTemplate = ({
|
|
|
1571
1576
|
name,
|
|
1572
1577
|
metas: metasRecord,
|
|
1573
1578
|
components,
|
|
1574
|
-
props
|
|
1579
|
+
props,
|
|
1580
|
+
imageLoader
|
|
1575
1581
|
}) => {
|
|
1576
1582
|
const metas = new Map(Object.entries(metasRecord));
|
|
1577
1583
|
const template = metas.get(name)?.template ?? [
|
|
@@ -1675,7 +1681,8 @@ var renderComponentTemplate = ({
|
|
|
1675
1681
|
}
|
|
1676
1682
|
},
|
|
1677
1683
|
Component: WebstudioComponent,
|
|
1678
|
-
components: new Map(Object.entries(components))
|
|
1684
|
+
components: new Map(Object.entries(components)),
|
|
1685
|
+
imageLoader: imageLoader ?? (({ src }) => src)
|
|
1679
1686
|
}
|
|
1680
1687
|
)
|
|
1681
1688
|
] });
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { ExoticComponent } from "react";
|
|
2
2
|
import type { Instance } from "@webstudio-is/sdk";
|
|
3
3
|
import type { WsComponentMeta } from "./components/component-meta";
|
|
4
|
-
|
|
4
|
+
import type { ImageLoader } from "@webstudio-is/image";
|
|
5
|
+
export declare const renderComponentTemplate: ({ name, metas: metasRecord, components, props, imageLoader, }: {
|
|
5
6
|
name: Instance["component"];
|
|
6
7
|
metas: Record<string, WsComponentMeta>;
|
|
7
8
|
props?: Record<string, unknown> | undefined;
|
|
8
9
|
components: Record<string, ExoticComponent<any>>;
|
|
10
|
+
imageLoader?: ImageLoader | undefined;
|
|
9
11
|
}) => import("react/jsx-runtime").JSX.Element;
|
package/lib/types/context.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { type ReadableAtom } from "nanostores";
|
|
|
3
3
|
import type { DataSource, Instance, Prop, Assets } from "@webstudio-is/sdk";
|
|
4
4
|
import type { Pages, PropsByInstanceId } from "./props";
|
|
5
5
|
import type { IndexesWithinAncestors } from "./instance-utils";
|
|
6
|
+
import type { ImageLoader } from "@webstudio-is/image";
|
|
6
7
|
export type Params = {
|
|
7
8
|
renderer?: "canvas" | "preview";
|
|
8
9
|
/**
|
|
@@ -31,6 +32,7 @@ export type Params = {
|
|
|
31
32
|
};
|
|
32
33
|
export type DataSourceValues = Map<DataSource["id"], unknown>;
|
|
33
34
|
export declare const ReactSdkContext: import("react").Context<Params & {
|
|
35
|
+
imageLoader: ImageLoader;
|
|
34
36
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
35
37
|
assetsStore: ReadableAtom<Assets>;
|
|
36
38
|
pagesStore: ReadableAtom<Pages>;
|
|
@@ -6,7 +6,8 @@ import { type Params, type DataSourceValues } from "../context";
|
|
|
6
6
|
import type { Pages, PropsByInstanceId } from "../props";
|
|
7
7
|
import type { WebstudioComponentProps } from "./webstudio-component";
|
|
8
8
|
import type { IndexesWithinAncestors } from "../instance-utils";
|
|
9
|
-
|
|
9
|
+
import type { ImageLoader } from "@webstudio-is/image";
|
|
10
|
+
export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl, imageLoader, instances, rootInstanceId, propsByInstanceIdStore, assetsStore, pagesStore, dataSourceValuesStore, executeEffectfulExpression, onDataSourceUpdate, indexesWithinAncestors, Component, components, scripts, }: Params & {
|
|
10
11
|
instances: Map<string, {
|
|
11
12
|
type: "instance";
|
|
12
13
|
id: string;
|
|
@@ -20,6 +21,7 @@ export declare const createElementsTree: ({ renderer, imageBaseUrl, assetBaseUrl
|
|
|
20
21
|
})[];
|
|
21
22
|
label?: string | undefined;
|
|
22
23
|
}>;
|
|
24
|
+
imageLoader: ImageLoader;
|
|
23
25
|
rootInstanceId: Instance["id"];
|
|
24
26
|
propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
|
|
25
27
|
assetsStore: ReadableAtom<Assets>;
|
package/lib/types/tree/root.d.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { type WebstudioComponentProps } from "./webstudio-component";
|
|
|
4
4
|
import type { Components } from "../components/components-utils";
|
|
5
5
|
import type { Params } from "../context";
|
|
6
6
|
import type { GeneratedUtils } from "../generator";
|
|
7
|
+
import type { ImageLoader } from "@webstudio-is/image";
|
|
7
8
|
export type RootPropsData = {
|
|
8
9
|
params?: Params;
|
|
9
10
|
page: Page;
|
|
@@ -21,6 +22,7 @@ type RootProps = {
|
|
|
21
22
|
Component?: ForwardRefExoticComponent<WebstudioComponentProps & RefAttributes<HTMLElement>>;
|
|
22
23
|
components: Components;
|
|
23
24
|
scripts?: ReactNode;
|
|
25
|
+
imageLoader: ImageLoader;
|
|
24
26
|
};
|
|
25
|
-
export declare const InstanceRoot: ({ data, utils, Component, components, scripts, }: RootProps) => JSX.Element | null;
|
|
27
|
+
export declare const InstanceRoot: ({ data, utils, Component, components, scripts, imageLoader, }: RootProps) => JSX.Element | null;
|
|
26
28
|
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.97.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"nanostores": "^0.9.3",
|
|
35
35
|
"no-case": "^3.0.4",
|
|
36
36
|
"title-case": "^3.0.3",
|
|
37
|
-
"@webstudio-is/css-engine": "^0.
|
|
38
|
-
"@webstudio-is/fonts": "^0.
|
|
39
|
-
"@webstudio-is/
|
|
37
|
+
"@webstudio-is/css-engine": "^0.97.0",
|
|
38
|
+
"@webstudio-is/fonts": "^0.97.0",
|
|
39
|
+
"@webstudio-is/image": "^0.97.0",
|
|
40
|
+
"@webstudio-is/sdk": "^0.97.0"
|
|
40
41
|
},
|
|
41
42
|
"exports": {
|
|
42
43
|
".": {
|