@webstudio-is/react-sdk 0.0.0-588fe22 → 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/runtime.js CHANGED
@@ -7,7 +7,12 @@ import {
7
7
  var ReactSdkContext = createContext({
8
8
  assetBaseUrl: "/",
9
9
  imageLoader: ({ src }) => src,
10
- resources: {}
10
+ videoLoader: ({ src }) => src,
11
+ resources: {},
12
+ breakpoints: [],
13
+ onError: (error) => {
14
+ console.error(error);
15
+ }
11
16
  });
12
17
  var useResource = (name) => {
13
18
  const { resources } = useContext(ReactSdkContext);
@@ -18,6 +23,9 @@ var useResource = (name) => {
18
23
  );
19
24
  return resourceMemozied;
20
25
  };
26
+ var renderText = (value) => {
27
+ return typeof value === "string" || typeof value === "number" ? value : "";
28
+ };
21
29
 
22
30
  // src/hook.ts
23
31
  var getClosestInstance = (instancePath, currentInstance, closestComponent) => {
@@ -82,7 +90,8 @@ var PageSettingsMeta = ({
82
90
  host,
83
91
  siteName,
84
92
  pageMeta,
85
- imageLoader
93
+ imageLoader,
94
+ assetBaseUrl
86
95
  }) => {
87
96
  const metas = [];
88
97
  if (url !== void 0) {
@@ -121,10 +130,11 @@ var PageSettingsMeta = ({
121
130
  });
122
131
  }
123
132
  if (pageMeta.socialImageAssetName) {
133
+ const origin = host ? `https://${host}` : "";
124
134
  metas.push({
125
135
  property: "og:image",
126
- content: `https://${host}${imageLoader({
127
- src: pageMeta.socialImageAssetName,
136
+ content: `${origin}${imageLoader({
137
+ src: `${assetBaseUrl}${pageMeta.socialImageAssetName}`,
128
138
  // Do not transform social image (not enough information do we need to do this)
129
139
  format: "raw"
130
140
  })}`
@@ -136,6 +146,12 @@ var PageSettingsMeta = ({
136
146
  });
137
147
  }
138
148
  metas.push(...pageMeta.custom);
149
+ const isTwitterCardSizeDefined = pageMeta.custom.some(
150
+ (meta) => meta.property === "twitter:card"
151
+ );
152
+ if ((pageMeta.socialImageAssetName !== void 0 || pageMeta.socialImageUrl !== void 0) && isTwitterCardSizeDefined === false) {
153
+ metas.push({ property: "twitter:card", content: "summary_large_image" });
154
+ }
139
155
  return metas.map((meta, index) => /* @__PURE__ */ jsx(Meta, { ...meta }, index));
140
156
  };
141
157
 
@@ -197,16 +213,13 @@ var PageSettingsCanonicalLink = (props) => {
197
213
 
198
214
  // src/runtime.ts
199
215
  var xmlNodeTagSuffix = "-ws-xml-node-fb77f896-8e96-40b9-b8f8-90a4e70d724a";
200
- var getIndexWithinAncestorFromComponentProps = (props) => {
201
- return props["data-ws-index"];
202
- };
203
216
  export {
204
217
  PageSettingsCanonicalLink,
205
218
  PageSettingsMeta,
206
219
  PageSettingsTitle,
207
220
  ReactSdkContext,
208
221
  getClosestInstance,
209
- getIndexWithinAncestorFromComponentProps,
222
+ renderText,
210
223
  useResource,
211
224
  useVariableState,
212
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,28 +1,52 @@
1
- import type { Instances, Instance, Props, Scope, DataSources, Prop } from "@webstudio-is/sdk";
2
- import type { IndexesWithinAncestors } from "./instance-utils";
3
- export declare const generateJsxElement: ({ context, scope, instance, props, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
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, }: {
4
14
  context?: "expression" | "jsx";
5
15
  scope: Scope;
16
+ metas: Map<Instance["component"], WsComponentMeta>;
17
+ /**
18
+ * Record<tag, componentDescriptor>
19
+ */
20
+ tagsOverrides?: Record<string, string>;
6
21
  instance: Instance;
7
22
  props: Props;
23
+ resources?: Resources;
8
24
  dataSources: DataSources;
9
25
  usedDataSources: DataSources;
10
26
  indexesWithinAncestors: IndexesWithinAncestors;
11
27
  children: string;
12
28
  classesMap?: Map<string, Array<string>>;
13
29
  }) => string;
14
- export declare const generateJsxChildren: ({ scope, 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, }: {
15
31
  scope: Scope;
32
+ metas: Map<Instance["component"], WsComponentMeta>;
33
+ tagsOverrides?: Record<string, string>;
16
34
  children: Instance["children"];
17
35
  instances: Instances;
18
36
  props: Props;
37
+ resources?: Resources;
19
38
  dataSources: DataSources;
20
39
  usedDataSources: DataSources;
21
40
  indexesWithinAncestors: IndexesWithinAncestors;
22
41
  classesMap?: Map<string, Array<string>>;
23
42
  excludePlaceholders?: boolean;
43
+ publishedContentBlocks?: ReadonlyMap<Instance["id"], PublishedContentBlock>;
44
+ contentBodyOverride?: Readonly<{
45
+ instanceId: Instance["id"];
46
+ children: Instance["children"];
47
+ }>;
24
48
  }) => string;
25
- export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, indexesWithinAncestors, classesMap, }: {
49
+ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, resources, dataSources, metas, tagsOverrides, classesMap, publishedContentBlocks, }: {
26
50
  scope: Scope;
27
51
  name: string;
28
52
  rootInstanceId: Instance["id"];
@@ -31,7 +55,13 @@ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId,
31
55
  }>[];
32
56
  instances: Instances;
33
57
  props: Props;
58
+ resources?: Resources;
34
59
  dataSources: DataSources;
35
- indexesWithinAncestors: IndexesWithinAncestors;
36
60
  classesMap: Map<string, Array<string>>;
61
+ publishedContentBlocks?: ReadonlyMap<Instance["id"], PublishedContentBlock>;
62
+ metas: Map<Instance["component"], WsComponentMeta>;
63
+ /**
64
+ * Record<tag, componentDescriptor>
65
+ */
66
+ tagsOverrides?: Record<string, string>;
37
67
  }) => string;
@@ -1,4 +1,4 @@
1
- import type { ImageLoader } from "@webstudio-is/image";
1
+ import type { ImageLoader, VideoLoader } from "@webstudio-is/image";
2
2
  export type Params = {
3
3
  /**
4
4
  * When rendering a published version, there is no renderer defined.
@@ -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,9 +24,19 @@ 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;
32
+ videoLoader?: VideoLoader;
24
33
  resources: Record<string, any>;
34
+ breakpoints: {
35
+ id: string;
36
+ minWidth?: number;
37
+ maxWidth?: number;
38
+ }[];
39
+ onError: (error: unknown) => void;
25
40
  }>;
26
41
  export declare const useResource: (name: string) => any;
42
+ export declare const renderText: (value: unknown) => string | number;
@@ -1,9 +1,9 @@
1
- import type { Instance, Prop } from "@webstudio-is/sdk";
2
- import type { IndexesWithinAncestors } from "./instance-utils";
1
+ import type { IndexesWithinAncestors, Instance, Prop } from "@webstudio-is/sdk";
3
2
  export type InstanceData = {
4
3
  id: Instance["id"];
5
4
  instanceKey: string;
6
5
  component: Instance["component"];
6
+ tag?: Instance["tag"];
7
7
  };
8
8
  /**
9
9
  * Hooks are subscriptions to builder events
@@ -1,9 +1,8 @@
1
1
  export * from "./remix";
2
- export * from "./css/index";
3
2
  export * from "./components/components-utils";
4
- export * from "./embed-template";
5
3
  export * from "./props";
4
+ export * from "./collection-utils";
6
5
  export type * from "./context";
7
- export { getIndexesWithinAncestors } from "./instance-utils";
8
6
  export type * from "./hook";
9
- export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, } from "./component-generator";
7
+ export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, type PublishedContentBlock, } from "./component-generator";
8
+ export * from "./standard-attributes";
@@ -1,10 +1,11 @@
1
1
  import type { ImageLoader } from "@webstudio-is/image";
2
2
  import type { PageMeta } from "@webstudio-is/sdk";
3
3
  export declare const isElementRenderedWithReact: (element: Element) => boolean;
4
- export declare const PageSettingsMeta: ({ url, host, siteName, pageMeta, imageLoader, }: {
4
+ export declare const PageSettingsMeta: ({ url, host, siteName, pageMeta, imageLoader, assetBaseUrl, }: {
5
5
  url?: string;
6
- host: string;
7
- siteName: string;
6
+ host?: string;
7
+ siteName?: string;
8
8
  pageMeta: PageMeta;
9
9
  imageLoader: ImageLoader;
10
+ assetBaseUrl: string;
10
11
  }) => import("react/jsx-runtime").JSX.Element[];