@webstudio-is/react-sdk 0.100.1-c4ae8b2.0 → 0.100.1-d89b38d.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
@@ -1504,61 +1504,7 @@ var getClosestInstance = (instancePath, currentInstance, closestComponent) => {
1504
1504
  };
1505
1505
 
1506
1506
  // src/generator.ts
1507
- import {
1508
- createScope
1509
- } from "@webstudio-is/sdk";
1510
1507
  var generateUtilsExport = (siteData) => {
1511
- const indexesWithinAncestors = getIndexesWithinAncestors(
1512
- siteData.metas,
1513
- siteData.instances,
1514
- [siteData.page.rootInstanceId]
1515
- );
1516
- let indexesWithinAncestorsEntries = "";
1517
- for (const [key, value] of indexesWithinAncestors) {
1518
- const keyString = JSON.stringify(key);
1519
- const valueString = JSON.stringify(value);
1520
- indexesWithinAncestorsEntries += `[${keyString}, ${valueString}],
1521
- `;
1522
- }
1523
- const generatedIndexesWithinAncestors = `
1524
- const indexesWithinAncestors = new Map<string, number>([
1525
- ${indexesWithinAncestorsEntries}
1526
- ]);
1527
- `;
1528
- const { variables, body, output } = generateDataSources({
1529
- scope: createScope(["_getVariable", "_setVariable", "_output"]),
1530
- typed: true,
1531
- dataSources: siteData.dataSources,
1532
- props: siteData.props
1533
- });
1534
- let generatedDataSources = "";
1535
- generatedDataSources += `const getDataSourcesLogic = (
1536
- `;
1537
- generatedDataSources += ` _getVariable: (id: string) => unknown,
1538
- `;
1539
- generatedDataSources += ` _setVariable: (id: string, value: unknown) => void
1540
- `;
1541
- generatedDataSources += `) => {
1542
- `;
1543
- for (const [dataSourceId, variable] of variables) {
1544
- const { valueName, setterName } = variable;
1545
- const initialValue = JSON.stringify(variable.initialValue);
1546
- generatedDataSources += `let ${valueName} = _getVariable("${dataSourceId}") ?? ${initialValue};
1547
- `;
1548
- generatedDataSources += `let ${setterName} = (value: unknown) => _setVariable("${dataSourceId}", value);
1549
- `;
1550
- }
1551
- generatedDataSources += body;
1552
- generatedDataSources += `let _output = new Map();
1553
- `;
1554
- for (const [dataSourceId, variableName] of output) {
1555
- generatedDataSources += `_output.set('${dataSourceId}', ${variableName})
1556
- `;
1557
- }
1558
- generatedDataSources += `return _output
1559
- `;
1560
- generatedDataSources += `}
1561
- `;
1562
1508
  const formsProperties = /* @__PURE__ */ new Map();
1563
1509
  for (const prop of siteData.props.values()) {
1564
1510
  if (prop.type === "string") {
@@ -1576,20 +1522,7 @@ var generateUtilsExport = (siteData) => {
1576
1522
  Array.from(formsProperties.entries())
1577
1523
  )})`;
1578
1524
  return `
1579
- /* eslint-disable */
1580
-
1581
- ${generatedIndexesWithinAncestors.trim()}
1582
-
1583
- ${generatedDataSources}
1584
-
1585
1525
  ${generatedFormsProperties}
1586
-
1587
- export const utils = {
1588
- indexesWithinAncestors,
1589
- getDataSourcesLogic,
1590
- };
1591
-
1592
- /* eslint-enable */
1593
1526
  `;
1594
1527
  };
1595
1528
 
@@ -1748,7 +1681,7 @@ var generatePageComponent = ({
1748
1681
  let generatedDataSources = "";
1749
1682
  for (const { valueName, setterName, initialValue } of variables.values()) {
1750
1683
  const initialValueString = JSON.stringify(initialValue);
1751
- generatedDataSources += `let [${valueName}, ${setterName}] = useState(${initialValueString})
1684
+ generatedDataSources += `let [${valueName}, ${setterName}] = useState<any>(${initialValueString})
1752
1685
  `;
1753
1686
  }
1754
1687
  generatedDataSources += dataSourcesBody;
@@ -1806,6 +1739,7 @@ export {
1806
1739
  getIndexesWithinAncestors,
1807
1740
  getInstanceIdFromComponentProps,
1808
1741
  getPresetStyleRules,
1742
+ getPropsByInstanceId,
1809
1743
  getStyleRules,
1810
1744
  idAttribute,
1811
1745
  indexAttribute,
@@ -1,12 +1,7 @@
1
- import { type DataSources, type Instance, type Instances, type Page, type Props } from "@webstudio-is/sdk";
2
- import type { WsComponentMeta } from "./components/component-meta";
3
- import { type IndexesWithinAncestors } from "./instance-utils";
1
+ import type { Props } from "@webstudio-is/sdk";
2
+ import type { IndexesWithinAncestors } from "./instance-utils";
4
3
  type PageData = {
5
- page: Page;
6
- metas: Map<Instance["component"], WsComponentMeta>;
7
- instances: Instances;
8
4
  props: Props;
9
- dataSources: DataSources;
10
5
  };
11
6
  export type GeneratedUtils = {
12
7
  indexesWithinAncestors: IndexesWithinAncestors;
@@ -14,8 +9,6 @@ export type GeneratedUtils = {
14
9
  };
15
10
  /**
16
11
  * Generates data based utilities at build time
17
- * Requires this import statement in scope
18
- * import * as sdk from "@webstudio-is/react-sdk";
19
12
  */
20
13
  export declare const generateUtilsExport: (siteData: PageData) => string;
21
14
  export {};
@@ -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, usePropUrl, usePropAsset, getInstanceIdFromComponentProps, getIndexWithinAncestorFromComponentProps, } from "./props";
8
+ export { useInstanceProps, getPropsByInstanceId, usePropUrl, usePropAsset, 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";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.100.1-c4ae8b2.0",
3
+ "version": "0.100.1-d89b38d.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-c4ae8b2.0",
21
- "@webstudio-is/tsconfig": "1.0.8-c4ae8b2.0"
20
+ "@webstudio-is/jest-config": "1.0.8-d89b38d.0",
21
+ "@webstudio-is/tsconfig": "1.0.8-d89b38d.0"
22
22
  },
23
23
  "peerDependencies": {
24
24
  "@remix-run/react": "^1.19.1",
@@ -35,20 +35,20 @@
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-c4ae8b2.0",
39
- "@webstudio-is/fonts": "0.100.1-c4ae8b2.0",
40
- "@webstudio-is/image": "0.100.1-c4ae8b2.0",
41
- "@webstudio-is/sdk": "0.100.1-c4ae8b2.0"
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"
42
42
  },
43
43
  "exports": {
44
44
  ".": {
45
- "source": "./src/index.ts",
45
+ "webstudio": "./src/index.ts",
46
46
  "types": "./lib/types/index.d.ts",
47
47
  "import": "./lib/index.js",
48
48
  "require": "./lib/index.js"
49
49
  },
50
50
  "./css-normalize": {
51
- "source": "./src/css/normalize.ts",
51
+ "webstudio": "./src/css/normalize.ts",
52
52
  "types": "./lib/types/css/normalize.d.ts",
53
53
  "import": "./lib/css/normalize.js",
54
54
  "require": "./lib/css/normalize.js"