@webstudio-is/react-sdk 0.0.0-73cd6ea → 0.0.0-7a19155
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 +261 -257
- package/lib/runtime.js +6 -1
- package/lib/standard-attributes.js +13 -0
- package/lib/types/collection-utils.d.ts +24 -0
- package/lib/types/component-generator.d.ts +24 -4
- package/lib/types/context.d.ts +9 -0
- package/lib/types/index.d.ts +3 -2
- package/lib/types/page-settings-meta.d.ts +2 -2
- package/lib/types/props.d.ts +440 -416
- package/lib/types/standard-attributes.d.ts +1 -0
- package/package.json +20 -14
- package/placeholder.d.ts +21 -3
- package/lib/types/__generated__/standard-attributes.d.ts +0 -2
- package/lib/types/component-generator.test.d.ts +0 -1
- package/lib/types/hook.test.d.ts +0 -1
- package/lib/types/props.test.d.ts +0 -1
- package/lib/types/remix.test.d.ts +0 -1
package/lib/runtime.js
CHANGED
|
@@ -23,6 +23,9 @@ var useResource = (name) => {
|
|
|
23
23
|
);
|
|
24
24
|
return resourceMemozied;
|
|
25
25
|
};
|
|
26
|
+
var renderText = (value) => {
|
|
27
|
+
return typeof value === "string" || typeof value === "number" ? value : "";
|
|
28
|
+
};
|
|
26
29
|
|
|
27
30
|
// src/hook.ts
|
|
28
31
|
var getClosestInstance = (instancePath, currentInstance, closestComponent) => {
|
|
@@ -127,9 +130,10 @@ var PageSettingsMeta = ({
|
|
|
127
130
|
});
|
|
128
131
|
}
|
|
129
132
|
if (pageMeta.socialImageAssetName) {
|
|
133
|
+
const origin = host ? `https://${host}` : "";
|
|
130
134
|
metas.push({
|
|
131
135
|
property: "og:image",
|
|
132
|
-
content:
|
|
136
|
+
content: `${origin}${imageLoader({
|
|
133
137
|
src: `${assetBaseUrl}${pageMeta.socialImageAssetName}`,
|
|
134
138
|
// Do not transform social image (not enough information do we need to do this)
|
|
135
139
|
format: "raw"
|
|
@@ -215,6 +219,7 @@ export {
|
|
|
215
219
|
PageSettingsTitle,
|
|
216
220
|
ReactSdkContext,
|
|
217
221
|
getClosestInstance,
|
|
222
|
+
renderText,
|
|
218
223
|
useResource,
|
|
219
224
|
useVariableState,
|
|
220
225
|
xmlNodeTagSuffix
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/standard-attributes.ts
|
|
2
|
+
import {
|
|
3
|
+
getInstancePropName,
|
|
4
|
+
getJsxPropName,
|
|
5
|
+
reactPropsToStandardAttributes,
|
|
6
|
+
standardAttributesToReactProps
|
|
7
|
+
} from "@webstudio-is/content-engine/jsx-attributes";
|
|
8
|
+
export {
|
|
9
|
+
getInstancePropName,
|
|
10
|
+
getJsxPropName,
|
|
11
|
+
reactPropsToStandardAttributes,
|
|
12
|
+
standardAttributesToReactProps
|
|
13
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared collection iteration logic for both builder and published sites.
|
|
3
|
+
*
|
|
4
|
+
* Collections support both arrays and objects:
|
|
5
|
+
* - Arrays: [item1, item2] -> entries are [["0", item1], ["1", item2]]
|
|
6
|
+
* - Objects: {key1: val1, key2: val2} -> entries are [["key1", val1], ["key2", val2]]
|
|
7
|
+
*
|
|
8
|
+
* Using Object.entries() unifies both cases since arrays are objects with numeric keys.
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* Normalize collection data to entries format [key, value][].
|
|
12
|
+
* Returns empty array if data is not iterable.
|
|
13
|
+
* For arrays, keys are converted to numbers.
|
|
14
|
+
*/
|
|
15
|
+
export declare const getCollectionEntries: (data: unknown) => Array<[string | number, unknown]>;
|
|
16
|
+
/**
|
|
17
|
+
* Template for generated code that iterates over collections.
|
|
18
|
+
* Used by component-generator.ts to ensure consistency.
|
|
19
|
+
*/
|
|
20
|
+
export declare const generateCollectionIterationCode: ({ dataExpression, keyVariable, itemVariable, }: {
|
|
21
|
+
dataExpression: string;
|
|
22
|
+
keyVariable: string;
|
|
23
|
+
itemVariable: string;
|
|
24
|
+
}) => string;
|
|
@@ -1,5 +1,16 @@
|
|
|
1
|
-
import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors } from "@webstudio-is/sdk";
|
|
2
|
-
export
|
|
1
|
+
import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors, Resources } from "@webstudio-is/sdk";
|
|
2
|
+
export type PublishedContentBlock = Readonly<{
|
|
3
|
+
bodyInstanceId?: Instance["id"];
|
|
4
|
+
sourceExpression?: string;
|
|
5
|
+
candidates: readonly Readonly<{
|
|
6
|
+
assetId: string;
|
|
7
|
+
dependencyRevision: string;
|
|
8
|
+
children: Instance["children"];
|
|
9
|
+
frontmatter: Readonly<Record<string, unknown>>;
|
|
10
|
+
resourceIds?: readonly string[];
|
|
11
|
+
}>[];
|
|
12
|
+
}>;
|
|
13
|
+
export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides, instance, props, resources, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
|
|
3
14
|
context?: "expression" | "jsx";
|
|
4
15
|
scope: Scope;
|
|
5
16
|
metas: Map<Instance["component"], WsComponentMeta>;
|
|
@@ -9,26 +20,33 @@ export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides
|
|
|
9
20
|
tagsOverrides?: Record<string, string>;
|
|
10
21
|
instance: Instance;
|
|
11
22
|
props: Props;
|
|
23
|
+
resources?: Resources;
|
|
12
24
|
dataSources: DataSources;
|
|
13
25
|
usedDataSources: DataSources;
|
|
14
26
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
15
27
|
children: string;
|
|
16
28
|
classesMap?: Map<string, Array<string>>;
|
|
17
29
|
}) => string;
|
|
18
|
-
export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, }: {
|
|
30
|
+
export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, resources, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, publishedContentBlocks, contentBodyOverride, }: {
|
|
19
31
|
scope: Scope;
|
|
20
32
|
metas: Map<Instance["component"], WsComponentMeta>;
|
|
21
33
|
tagsOverrides?: Record<string, string>;
|
|
22
34
|
children: Instance["children"];
|
|
23
35
|
instances: Instances;
|
|
24
36
|
props: Props;
|
|
37
|
+
resources?: Resources;
|
|
25
38
|
dataSources: DataSources;
|
|
26
39
|
usedDataSources: DataSources;
|
|
27
40
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
28
41
|
classesMap?: Map<string, Array<string>>;
|
|
29
42
|
excludePlaceholders?: boolean;
|
|
43
|
+
publishedContentBlocks?: ReadonlyMap<Instance["id"], PublishedContentBlock>;
|
|
44
|
+
contentBodyOverride?: Readonly<{
|
|
45
|
+
instanceId: Instance["id"];
|
|
46
|
+
children: Instance["children"];
|
|
47
|
+
}>;
|
|
30
48
|
}) => string;
|
|
31
|
-
export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, metas, tagsOverrides, classesMap, }: {
|
|
49
|
+
export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, resources, dataSources, metas, tagsOverrides, classesMap, publishedContentBlocks, }: {
|
|
32
50
|
scope: Scope;
|
|
33
51
|
name: string;
|
|
34
52
|
rootInstanceId: Instance["id"];
|
|
@@ -37,8 +55,10 @@ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId,
|
|
|
37
55
|
}>[];
|
|
38
56
|
instances: Instances;
|
|
39
57
|
props: Props;
|
|
58
|
+
resources?: Resources;
|
|
40
59
|
dataSources: DataSources;
|
|
41
60
|
classesMap: Map<string, Array<string>>;
|
|
61
|
+
publishedContentBlocks?: ReadonlyMap<Instance["id"], PublishedContentBlock>;
|
|
42
62
|
metas: Map<Instance["component"], WsComponentMeta>;
|
|
43
63
|
/**
|
|
44
64
|
* Record<tag, componentDescriptor>
|
package/lib/types/context.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ export type Params = {
|
|
|
6
6
|
* - preview is the preview mode in builder
|
|
7
7
|
*/
|
|
8
8
|
renderer?: "canvas" | "preview";
|
|
9
|
+
/**
|
|
10
|
+
* Safe mode prevents external JavaScript execution in HTML embeds.
|
|
11
|
+
* When enabled, all HTML embeds act as if "run scripts on canvas" is false,
|
|
12
|
+
* regardless of their actual settings.
|
|
13
|
+
*/
|
|
14
|
+
isSafeMode?: boolean;
|
|
9
15
|
/**
|
|
10
16
|
* Base url or base path for any asset with ending slash.
|
|
11
17
|
* Used to load assets like fonts or images in styles
|
|
@@ -18,6 +24,8 @@ export type Params = {
|
|
|
18
24
|
* https://assets.webstudio.is/
|
|
19
25
|
*/
|
|
20
26
|
assetBaseUrl: string;
|
|
27
|
+
/** Runtime URLs keyed by their root-relative path in the Assets panel. */
|
|
28
|
+
assetUrlsByPath?: Readonly<Record<string, string>>;
|
|
21
29
|
};
|
|
22
30
|
export declare const ReactSdkContext: import("react").Context<Params & {
|
|
23
31
|
imageLoader: ImageLoader;
|
|
@@ -31,3 +39,4 @@ export declare const ReactSdkContext: import("react").Context<Params & {
|
|
|
31
39
|
onError: (error: unknown) => void;
|
|
32
40
|
}>;
|
|
33
41
|
export declare const useResource: (name: string) => any;
|
|
42
|
+
export declare const renderText: (value: unknown) => string | number;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
export * from "./remix";
|
|
2
2
|
export * from "./components/components-utils";
|
|
3
3
|
export * from "./props";
|
|
4
|
+
export * from "./collection-utils";
|
|
4
5
|
export type * from "./context";
|
|
5
6
|
export type * from "./hook";
|
|
6
|
-
export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, } from "./component-generator";
|
|
7
|
-
export * from "./
|
|
7
|
+
export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, type PublishedContentBlock, } from "./component-generator";
|
|
8
|
+
export * from "./standard-attributes";
|
|
@@ -3,8 +3,8 @@ import type { PageMeta } from "@webstudio-is/sdk";
|
|
|
3
3
|
export declare const isElementRenderedWithReact: (element: Element) => boolean;
|
|
4
4
|
export declare const PageSettingsMeta: ({ url, host, siteName, pageMeta, imageLoader, assetBaseUrl, }: {
|
|
5
5
|
url?: string;
|
|
6
|
-
host
|
|
7
|
-
siteName
|
|
6
|
+
host?: string;
|
|
7
|
+
siteName?: string;
|
|
8
8
|
pageMeta: PageMeta;
|
|
9
9
|
imageLoader: ImageLoader;
|
|
10
10
|
assetBaseUrl: string;
|