@webstudio-is/react-sdk 0.125.0 → 0.126.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
@@ -69,6 +69,10 @@ var addGlobalRules = (sheet, { assets, assetBaseUrl }) => {
69
69
  };
70
70
 
71
71
  // src/props.ts
72
+ import {
73
+ getPagePath,
74
+ findPageByIdOrPath
75
+ } from "@webstudio-is/sdk";
72
76
  var normalizeProps = ({
73
77
  props,
74
78
  assetBaseUrl,
@@ -94,22 +98,20 @@ var normalizeProps = ({
94
98
  continue;
95
99
  }
96
100
  if (prop.type === "page") {
97
- let page;
98
101
  let idProp;
99
- if (typeof prop.value === "string") {
100
- const pageId = prop.value;
101
- page = pages.get(pageId);
102
- } else {
103
- const { pageId, instanceId } = prop.value;
104
- page = pages.get(pageId);
102
+ const pageId = typeof prop.value === "string" ? prop.value : prop.value.pageId;
103
+ const page = findPageByIdOrPath(pageId, pages);
104
+ if (page === void 0) {
105
+ continue;
106
+ }
107
+ if (typeof prop.value !== "string") {
108
+ const { instanceId } = prop.value;
105
109
  idProp = props.find(
106
110
  (prop2) => prop2.instanceId === instanceId && prop2.name === "id"
107
111
  );
108
112
  }
109
- if (page === void 0) {
110
- continue;
111
- }
112
- const url = new URL(page.path, "https://any-valid.url");
113
+ const path = getPagePath(page.id, pages);
114
+ const url = new URL(path, "https://any-valid.url");
113
115
  let value = url.pathname;
114
116
  if (idProp?.type === "string") {
115
117
  const hash = idProp.value;
@@ -286,13 +288,18 @@ import {
286
288
  } from "react";
287
289
 
288
290
  // src/context.tsx
289
- import { createContext } from "react";
291
+ import { createContext, useContext } from "react";
290
292
  var ReactSdkContext = createContext({
291
293
  assetBaseUrl: "/",
292
294
  imageBaseUrl: "/",
293
295
  imageLoader: ({ src }) => src,
294
- pagesPaths: /* @__PURE__ */ new Set()
296
+ pagesPaths: /* @__PURE__ */ new Set(),
297
+ resources: {}
295
298
  });
299
+ var useResource = (name) => {
300
+ const { resources } = useContext(ReactSdkContext);
301
+ return resources[name];
302
+ };
296
303
 
297
304
  // src/tree/create-elements-tree.tsx
298
305
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -325,7 +332,8 @@ var createElementsTree = ({
325
332
  imageLoader,
326
333
  pagesPaths: /* @__PURE__ */ new Set(),
327
334
  assetBaseUrl,
328
- imageBaseUrl
335
+ imageBaseUrl,
336
+ resources: {}
329
337
  },
330
338
  children: root
331
339
  }
@@ -415,7 +423,7 @@ import { ListViewIcon } from "@webstudio-is/icons/svg";
415
423
  var portalComponent = "Slot";
416
424
  var collectionComponent = "ws:collection";
417
425
  var collectionMeta = {
418
- category: "general",
426
+ category: "data",
419
427
  order: 7,
420
428
  type: "container",
421
429
  label: "Collection",
@@ -429,24 +437,24 @@ var collectionMeta = {
429
437
  {
430
438
  name: "data",
431
439
  type: "json",
432
- value: ["apple", "orange", "banana"]
440
+ value: [
441
+ "Collection Item 1",
442
+ "Collection Item 2",
443
+ "Collection Item 3"
444
+ ]
433
445
  },
434
- { name: "item", type: "parameter", variableName: "collectionItem" }
446
+ {
447
+ name: "item",
448
+ type: "parameter",
449
+ variableName: "collectionItem",
450
+ variableAlias: "Collection Item"
451
+ }
435
452
  ],
436
453
  children: [
437
454
  {
438
455
  type: "instance",
439
456
  component: "Box",
440
- children: [
441
- {
442
- type: "instance",
443
- component: "HtmlEmbed",
444
- props: [
445
- { name: "code", type: "expression", code: "collectionItem" }
446
- ],
447
- children: []
448
- }
449
- ]
457
+ children: [{ type: "expression", value: "collectionItem" }]
450
458
  }
451
459
  ]
452
460
  }
@@ -876,7 +884,12 @@ var EmbedTemplateText = z2.object({
876
884
  type: z2.literal("text"),
877
885
  value: z2.string()
878
886
  });
887
+ var EmbedTemplateExpression = z2.object({
888
+ type: z2.literal("expression"),
889
+ value: z2.string()
890
+ });
879
891
  var EmbedTemplateVariable = z2.object({
892
+ alias: z2.optional(z2.string()),
880
893
  initialValue: z2.unknown()
881
894
  });
882
895
  var EmbedTemplateProp = z2.union([
@@ -913,7 +926,8 @@ var EmbedTemplateProp = z2.union([
913
926
  z2.object({
914
927
  type: z2.literal("parameter"),
915
928
  name: z2.string(),
916
- variableName: z2.string()
929
+ variableName: z2.string(),
930
+ variableAlias: z2.optional(z2.string())
917
931
  }),
918
932
  z2.object({
919
933
  type: z2.literal("action"),
@@ -947,7 +961,9 @@ var EmbedTemplateInstance = z2.lazy(
947
961
  })
948
962
  );
949
963
  var WsEmbedTemplate = z2.lazy(
950
- () => z2.array(z2.union([EmbedTemplateInstance, EmbedTemplateText]))
964
+ () => z2.array(
965
+ z2.union([EmbedTemplateInstance, EmbedTemplateText, EmbedTemplateExpression])
966
+ )
951
967
  );
952
968
  var getVariablValue = (value) => {
953
969
  if (typeof value === "string") {
@@ -978,7 +994,7 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
978
994
  type: "variable",
979
995
  id: generateId(),
980
996
  scopeInstanceId: instanceId,
981
- name,
997
+ name: variable.alias ?? name,
982
998
  value: getVariablValue(variable.initialValue)
983
999
  });
984
1000
  }
@@ -1035,7 +1051,7 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
1035
1051
  type: "parameter",
1036
1052
  id: dataSourceId,
1037
1053
  scopeInstanceId: instanceId,
1038
- name: prop.variableName
1054
+ name: prop.variableAlias ?? prop.variableName
1039
1055
  });
1040
1056
  props.push({
1041
1057
  id: propId,
@@ -1131,6 +1147,18 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
1131
1147
  value: item.value
1132
1148
  });
1133
1149
  }
1150
+ if (item.type === "expression") {
1151
+ parentChildren.push({
1152
+ type: "expression",
1153
+ // replace all references with variable names
1154
+ value: validateExpression(item.value, {
1155
+ transformIdentifier: (ref) => {
1156
+ const id = dataSourceByRef.get(ref)?.id ?? ref;
1157
+ return encodeDataSourceVariable(id);
1158
+ }
1159
+ })
1160
+ });
1161
+ }
1134
1162
  }
1135
1163
  return parentChildren;
1136
1164
  };
@@ -1160,7 +1188,10 @@ var generateDataFromEmbedTemplate = (treeTemplate, metas, defaultBreakpointId, g
1160
1188
  dataSources: Array.from(dataSourceByRef.values()),
1161
1189
  styleSourceSelections,
1162
1190
  styleSources,
1163
- styles
1191
+ styles,
1192
+ assets: [],
1193
+ breakpoints: [],
1194
+ resources: []
1164
1195
  };
1165
1196
  };
1166
1197
  var namespaceEmbedTemplateComponents = (template, namespace, components) => {
@@ -1168,6 +1199,9 @@ var namespaceEmbedTemplateComponents = (template, namespace, components) => {
1168
1199
  if (item.type === "text") {
1169
1200
  return item;
1170
1201
  }
1202
+ if (item.type === "expression") {
1203
+ return item;
1204
+ }
1171
1205
  if (item.type === "instance") {
1172
1206
  const prefix = components.has(item.component) ? `${namespace}:` : "";
1173
1207
  return {
@@ -1218,6 +1252,7 @@ var WsComponentPropsMeta = z3.object({
1218
1252
  var componentCategories = [
1219
1253
  "general",
1220
1254
  "text",
1255
+ "data",
1221
1256
  "media",
1222
1257
  "forms",
1223
1258
  "radix",
@@ -1329,10 +1364,12 @@ var getClosestInstance = (instancePath, currentInstance, closestComponent) => {
1329
1364
  };
1330
1365
 
1331
1366
  // src/generator.ts
1367
+ import { getPagePath as getPagePath2 } from "@webstudio-is/sdk";
1332
1368
  var generateUtilsExport = (siteData) => {
1333
1369
  const pagesPaths = [siteData.pages.homePage.path];
1334
1370
  for (const page of siteData.pages.pages) {
1335
- pagesPaths.push(page.path);
1371
+ const path = getPagePath2(page.id, siteData.pages);
1372
+ pagesPaths.push(path);
1336
1373
  }
1337
1374
  const generatedPagesPaths = `export const pagesPaths = new Set(${JSON.stringify(
1338
1375
  pagesPaths
@@ -1596,7 +1633,8 @@ var generatePageComponent = ({
1596
1633
  dataSource.resourceId,
1597
1634
  dataSource.name
1598
1635
  );
1599
- generatedDataSources += `let ${valueName}: any = _props.resources["${resourceName}"]
1636
+ const resourceNameString = JSON.stringify(resourceName);
1637
+ generatedDataSources += `let ${valueName} = useResource(${resourceNameString})
1600
1638
  `;
1601
1639
  }
1602
1640
  }
@@ -1621,9 +1659,7 @@ var generatePageComponent = ({
1621
1659
  let generatedComponent = "";
1622
1660
  generatedComponent += `type Params = Record<string, string | undefined>
1623
1661
  `;
1624
- generatedComponent += `type Resources = Record<string, unknown>
1625
- `;
1626
- generatedComponent += `const Page = (_props: { params: Params, resources: Resources }) => {
1662
+ generatedComponent += `const Page = (_props: { params: Params }) => {
1627
1663
  `;
1628
1664
  generatedComponent += `${generatedDataSources}`;
1629
1665
  generatedComponent += `return ${generatedJsx}`;
@@ -1784,5 +1820,6 @@ export {
1784
1820
  showAttribute,
1785
1821
  stateCategories,
1786
1822
  textContentAttribute,
1823
+ useResource,
1787
1824
  validateExpression
1788
1825
  };
@@ -688,7 +688,7 @@ declare const WsComponentPropsMeta: z.ZodObject<{
688
688
  initialProps?: string[] | undefined;
689
689
  }>;
690
690
  export type WsComponentPropsMeta = z.infer<typeof WsComponentPropsMeta>;
691
- export declare const componentCategories: readonly ["general", "text", "media", "forms", "radix", "hidden"];
691
+ export declare const componentCategories: readonly ["general", "text", "data", "media", "forms", "radix", "hidden"];
692
692
  export declare const stateCategories: readonly ["states", "component-states"];
693
693
  export declare const ComponentState: z.ZodObject<{
694
694
  category: z.ZodOptional<z.ZodEnum<["states", "component-states"]>>;
@@ -706,7 +706,7 @@ export declare const ComponentState: z.ZodObject<{
706
706
  export type ComponentState = z.infer<typeof ComponentState>;
707
707
  export declare const defaultStates: ComponentState[];
708
708
  export declare const WsComponentMeta: z.ZodObject<{
709
- category: z.ZodOptional<z.ZodEnum<["general", "text", "media", "forms", "radix", "hidden"]>>;
709
+ category: z.ZodOptional<z.ZodEnum<["general", "text", "data", "media", "forms", "radix", "hidden"]>>;
710
710
  type: z.ZodEnum<["container", "control", "embed", "rich-text-child"]>;
711
711
  requiredAncestors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
712
712
  invalidAncestors: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
@@ -2021,12 +2021,21 @@ export declare const WsComponentMeta: z.ZodObject<{
2021
2021
  }, {
2022
2022
  value: string;
2023
2023
  type: "text";
2024
+ }>, z.ZodObject<{
2025
+ type: z.ZodLiteral<"expression">;
2026
+ value: z.ZodString;
2027
+ }, "strip", z.ZodTypeAny, {
2028
+ value: string;
2029
+ type: "expression";
2030
+ }, {
2031
+ value: string;
2032
+ type: "expression";
2024
2033
  }>]>, "many">>>;
2025
2034
  order: z.ZodOptional<z.ZodNumber>;
2026
2035
  }, "strip", z.ZodTypeAny, {
2027
2036
  type: "embed" | "control" | "container" | "rich-text-child";
2028
2037
  icon: string;
2029
- category?: "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2038
+ category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2030
2039
  requiredAncestors?: string[] | undefined;
2031
2040
  invalidAncestors?: string[] | undefined;
2032
2041
  indexWithinAncestor?: string | undefined;
@@ -2471,12 +2480,15 @@ export declare const WsComponentMeta: z.ZodObject<{
2471
2480
  template?: ({
2472
2481
  value: string;
2473
2482
  type: "text";
2483
+ } | {
2484
+ value: string;
2485
+ type: "expression";
2474
2486
  } | import("../embed-template").EmbedTemplateInstance)[] | undefined;
2475
2487
  order?: number | undefined;
2476
2488
  }, {
2477
2489
  type: "embed" | "control" | "container" | "rich-text-child";
2478
2490
  icon: string;
2479
- category?: "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2491
+ category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2480
2492
  requiredAncestors?: string[] | undefined;
2481
2493
  invalidAncestors?: string[] | undefined;
2482
2494
  indexWithinAncestor?: string | undefined;
@@ -2921,6 +2933,9 @@ export declare const WsComponentMeta: z.ZodObject<{
2921
2933
  template?: ({
2922
2934
  value: string;
2923
2935
  type: "text";
2936
+ } | {
2937
+ value: string;
2938
+ type: "expression";
2924
2939
  } | import("../embed-template").EmbedTemplateInstance)[] | undefined;
2925
2940
  order?: number | undefined;
2926
2941
  }>;
@@ -35,4 +35,6 @@ export declare const ReactSdkContext: import("react").Context<Params & {
35
35
  * always empty for builder which handle anchor clicks globally
36
36
  */
37
37
  pagesPaths: Set<Page["path"]>;
38
+ resources: Record<string, any>;
38
39
  }>;
40
+ export declare const useResource: (name: string) => any;
@@ -1,5 +1,5 @@
1
1
  import { z } from "zod";
2
- import type { Instance, Breakpoint } from "@webstudio-is/sdk";
2
+ import type { Instance, Breakpoint, WebstudioFragment } from "@webstudio-is/sdk";
3
3
  import { type StyleProperty } from "@webstudio-is/css-engine";
4
4
  import type { Simplify } from "type-fest";
5
5
  import type { WsComponentMeta } from "./components/component-meta";
@@ -14,11 +14,25 @@ declare const EmbedTemplateText: z.ZodObject<{
14
14
  type: "text";
15
15
  }>;
16
16
  type EmbedTemplateText = z.infer<typeof EmbedTemplateText>;
17
+ declare const EmbedTemplateExpression: z.ZodObject<{
18
+ type: z.ZodLiteral<"expression">;
19
+ value: z.ZodString;
20
+ }, "strip", z.ZodTypeAny, {
21
+ value: string;
22
+ type: "expression";
23
+ }, {
24
+ value: string;
25
+ type: "expression";
26
+ }>;
27
+ type EmbedTemplateExpression = z.infer<typeof EmbedTemplateExpression>;
17
28
  declare const EmbedTemplateVariable: z.ZodObject<{
29
+ alias: z.ZodOptional<z.ZodString>;
18
30
  initialValue: z.ZodUnknown;
19
31
  }, "strip", z.ZodTypeAny, {
32
+ alias?: string | undefined;
20
33
  initialValue?: unknown;
21
34
  }, {
35
+ alias?: string | undefined;
22
36
  initialValue?: unknown;
23
37
  }>;
24
38
  type EmbedTemplateVariable = z.infer<typeof EmbedTemplateVariable>;
@@ -98,14 +112,17 @@ export declare const EmbedTemplateProp: z.ZodUnion<[z.ZodObject<{
98
112
  type: z.ZodLiteral<"parameter">;
99
113
  name: z.ZodString;
100
114
  variableName: z.ZodString;
115
+ variableAlias: z.ZodOptional<z.ZodString>;
101
116
  }, "strip", z.ZodTypeAny, {
102
117
  type: "parameter";
103
118
  name: string;
104
119
  variableName: string;
120
+ variableAlias?: string | undefined;
105
121
  }, {
106
122
  type: "parameter";
107
123
  name: string;
108
124
  variableName: string;
125
+ variableAlias?: string | undefined;
109
126
  }>, z.ZodObject<{
110
127
  type: z.ZodLiteral<"action">;
111
128
  name: z.ZodString;
@@ -2191,7 +2208,7 @@ export type EmbedTemplateInstance = {
2191
2208
  props?: EmbedTemplateProp[];
2192
2209
  tokens?: string[];
2193
2210
  styles?: EmbedTemplateStyleDecl[];
2194
- children: Array<EmbedTemplateInstance | EmbedTemplateText>;
2211
+ children: Array<EmbedTemplateInstance | EmbedTemplateText | EmbedTemplateExpression>;
2195
2212
  };
2196
2213
  export declare const EmbedTemplateInstance: z.ZodType<EmbedTemplateInstance>;
2197
2214
  export declare const WsEmbedTemplate: z.ZodLazy<z.ZodArray<z.ZodUnion<[z.ZodType<EmbedTemplateInstance, z.ZodTypeDef, EmbedTemplateInstance>, z.ZodObject<{
@@ -2203,381 +2220,24 @@ export declare const WsEmbedTemplate: z.ZodLazy<z.ZodArray<z.ZodUnion<[z.ZodType
2203
2220
  }, {
2204
2221
  value: string;
2205
2222
  type: "text";
2223
+ }>, z.ZodObject<{
2224
+ type: z.ZodLiteral<"expression">;
2225
+ value: z.ZodString;
2226
+ }, "strip", z.ZodTypeAny, {
2227
+ value: string;
2228
+ type: "expression";
2229
+ }, {
2230
+ value: string;
2231
+ type: "expression";
2206
2232
  }>]>, "many">>;
2207
2233
  export type WsEmbedTemplate = z.infer<typeof WsEmbedTemplate>;
2208
2234
  export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
2209
2235
  value: string;
2210
2236
  type: "text";
2211
- } | EmbedTemplateInstance)[], metas: Map<Instance["component"], WsComponentMeta>, defaultBreakpointId: Breakpoint["id"], generateId?: () => string) => {
2212
- children: ({
2213
- value: string;
2214
- type: "text";
2215
- } | {
2216
- value: string;
2217
- type: "id";
2218
- } | {
2219
- value: string;
2220
- type: "expression";
2221
- })[];
2222
- instances: {
2223
- type: "instance";
2224
- id: string;
2225
- children: ({
2226
- value: string;
2227
- type: "text";
2228
- } | {
2229
- value: string;
2230
- type: "id";
2231
- } | {
2232
- value: string;
2233
- type: "expression";
2234
- })[];
2235
- component: string;
2236
- label?: string | undefined;
2237
- }[];
2238
- props: ({
2239
- value: number;
2240
- type: "number";
2241
- name: string;
2242
- id: string;
2243
- instanceId: string;
2244
- required?: boolean | undefined;
2245
- } | {
2246
- value: string;
2247
- type: "string";
2248
- name: string;
2249
- id: string;
2250
- instanceId: string;
2251
- required?: boolean | undefined;
2252
- } | {
2253
- value: boolean;
2254
- type: "boolean";
2255
- name: string;
2256
- id: string;
2257
- instanceId: string;
2258
- required?: boolean | undefined;
2259
- } | {
2260
- type: "json";
2261
- name: string;
2262
- id: string;
2263
- instanceId: string;
2264
- value?: unknown;
2265
- required?: boolean | undefined;
2266
- } | {
2267
- value: string;
2268
- type: "asset";
2269
- name: string;
2270
- id: string;
2271
- instanceId: string;
2272
- required?: boolean | undefined;
2273
- } | {
2274
- value: (string | {
2275
- instanceId: string;
2276
- pageId: string;
2277
- }) & (string | {
2278
- instanceId: string;
2279
- pageId: string;
2280
- } | undefined);
2281
- type: "page";
2282
- name: string;
2283
- id: string;
2284
- instanceId: string;
2285
- required?: boolean | undefined;
2286
- } | {
2287
- value: string[];
2288
- type: "string[]";
2289
- name: string;
2290
- id: string;
2291
- instanceId: string;
2292
- required?: boolean | undefined;
2293
- } | {
2294
- value: string;
2295
- type: "parameter";
2296
- name: string;
2297
- id: string;
2298
- instanceId: string;
2299
- required?: boolean | undefined;
2300
- } | {
2301
- value: string;
2302
- type: "expression";
2303
- name: string;
2304
- id: string;
2305
- instanceId: string;
2306
- required?: boolean | undefined;
2307
- } | {
2308
- value: {
2309
- code: string;
2310
- type: "execute";
2311
- args: string[];
2312
- }[];
2313
- type: "action";
2314
- name: string;
2315
- id: string;
2316
- instanceId: string;
2317
- required?: boolean | undefined;
2318
- })[];
2319
- dataSources: ({
2320
- value: {
2321
- value: number;
2322
- type: "number";
2323
- } | {
2324
- value: string;
2325
- type: "string";
2326
- } | {
2327
- value: boolean;
2328
- type: "boolean";
2329
- } | {
2330
- value: string[];
2331
- type: "string[]";
2332
- } | {
2333
- type: "json";
2334
- value?: unknown;
2335
- };
2336
- type: "variable";
2337
- name: string;
2338
- id: string;
2339
- scopeInstanceId?: string | undefined;
2340
- } | {
2341
- type: "parameter";
2342
- name: string;
2343
- id: string;
2344
- scopeInstanceId?: string | undefined;
2345
- } | {
2346
- type: "resource";
2347
- name: string;
2348
- id: string;
2349
- resourceId: string;
2350
- scopeInstanceId?: string | undefined;
2351
- })[];
2352
- styleSourceSelections: {
2353
- values: string[];
2354
- instanceId: string;
2355
- }[];
2356
- styleSources: ({
2357
- type: "token";
2358
- name: string;
2359
- id: string;
2360
- } | {
2361
- type: "local";
2362
- id: string;
2363
- })[];
2364
- styles: {
2365
- value: {
2366
- value: number;
2367
- type: "unit";
2368
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2369
- } | {
2370
- value: string;
2371
- type: "keyword";
2372
- } | {
2373
- value: string;
2374
- type: "unparsed";
2375
- hidden?: boolean | undefined;
2376
- } | {
2377
- value: string[];
2378
- type: "fontFamily";
2379
- } | {
2380
- type: "rgb";
2381
- r: number;
2382
- g: number;
2383
- b: number;
2384
- alpha: number;
2385
- } | {
2386
- value: {
2387
- value: string;
2388
- type: "asset";
2389
- } | {
2390
- type: "url";
2391
- url: string;
2392
- };
2393
- type: "image";
2394
- hidden?: boolean | undefined;
2395
- } | {
2396
- value: string;
2397
- type: "invalid";
2398
- } | {
2399
- value: "";
2400
- type: "unset";
2401
- } | {
2402
- value: ({
2403
- value: number;
2404
- type: "unit";
2405
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2406
- } | {
2407
- value: string;
2408
- type: "keyword";
2409
- } | {
2410
- value: string;
2411
- type: "unparsed";
2412
- hidden?: boolean | undefined;
2413
- } | {
2414
- type: "rgb";
2415
- r: number;
2416
- g: number;
2417
- b: number;
2418
- alpha: number;
2419
- })[];
2420
- type: "tuple";
2421
- hidden?: boolean | undefined;
2422
- } | {
2423
- value: ({
2424
- value: number;
2425
- type: "unit";
2426
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2427
- } | {
2428
- value: string;
2429
- type: "keyword";
2430
- } | {
2431
- value: string;
2432
- type: "unparsed";
2433
- hidden?: boolean | undefined;
2434
- } | {
2435
- value: {
2436
- value: string;
2437
- type: "asset";
2438
- } | {
2439
- type: "url";
2440
- url: string;
2441
- };
2442
- type: "image";
2443
- hidden?: boolean | undefined;
2444
- } | {
2445
- value: string;
2446
- type: "invalid";
2447
- } | {
2448
- value: ({
2449
- value: number;
2450
- type: "unit";
2451
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2452
- } | {
2453
- value: string;
2454
- type: "keyword";
2455
- } | {
2456
- value: string;
2457
- type: "unparsed";
2458
- hidden?: boolean | undefined;
2459
- } | {
2460
- type: "rgb";
2461
- r: number;
2462
- g: number;
2463
- b: number;
2464
- alpha: number;
2465
- })[];
2466
- type: "tuple";
2467
- hidden?: boolean | undefined;
2468
- })[];
2469
- type: "layers";
2470
- } | {
2471
- value: string;
2472
- type: "var";
2473
- fallbacks: ({
2474
- value: number;
2475
- type: "unit";
2476
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2477
- } | {
2478
- value: string;
2479
- type: "keyword";
2480
- } | {
2481
- value: string;
2482
- type: "unparsed";
2483
- hidden?: boolean | undefined;
2484
- } | {
2485
- value: string[];
2486
- type: "fontFamily";
2487
- } | {
2488
- type: "rgb";
2489
- r: number;
2490
- g: number;
2491
- b: number;
2492
- alpha: number;
2493
- } | {
2494
- value: {
2495
- value: string;
2496
- type: "asset";
2497
- } | {
2498
- type: "url";
2499
- url: string;
2500
- };
2501
- type: "image";
2502
- hidden?: boolean | undefined;
2503
- } | {
2504
- value: ({
2505
- value: number;
2506
- type: "unit";
2507
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2508
- } | {
2509
- value: string;
2510
- type: "keyword";
2511
- } | {
2512
- value: string;
2513
- type: "unparsed";
2514
- hidden?: boolean | undefined;
2515
- } | {
2516
- type: "rgb";
2517
- r: number;
2518
- g: number;
2519
- b: number;
2520
- alpha: number;
2521
- })[];
2522
- type: "tuple";
2523
- hidden?: boolean | undefined;
2524
- } | {
2525
- value: ({
2526
- value: number;
2527
- type: "unit";
2528
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2529
- } | {
2530
- value: string;
2531
- type: "keyword";
2532
- } | {
2533
- value: string;
2534
- type: "unparsed";
2535
- hidden?: boolean | undefined;
2536
- } | {
2537
- value: {
2538
- value: string;
2539
- type: "asset";
2540
- } | {
2541
- type: "url";
2542
- url: string;
2543
- };
2544
- type: "image";
2545
- hidden?: boolean | undefined;
2546
- } | {
2547
- value: string;
2548
- type: "invalid";
2549
- } | {
2550
- value: ({
2551
- value: number;
2552
- type: "unit";
2553
- unit: "number" | "%" | "deg" | "grad" | "rad" | "turn" | "db" | "fr" | "hz" | "khz" | "cm" | "mm" | "q" | "in" | "pt" | "pc" | "px" | "em" | "rem" | "ex" | "rex" | "cap" | "rcap" | "ch" | "rch" | "ic" | "ric" | "lh" | "rlh" | "vw" | "svw" | "lvw" | "dvw" | "vh" | "svh" | "lvh" | "dvh" | "vi" | "svi" | "lvi" | "dvi" | "vb" | "svb" | "lvb" | "dvb" | "vmin" | "svmin" | "lvmin" | "dvmin" | "vmax" | "svmax" | "lvmax" | "dvmax" | "cqw" | "cqh" | "cqi" | "cqb" | "cqmin" | "cqmax" | "dpi" | "dpcm" | "dppx" | "x" | "st" | "s" | "ms";
2554
- } | {
2555
- value: string;
2556
- type: "keyword";
2557
- } | {
2558
- value: string;
2559
- type: "unparsed";
2560
- hidden?: boolean | undefined;
2561
- } | {
2562
- type: "rgb";
2563
- r: number;
2564
- g: number;
2565
- b: number;
2566
- alpha: number;
2567
- })[];
2568
- type: "tuple";
2569
- hidden?: boolean | undefined;
2570
- })[];
2571
- type: "layers";
2572
- })[];
2573
- };
2574
- styleSourceId: string;
2575
- breakpointId: string;
2576
- state?: string | undefined;
2577
- property: StyleProperty;
2578
- }[];
2579
- };
2580
- export type EmbedTemplateData = ReturnType<typeof generateDataFromEmbedTemplate>;
2237
+ } | {
2238
+ value: string;
2239
+ type: "expression";
2240
+ } | EmbedTemplateInstance)[], metas: Map<Instance["component"], WsComponentMeta>, defaultBreakpointId: Breakpoint["id"], generateId?: () => string) => WebstudioFragment;
2581
2241
  export declare const namespaceMeta: (meta: WsComponentMeta, namespace: string, components: Set<EmbedTemplateInstance["component"]>) => {
2582
2242
  type: "embed" | "control" | "container" | "rich-text-child";
2583
2243
  description?: string | undefined;
@@ -2586,8 +2246,11 @@ export declare const namespaceMeta: (meta: WsComponentMeta, namespace: string, c
2586
2246
  template?: ({
2587
2247
  value: string;
2588
2248
  type: "text";
2249
+ } | {
2250
+ value: string;
2251
+ type: "expression";
2589
2252
  } | EmbedTemplateInstance)[] | undefined;
2590
- category?: "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2253
+ category?: "data" | "text" | "hidden" | "media" | "general" | "forms" | "radix" | undefined;
2591
2254
  requiredAncestors?: string[] | undefined;
2592
2255
  invalidAncestors?: string[] | undefined;
2593
2256
  indexWithinAncestor?: string | undefined;
@@ -1,4 +1,4 @@
1
- import type { Pages, Props } from "@webstudio-is/sdk";
1
+ import { type Pages, type Props } from "@webstudio-is/sdk";
2
2
  type PageData = {
3
3
  pages: Pages;
4
4
  props: Props;
@@ -8,7 +8,7 @@ export { PropMeta } from "./prop-meta";
8
8
  export { type WsComponentPropsMeta, type ComponentState, type PresetStyle, WsComponentMeta, componentCategories, stateCategories, defaultStates, } from "./components/component-meta";
9
9
  export * from "./embed-template";
10
10
  export * from "./props";
11
- export { type Params, ReactSdkContext } from "./context";
11
+ export * from "./context";
12
12
  export { validateExpression, encodeDataSourceVariable, decodeDataSourceVariable, generateDataSources, } from "./expression";
13
13
  export { getIndexesWithinAncestors } from "./instance-utils";
14
14
  export * from "./hook";
@@ -1,5 +1,4 @@
1
- import type { Page, Prop, Assets } from "@webstudio-is/sdk";
2
- export type Pages = Map<Page["id"], Page>;
1
+ import { type Prop, type Assets, type Pages } from "@webstudio-is/sdk";
3
2
  export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
4
3
  props: Prop[];
5
4
  assetBaseUrl: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.125.0",
3
+ "version": "0.126.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -16,8 +16,8 @@
16
16
  "type-fest": "^4.3.1",
17
17
  "typescript": "5.2.2",
18
18
  "zod": "^3.21.4",
19
- "@webstudio-is/tsconfig": "1.0.7",
20
- "@webstudio-is/jest-config": "1.0.7"
19
+ "@webstudio-is/jest-config": "1.0.7",
20
+ "@webstudio-is/tsconfig": "1.0.7"
21
21
  },
22
22
  "peerDependencies": {
23
23
  "@remix-run/react": "^1.19.1",
@@ -33,11 +33,11 @@
33
33
  "jsep": "^1.3.8",
34
34
  "nanoid": "^5.0.1",
35
35
  "title-case": "^4.1.0",
36
- "@webstudio-is/fonts": "0.125.0",
37
- "@webstudio-is/icons": "^0.125.0",
38
- "@webstudio-is/image": "0.125.0",
39
- "@webstudio-is/sdk": "0.125.0",
40
- "@webstudio-is/css-engine": "0.125.0"
36
+ "@webstudio-is/fonts": "0.126.0",
37
+ "@webstudio-is/image": "0.126.0",
38
+ "@webstudio-is/css-engine": "0.126.0",
39
+ "@webstudio-is/icons": "^0.126.0",
40
+ "@webstudio-is/sdk": "0.126.0"
41
41
  },
42
42
  "exports": {
43
43
  ".": {