@webstudio-is/react-sdk 0.100.1-d89b38d.0 → 0.101.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
@@ -26,9 +26,9 @@ var ReactSdkContext = createContext({
26
26
  assetBaseUrl: "/",
27
27
  imageBaseUrl: "/",
28
28
  imageLoader: ({ src }) => src,
29
+ pagesPaths: /* @__PURE__ */ new Set(),
29
30
  propsByInstanceIdStore: atom(/* @__PURE__ */ new Map()),
30
31
  assetsStore: atom(/* @__PURE__ */ new Map()),
31
- pagesStore: atom(/* @__PURE__ */ new Map()),
32
32
  dataSourcesLogicStore: atom(/* @__PURE__ */ new Map()),
33
33
  indexesWithinAncestors: /* @__PURE__ */ new Map()
34
34
  });
@@ -44,7 +44,6 @@ var createElementsTree = ({
44
44
  rootInstanceId,
45
45
  propsByInstanceIdStore,
46
46
  assetsStore,
47
- pagesStore,
48
47
  dataSourcesLogicStore,
49
48
  indexesWithinAncestors,
50
49
  Component,
@@ -81,10 +80,10 @@ var createElementsTree = ({
81
80
  value: {
82
81
  propsByInstanceIdStore,
83
82
  assetsStore,
84
- pagesStore,
85
83
  dataSourcesLogicStore,
86
84
  renderer,
87
85
  imageLoader,
86
+ pagesPaths: /* @__PURE__ */ new Set(),
88
87
  assetBaseUrl,
89
88
  imageBaseUrl,
90
89
  indexesWithinAncestors
@@ -148,174 +147,9 @@ var createInstanceElement = ({
148
147
  );
149
148
  };
150
149
 
151
- // src/tree/root.ts
152
- import {
153
- useRef
154
- } from "react";
155
- import {
156
- atom as atom2,
157
- computed as computed2
158
- } from "nanostores";
159
-
160
- // src/tree/webstudio-component.tsx
161
- import { Fragment as Fragment2, forwardRef } from "react";
162
-
163
- // src/props.ts
164
- import { useContext, useMemo } from "react";
165
- import { computed } from "nanostores";
166
- import { useStore } from "@nanostores/react";
167
- var getPropsByInstanceId = (props) => {
168
- const propsByInstanceId = /* @__PURE__ */ new Map();
169
- for (const prop of props.values()) {
170
- let instanceProps = propsByInstanceId.get(prop.instanceId);
171
- if (instanceProps === void 0) {
172
- instanceProps = [];
173
- propsByInstanceId.set(prop.instanceId, instanceProps);
174
- }
175
- instanceProps.push(prop);
176
- }
177
- return propsByInstanceId;
178
- };
179
- var useInstanceProps = (instanceId) => {
180
- const {
181
- propsByInstanceIdStore,
182
- dataSourcesLogicStore,
183
- indexesWithinAncestors
184
- } = useContext(ReactSdkContext);
185
- const index = indexesWithinAncestors.get(instanceId);
186
- const instancePropsObjectStore = useMemo(() => {
187
- return computed(
188
- [propsByInstanceIdStore, dataSourcesLogicStore],
189
- (propsByInstanceId, dataSourcesLogic) => {
190
- const instancePropsObject2 = {};
191
- if (index !== void 0) {
192
- instancePropsObject2[indexAttribute] = index.toString();
193
- }
194
- const instanceProps = propsByInstanceId.get(instanceId);
195
- if (instanceProps === void 0) {
196
- return instancePropsObject2;
197
- }
198
- for (const prop of instanceProps) {
199
- if (prop.type === "asset" || prop.type === "page") {
200
- continue;
201
- }
202
- if (prop.type === "dataSource") {
203
- const dataSourceId = prop.value;
204
- const value = dataSourcesLogic.get(dataSourceId);
205
- if (value !== void 0) {
206
- instancePropsObject2[prop.name] = value;
207
- }
208
- continue;
209
- }
210
- if (prop.type === "action") {
211
- const action = dataSourcesLogic.get(prop.id);
212
- if (typeof action === "function") {
213
- instancePropsObject2[prop.name] = action;
214
- }
215
- continue;
216
- }
217
- instancePropsObject2[prop.name] = prop.value;
218
- }
219
- return instancePropsObject2;
220
- }
221
- );
222
- }, [propsByInstanceIdStore, dataSourcesLogicStore, instanceId, index]);
223
- const instancePropsObject = useStore(instancePropsObjectStore);
224
- return instancePropsObject;
225
- };
226
- var usePropAsset = (instanceId, name) => {
227
- const { propsByInstanceIdStore, assetsStore } = useContext(ReactSdkContext);
228
- const assetStore = useMemo(() => {
229
- return computed(
230
- [propsByInstanceIdStore, assetsStore],
231
- (propsByInstanceId, assets) => {
232
- const instanceProps = propsByInstanceId.get(instanceId);
233
- if (instanceProps === void 0) {
234
- return;
235
- }
236
- for (const prop of instanceProps) {
237
- if (prop.type === "asset" && prop.name === name) {
238
- const assetId = prop.value;
239
- return assets.get(assetId);
240
- }
241
- }
242
- }
243
- );
244
- }, [propsByInstanceIdStore, assetsStore, instanceId, name]);
245
- const asset = useStore(assetStore);
246
- return asset;
247
- };
248
- var resolveUrlProp = (instanceId, name, {
249
- props,
250
- pages,
251
- assets
252
- }) => {
253
- const instanceProps = props.get(instanceId);
254
- if (instanceProps === void 0) {
255
- return;
256
- }
257
- let prop = void 0;
258
- for (const intanceProp of instanceProps) {
259
- if (intanceProp.name !== name) {
260
- continue;
261
- }
262
- prop = intanceProp;
263
- }
264
- if (prop === void 0) {
265
- return;
266
- }
267
- if (prop.type === "page") {
268
- if (typeof prop.value === "string") {
269
- const page2 = pages.get(prop.value);
270
- return page2 && { type: "page", page: page2 };
271
- }
272
- const { instanceId: instanceId2, pageId } = prop.value;
273
- const page = pages.get(pageId);
274
- if (page === void 0) {
275
- return;
276
- }
277
- const idProp = props.get(instanceId2)?.find((prop2) => prop2.name === "id");
278
- return {
279
- type: "page",
280
- page,
281
- instanceId: instanceId2,
282
- hash: idProp === void 0 || idProp.type !== "string" ? void 0 : idProp.value
283
- };
284
- }
285
- if (prop.type === "string") {
286
- for (const page of pages.values()) {
287
- if (page.path === prop.value) {
288
- return { type: "page", page };
289
- }
290
- }
291
- return { type: "string", url: prop.value };
292
- }
293
- if (prop.type === "asset") {
294
- const asset = assets.get(prop.value);
295
- return asset && { type: "asset", asset };
296
- }
297
- return;
298
- };
299
- var usePropUrl = (instanceId, name) => {
300
- const { propsByInstanceIdStore, pagesStore, assetsStore } = useContext(ReactSdkContext);
301
- const store = useMemo(
302
- () => computed(
303
- [propsByInstanceIdStore, pagesStore, assetsStore],
304
- (props, pages, assets) => resolveUrlProp(instanceId, name, { props, pages, assets })
305
- ),
306
- [propsByInstanceIdStore, pagesStore, assetsStore, instanceId, name]
307
- );
308
- return useStore(store);
309
- };
310
- var getInstanceIdFromComponentProps = (props) => {
311
- return props[idAttribute];
312
- };
313
- var getIndexWithinAncestorFromComponentProps = (props) => {
314
- return props[indexAttribute];
315
- };
316
-
317
150
  // src/tree/webstudio-component.tsx
318
- import { Fragment as Fragment3, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
151
+ import { Fragment as Fragment2 } from "react";
152
+ import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
319
153
  var renderText = (text) => {
320
154
  const lines = text.split("\n");
321
155
  return lines.map((line, index) => /* @__PURE__ */ jsxs2(Fragment2, { children: [
@@ -331,105 +165,12 @@ var renderWebstudioComponentChildren = (children) => {
331
165
  return typeof child === "string" ? renderText(child) : child;
332
166
  });
333
167
  };
334
- var WebstudioComponent = forwardRef(({ instance, instanceSelector, children, components, ...rest }, ref) => {
335
- const { [showAttribute]: show = true, ...instanceProps } = useInstanceProps(
336
- instance.id
337
- );
338
- const props = {
339
- ...instanceProps,
340
- ...rest,
341
- [idAttribute]: instance.id,
342
- [componentAttribute]: instance.component
343
- };
344
- if (show === false) {
345
- return /* @__PURE__ */ jsx2(Fragment3, {});
346
- }
347
- const Component = components.get(instance.component);
348
- if (Component === void 0) {
349
- return /* @__PURE__ */ jsx2(Fragment3, {});
350
- }
351
- return /* @__PURE__ */ jsx2(Component, { ...props, ref, children: renderWebstudioComponentChildren(children) });
352
- });
353
168
  var idAttribute = "data-ws-id";
354
169
  var selectorIdAttribute = "data-ws-selector";
355
170
  var componentAttribute = "data-ws-component";
356
171
  var showAttribute = "data-ws-show";
357
172
  var indexAttribute = "data-ws-index";
358
173
  var collapsedAttribute = "data-ws-collapsed";
359
- var splitPropsWithWebstudioAttributes = ({
360
- [idAttribute]: idAttributeValue,
361
- [componentAttribute]: componentAttributeValue,
362
- [showAttribute]: showAttributeValue,
363
- [collapsedAttribute]: collapsedAttributeValue,
364
- [selectorIdAttribute]: parentIdAttributeValue,
365
- ...props
366
- }) => [
367
- {
368
- [idAttribute]: idAttributeValue,
369
- [componentAttribute]: componentAttributeValue,
370
- [showAttribute]: showAttributeValue,
371
- [collapsedAttribute]: collapsedAttributeValue,
372
- [selectorIdAttribute]: parentIdAttributeValue
373
- },
374
- props
375
- ];
376
-
377
- // src/tree/root.ts
378
- var InstanceRoot = ({
379
- data,
380
- utils,
381
- Component,
382
- components,
383
- scripts,
384
- imageLoader
385
- }) => {
386
- const { indexesWithinAncestors, getDataSourcesLogic } = utils;
387
- const dataSourceVariablesStoreRef = useRef(void 0);
388
- if (dataSourceVariablesStoreRef.current === void 0) {
389
- dataSourceVariablesStoreRef.current = atom2(/* @__PURE__ */ new Map());
390
- }
391
- const dataSourceVariablesStore = dataSourceVariablesStoreRef.current;
392
- const dataSourcesLogicStoreRef = useRef(void 0);
393
- if (dataSourcesLogicStoreRef.current === void 0) {
394
- dataSourcesLogicStoreRef.current = computed2(
395
- dataSourceVariablesStore,
396
- (dataSourceVariables) => {
397
- try {
398
- const getVariable = (id) => {
399
- return dataSourceVariables.get(id);
400
- };
401
- const setVariable = (id, value) => {
402
- const dataSourceVariables2 = new Map(dataSourceVariablesStore.get());
403
- dataSourceVariables2.set(id, value);
404
- dataSourceVariablesStore.set(dataSourceVariables2);
405
- };
406
- return getDataSourcesLogic(getVariable, setVariable);
407
- } catch (error) {
408
- console.error(error);
409
- }
410
- return /* @__PURE__ */ new Map();
411
- }
412
- );
413
- }
414
- const dataSourcesLogicStore = dataSourcesLogicStoreRef.current;
415
- return createElementsTree({
416
- imageLoader,
417
- imageBaseUrl: data.params?.imageBaseUrl ?? "/",
418
- assetBaseUrl: data.params?.assetBaseUrl ?? "/",
419
- instances: new Map(data.build.instances),
420
- rootInstanceId: data.page.rootInstanceId,
421
- propsByInstanceIdStore: atom2(
422
- getPropsByInstanceId(new Map(data.build.props))
423
- ),
424
- assetsStore: atom2(new Map(data.assets.map((asset) => [asset.id, asset]))),
425
- pagesStore: atom2(new Map(data.pages.map((page) => [page.id, page]))),
426
- indexesWithinAncestors,
427
- dataSourcesLogicStore,
428
- Component: Component ?? WebstudioComponent,
429
- components,
430
- scripts
431
- });
432
- };
433
174
 
434
175
  // src/css/style-rules.ts
435
176
  var getStyleRules = (styles, styleSourceSelections) => {
@@ -1446,6 +1187,87 @@ var WsComponentMeta = z3.object({
1446
1187
  order: z3.number().optional()
1447
1188
  });
1448
1189
 
1190
+ // src/props.ts
1191
+ var normalizeProps = ({
1192
+ props,
1193
+ assetBaseUrl,
1194
+ assets,
1195
+ pages
1196
+ }) => {
1197
+ const newProps = [];
1198
+ for (const prop of props) {
1199
+ if (prop.type === "asset") {
1200
+ const assetId = prop.value;
1201
+ const asset = assets.get(assetId);
1202
+ if (asset === void 0) {
1203
+ continue;
1204
+ }
1205
+ newProps.push({
1206
+ id: prop.id,
1207
+ name: prop.name,
1208
+ required: prop.required,
1209
+ instanceId: prop.instanceId,
1210
+ type: "string",
1211
+ value: `${assetBaseUrl}${asset.name}`
1212
+ });
1213
+ continue;
1214
+ }
1215
+ if (prop.type === "page") {
1216
+ let page;
1217
+ let idProp;
1218
+ if (typeof prop.value === "string") {
1219
+ const pageId = prop.value;
1220
+ page = pages.get(pageId);
1221
+ } else {
1222
+ const { pageId, instanceId } = prop.value;
1223
+ page = pages.get(pageId);
1224
+ idProp = props.find(
1225
+ (prop2) => prop2.instanceId === instanceId && prop2.name === "id"
1226
+ );
1227
+ }
1228
+ if (page === void 0) {
1229
+ continue;
1230
+ }
1231
+ const url = new URL(page.path, "https://any-valid.url");
1232
+ let value = url.pathname;
1233
+ if (idProp?.type === "string") {
1234
+ const hash = idProp.value;
1235
+ url.hash = encodeURIComponent(hash);
1236
+ value = `${url.pathname}${url.hash}`;
1237
+ }
1238
+ newProps.push({
1239
+ id: prop.id,
1240
+ name: prop.name,
1241
+ required: prop.required,
1242
+ instanceId: prop.instanceId,
1243
+ type: "string",
1244
+ value
1245
+ });
1246
+ continue;
1247
+ }
1248
+ newProps.push(prop);
1249
+ }
1250
+ return newProps;
1251
+ };
1252
+ var getPropsByInstanceId = (props) => {
1253
+ const propsByInstanceId = /* @__PURE__ */ new Map();
1254
+ for (const prop of props.values()) {
1255
+ let instanceProps = propsByInstanceId.get(prop.instanceId);
1256
+ if (instanceProps === void 0) {
1257
+ instanceProps = [];
1258
+ propsByInstanceId.set(prop.instanceId, instanceProps);
1259
+ }
1260
+ instanceProps.push(prop);
1261
+ }
1262
+ return propsByInstanceId;
1263
+ };
1264
+ var getInstanceIdFromComponentProps = (props) => {
1265
+ return props[idAttribute];
1266
+ };
1267
+ var getIndexWithinAncestorFromComponentProps = (props) => {
1268
+ return props[indexAttribute];
1269
+ };
1270
+
1449
1271
  // src/instance-utils.ts
1450
1272
  var getIndexesWithinAncestors = (metas, instances, rootIds) => {
1451
1273
  const ancestors = /* @__PURE__ */ new Set();
@@ -1505,6 +1327,13 @@ var getClosestInstance = (instancePath, currentInstance, closestComponent) => {
1505
1327
 
1506
1328
  // src/generator.ts
1507
1329
  var generateUtilsExport = (siteData) => {
1330
+ const pagesPaths = [siteData.pages.homePage.path];
1331
+ for (const page of siteData.pages.pages) {
1332
+ pagesPaths.push(page.path);
1333
+ }
1334
+ const generatedPagesPaths = `export const pagesPaths = new Set(${JSON.stringify(
1335
+ pagesPaths
1336
+ )})`;
1508
1337
  const formsProperties = /* @__PURE__ */ new Map();
1509
1338
  for (const prop of siteData.props.values()) {
1510
1339
  if (prop.type === "string") {
@@ -1522,6 +1351,8 @@ var generateUtilsExport = (siteData) => {
1522
1351
  Array.from(formsProperties.entries())
1523
1352
  )})`;
1524
1353
  return `
1354
+ ${generatedPagesPaths}
1355
+
1525
1356
  ${generatedFormsProperties}
1526
1357
  `;
1527
1358
  };
@@ -1712,11 +1543,9 @@ var generatePageComponent = ({
1712
1543
  export {
1713
1544
  EmbedTemplateInstance,
1714
1545
  EmbedTemplateStyleDecl,
1715
- InstanceRoot,
1716
1546
  PropMeta,
1717
1547
  ReactSdkContext,
1718
1548
  Root,
1719
- WebstudioComponent,
1720
1549
  WsComponentMeta,
1721
1550
  WsEmbedTemplate,
1722
1551
  addGlobalRules,
@@ -1744,13 +1573,10 @@ export {
1744
1573
  idAttribute,
1745
1574
  indexAttribute,
1746
1575
  namespaceMeta,
1576
+ normalizeProps,
1747
1577
  renderWebstudioComponentChildren,
1748
1578
  selectorIdAttribute,
1749
1579
  showAttribute,
1750
- splitPropsWithWebstudioAttributes,
1751
1580
  stateCategories,
1752
- useInstanceProps,
1753
- usePropAsset,
1754
- usePropUrl,
1755
1581
  validateExpression
1756
1582
  };
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { type ReadableAtom } from "nanostores";
3
- import type { Assets } from "@webstudio-is/sdk";
4
- import type { Pages, PropsByInstanceId } from "./props";
3
+ import type { Assets, Page } from "@webstudio-is/sdk";
4
+ import type { PropsByInstanceId } from "./props";
5
5
  import type { IndexesWithinAncestors } from "./instance-utils";
6
6
  import type { ImageLoader } from "@webstudio-is/image";
7
7
  export type Params = {
@@ -32,9 +32,14 @@ export type Params = {
32
32
  };
33
33
  export declare const ReactSdkContext: import("react").Context<Params & {
34
34
  imageLoader: ImageLoader;
35
+ /**
36
+ * List of pages paths for link component
37
+ * to navigate without reloading on published sites
38
+ * always empty for builder which handle anchor clicks globally
39
+ */
40
+ pagesPaths: Set<Page["path"]>;
35
41
  propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
36
42
  assetsStore: ReadableAtom<Assets>;
37
- pagesStore: ReadableAtom<Pages>;
38
43
  dataSourcesLogicStore: ReadableAtom<Map<string, unknown>>;
39
44
  indexesWithinAncestors: IndexesWithinAncestors;
40
45
  }>;
@@ -1,12 +1,8 @@
1
- import type { Props } from "@webstudio-is/sdk";
2
- import type { IndexesWithinAncestors } from "./instance-utils";
1
+ import type { Pages, Props } from "@webstudio-is/sdk";
3
2
  type PageData = {
3
+ pages: Pages;
4
4
  props: Props;
5
5
  };
6
- export type GeneratedUtils = {
7
- indexesWithinAncestors: IndexesWithinAncestors;
8
- getDataSourcesLogic: (getVariable: (id: string) => unknown, setVariable: (id: string, value: unknown) => void) => Map<string, unknown>;
9
- };
10
6
  /**
11
7
  * Generates data based utilities at build time
12
8
  */
@@ -5,7 +5,7 @@ export * from "./components/components-utils";
5
5
  export { PropMeta } from "./prop-meta";
6
6
  export { type WsComponentPropsMeta, type ComponentState, type PresetStyle, WsComponentMeta, componentCategories, stateCategories, defaultStates, } from "./components/component-meta";
7
7
  export * from "./embed-template";
8
- export { useInstanceProps, getPropsByInstanceId, usePropUrl, usePropAsset, getInstanceIdFromComponentProps, getIndexWithinAncestorFromComponentProps, } from "./props";
8
+ export { normalizeProps, getPropsByInstanceId, getInstanceIdFromComponentProps, getIndexWithinAncestorFromComponentProps, } from "./props";
9
9
  export { type Params, ReactSdkContext } from "./context";
10
10
  export { validateExpression, computeExpressionsDependencies, encodeDataSourceVariable, decodeDataSourceVariable, generateDataSources, } from "./expression";
11
11
  export { getIndexesWithinAncestors } from "./instance-utils";
@@ -1,7 +1,59 @@
1
- import type { Instance, Page, Prop, Asset, Assets } from "@webstudio-is/sdk";
1
+ import type { Instance, Page, Prop, Assets } from "@webstudio-is/sdk";
2
2
  export type PropsByInstanceId = Map<Instance["id"], Prop[]>;
3
3
  export type Pages = Map<Page["id"], Page>;
4
- export declare const getPropsByInstanceId: (props: Map<string, {
4
+ export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
5
+ props: Prop[];
6
+ assetBaseUrl: string;
7
+ assets: Map<string, {
8
+ type: "font";
9
+ name: string;
10
+ format: "ttf" | "woff" | "woff2" | "otf";
11
+ meta: ({
12
+ family: string;
13
+ style: "normal" | "italic" | "oblique";
14
+ weight: number;
15
+ } | {
16
+ family: string;
17
+ variationAxes: Partial<Record<"wght" | "wdth" | "slnt" | "opsz" | "ital" | "GRAD" | "XTRA" | "XOPQ" | "YOPQ" | "YTLC" | "YTUC" | "YTAS" | "YTDE" | "YTFI", {
18
+ name: string;
19
+ min: number;
20
+ default: number;
21
+ max: number;
22
+ }>>;
23
+ }) & ({
24
+ family: string;
25
+ style: "normal" | "italic" | "oblique";
26
+ weight: number;
27
+ } | {
28
+ family: string;
29
+ variationAxes: Partial<Record<"wght" | "wdth" | "slnt" | "opsz" | "ital" | "GRAD" | "XTRA" | "XOPQ" | "YOPQ" | "YTLC" | "YTUC" | "YTAS" | "YTDE" | "YTFI", {
30
+ name: string;
31
+ min: number;
32
+ default: number;
33
+ max: number;
34
+ }>>;
35
+ } | undefined);
36
+ id: string;
37
+ projectId: string;
38
+ size: number;
39
+ description: string | null;
40
+ createdAt: string;
41
+ } | {
42
+ type: "image";
43
+ name: string;
44
+ format: string;
45
+ meta: {
46
+ width: number;
47
+ height: number;
48
+ };
49
+ id: string;
50
+ projectId: string;
51
+ size: number;
52
+ description: string | null;
53
+ createdAt: string;
54
+ }>;
55
+ pages: Pages;
56
+ }) => ({
5
57
  value: number;
6
58
  type: "number";
7
59
  name: string;
@@ -67,130 +119,73 @@ export declare const getPropsByInstanceId: (props: Map<string, {
67
119
  id: string;
68
120
  instanceId: string;
69
121
  required?: boolean | undefined;
70
- }>) => PropsByInstanceId;
71
- export declare const useInstanceProps: (instanceId: Instance["id"]) => Record<string, unknown>;
72
- export declare const usePropAsset: (instanceId: Instance["id"], name: string) => {
73
- type: "font";
74
- name: string;
75
- format: "ttf" | "woff" | "woff2" | "otf";
76
- meta: ({
77
- family: string;
78
- style: "normal" | "italic" | "oblique";
79
- weight: number;
80
- } | {
81
- family: string;
82
- variationAxes: Partial<Record<"wght" | "wdth" | "slnt" | "opsz" | "ital" | "GRAD" | "XTRA" | "XOPQ" | "YOPQ" | "YTLC" | "YTUC" | "YTAS" | "YTDE" | "YTFI", {
83
- name: string;
84
- min: number;
85
- default: number;
86
- max: number;
87
- }>>;
88
- }) & ({
89
- family: string;
90
- style: "normal" | "italic" | "oblique";
91
- weight: number;
92
- } | {
93
- family: string;
94
- variationAxes: Partial<Record<"wght" | "wdth" | "slnt" | "opsz" | "ital" | "GRAD" | "XTRA" | "XOPQ" | "YOPQ" | "YTLC" | "YTUC" | "YTAS" | "YTDE" | "YTFI", {
95
- name: string;
96
- min: number;
97
- default: number;
98
- max: number;
99
- }>>;
100
- } | undefined);
122
+ })[];
123
+ export declare const getPropsByInstanceId: (props: Map<string, {
124
+ value: number;
125
+ type: "number";
126
+ name: string;
101
127
  id: string;
102
- projectId: string;
103
- size: number;
104
- description: string | null;
105
- createdAt: string;
128
+ instanceId: string;
129
+ required?: boolean | undefined;
106
130
  } | {
107
- type: "image";
108
- name: string;
109
- format: string;
110
- meta: {
111
- width: number;
112
- height: number;
113
- };
114
- id: string;
115
- projectId: string;
116
- size: number;
117
- description: string | null;
118
- createdAt: string;
119
- } | undefined;
120
- export declare const resolveUrlProp: (instanceId: Instance["id"], name: string, { props, pages, assets, }: {
121
- props: PropsByInstanceId;
122
- pages: Pages;
123
- assets: Map<string, {
124
- type: "font";
125
- name: string;
126
- format: "ttf" | "woff" | "woff2" | "otf";
127
- meta: ({
128
- family: string;
129
- style: "normal" | "italic" | "oblique";
130
- weight: number;
131
- } | {
132
- family: string;
133
- variationAxes: Partial<Record<"wght" | "wdth" | "slnt" | "opsz" | "ital" | "GRAD" | "XTRA" | "XOPQ" | "YOPQ" | "YTLC" | "YTUC" | "YTAS" | "YTDE" | "YTFI", {
134
- name: string;
135
- min: number;
136
- default: number;
137
- max: number;
138
- }>>;
139
- }) & ({
140
- family: string;
141
- style: "normal" | "italic" | "oblique";
142
- weight: number;
143
- } | {
144
- family: string;
145
- variationAxes: Partial<Record<"wght" | "wdth" | "slnt" | "opsz" | "ital" | "GRAD" | "XTRA" | "XOPQ" | "YOPQ" | "YTLC" | "YTUC" | "YTAS" | "YTDE" | "YTFI", {
146
- name: string;
147
- min: number;
148
- default: number;
149
- max: number;
150
- }>>;
151
- } | undefined);
152
- id: string;
153
- projectId: string;
154
- size: number;
155
- description: string | null;
156
- createdAt: string;
157
- } | {
158
- type: "image";
159
- name: string;
160
- format: string;
161
- meta: {
162
- width: number;
163
- height: number;
164
- };
165
- id: string;
166
- projectId: string;
167
- size: number;
168
- description: string | null;
169
- createdAt: string;
170
- }>;
171
- }) => {
172
- type: "page";
173
- page: Page;
174
- instanceId?: string | undefined;
175
- hash?: string | undefined;
131
+ value: string;
132
+ type: "string";
133
+ name: string;
134
+ id: string;
135
+ instanceId: string;
136
+ required?: boolean | undefined;
137
+ } | {
138
+ value: boolean;
139
+ type: "boolean";
140
+ name: string;
141
+ id: string;
142
+ instanceId: string;
143
+ required?: boolean | undefined;
176
144
  } | {
145
+ value: string;
177
146
  type: "asset";
178
- asset: Asset;
147
+ name: string;
148
+ id: string;
149
+ instanceId: string;
150
+ required?: boolean | undefined;
179
151
  } | {
180
- type: "string";
181
- url: string;
182
- } | undefined;
183
- export declare const usePropUrl: (instanceId: Instance["id"], name: string) => {
152
+ value: (string | {
153
+ instanceId: string;
154
+ pageId: string;
155
+ }) & (string | {
156
+ instanceId: string;
157
+ pageId: string;
158
+ } | undefined);
184
159
  type: "page";
185
- page: Page;
186
- instanceId?: string | undefined;
187
- hash?: string | undefined;
160
+ name: string;
161
+ id: string;
162
+ instanceId: string;
163
+ required?: boolean | undefined;
188
164
  } | {
189
- type: "asset";
190
- asset: Asset;
165
+ value: string[];
166
+ type: "string[]";
167
+ name: string;
168
+ id: string;
169
+ instanceId: string;
170
+ required?: boolean | undefined;
191
171
  } | {
192
- type: "string";
193
- url: string;
194
- } | undefined;
172
+ value: string;
173
+ type: "dataSource";
174
+ name: string;
175
+ id: string;
176
+ instanceId: string;
177
+ required?: boolean | undefined;
178
+ } | {
179
+ value: {
180
+ code: string;
181
+ type: "execute";
182
+ args: string[];
183
+ }[];
184
+ type: "action";
185
+ name: string;
186
+ id: string;
187
+ instanceId: string;
188
+ required?: boolean | undefined;
189
+ }>) => PropsByInstanceId;
195
190
  export declare const getInstanceIdFromComponentProps: (props: Record<string, unknown>) => string;
196
191
  export declare const getIndexWithinAncestorFromComponentProps: (props: Record<string, unknown>) => string | undefined;
@@ -3,11 +3,11 @@ import type { ReadableAtom } from "nanostores";
3
3
  import type { Instance, Instances, Assets } from "@webstudio-is/sdk";
4
4
  import type { Components } from "../components/components-utils";
5
5
  import { type Params } from "../context";
6
- import type { Pages, PropsByInstanceId } from "../props";
6
+ import type { 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, dataSourcesLogicStore, indexesWithinAncestors, Component, components, scripts, }: Params & {
10
+ export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl, imageLoader, instances, rootInstanceId, propsByInstanceIdStore, assetsStore, dataSourcesLogicStore, indexesWithinAncestors, Component, components, scripts, }: Params & {
11
11
  instances: Map<string, {
12
12
  type: "instance";
13
13
  id: string;
@@ -25,7 +25,6 @@ export declare const createElementsTree: ({ renderer, assetBaseUrl, imageBaseUrl
25
25
  rootInstanceId: Instance["id"];
26
26
  propsByInstanceIdStore: ReadableAtom<PropsByInstanceId>;
27
27
  assetsStore: ReadableAtom<Assets>;
28
- pagesStore: ReadableAtom<Pages>;
29
28
  dataSourcesLogicStore: ReadableAtom<Map<string, unknown>>;
30
29
  indexesWithinAncestors: IndexesWithinAncestors;
31
30
  Component: ForwardRefExoticComponent<WebstudioComponentProps & RefAttributes<HTMLElement>>;
@@ -1,3 +1,2 @@
1
1
  export * from "./create-elements-tree";
2
- export * from "./root";
3
2
  export * from "./webstudio-component";
@@ -8,18 +8,9 @@ export type WebstudioComponentProps = {
8
8
  children: Array<JSX.Element | string>;
9
9
  components: Components;
10
10
  };
11
- export declare const WebstudioComponent: import("react").ForwardRefExoticComponent<WebstudioComponentProps & import("react").RefAttributes<HTMLElement>>;
12
11
  export declare const idAttribute: "data-ws-id";
13
12
  export declare const selectorIdAttribute: "data-ws-selector";
14
13
  export declare const componentAttribute: "data-ws-component";
15
14
  export declare const showAttribute: "data-ws-show";
16
15
  export declare const indexAttribute: "data-ws-index";
17
16
  export declare const collapsedAttribute: "data-ws-collapsed";
18
- export type WebstudioAttributes = {
19
- [idAttribute]?: string | undefined;
20
- [selectorIdAttribute]?: string | undefined;
21
- [componentAttribute]?: string | undefined;
22
- [showAttribute]?: string | undefined;
23
- [collapsedAttribute]?: string | undefined;
24
- };
25
- export declare const splitPropsWithWebstudioAttributes: <P extends WebstudioAttributes>({ [idAttribute]: idAttributeValue, [componentAttribute]: componentAttributeValue, [showAttribute]: showAttributeValue, [collapsedAttribute]: collapsedAttributeValue, [selectorIdAttribute]: parentIdAttributeValue, ...props }: P) => [WebstudioAttributes, Omit<P, keyof WebstudioAttributes>];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.100.1-d89b38d.0",
3
+ "version": "0.101.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -17,8 +17,8 @@
17
17
  "type-fest": "^4.3.1",
18
18
  "typescript": "5.2.2",
19
19
  "zod": "^3.21.4",
20
- "@webstudio-is/jest-config": "1.0.8-d89b38d.0",
21
- "@webstudio-is/tsconfig": "1.0.8-d89b38d.0"
20
+ "@webstudio-is/jest-config": "1.0.7",
21
+ "@webstudio-is/tsconfig": "1.0.7"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@remix-run/react": "^1.19.1",
@@ -35,10 +35,10 @@
35
35
  "nanostores": "^0.9.3",
36
36
  "no-case": "^3.0.4",
37
37
  "title-case": "^3.0.3",
38
- "@webstudio-is/css-engine": "0.100.1-d89b38d.0",
39
- "@webstudio-is/fonts": "0.100.1-d89b38d.0",
40
- "@webstudio-is/image": "0.100.1-d89b38d.0",
41
- "@webstudio-is/sdk": "0.100.1-d89b38d.0"
38
+ "@webstudio-is/css-engine": "0.101.0",
39
+ "@webstudio-is/fonts": "0.101.0",
40
+ "@webstudio-is/image": "0.101.0",
41
+ "@webstudio-is/sdk": "0.101.0"
42
42
  },
43
43
  "exports": {
44
44
  ".": {
@@ -1,28 +0,0 @@
1
- import { type ForwardRefExoticComponent, type RefAttributes, type ReactNode } from "react";
2
- import type { Page, Asset, DataSource, Instance, Prop } from "@webstudio-is/sdk";
3
- import { type WebstudioComponentProps } from "./webstudio-component";
4
- import type { Components } from "../components/components-utils";
5
- import type { Params } from "../context";
6
- import type { GeneratedUtils } from "../generator";
7
- import type { ImageLoader } from "@webstudio-is/image";
8
- export type RootPropsData = {
9
- params?: Params;
10
- page: Page;
11
- pages: Array<Page>;
12
- assets: Array<Asset>;
13
- build: {
14
- instances: [Instance["id"], Instance][];
15
- dataSources: [DataSource["id"], DataSource][];
16
- props: [Prop["id"], Prop][];
17
- };
18
- };
19
- type RootProps = {
20
- data: RootPropsData;
21
- utils: GeneratedUtils;
22
- Component?: ForwardRefExoticComponent<WebstudioComponentProps & RefAttributes<HTMLElement>>;
23
- components: Components;
24
- scripts?: ReactNode;
25
- imageLoader: ImageLoader;
26
- };
27
- export declare const InstanceRoot: ({ data, utils, Component, components, scripts, imageLoader, }: RootProps) => JSX.Element | null;
28
- export {};