@webstudio-is/react-sdk 0.205.0 → 0.207.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
@@ -467,50 +467,6 @@ var namespaceMeta = (meta, namespace, components) => {
467
467
  return newMeta;
468
468
  };
469
469
 
470
- // src/instance-utils.ts
471
- var getIndexesWithinAncestors = (metas, instances, rootIds) => {
472
- const ancestors = /* @__PURE__ */ new Set();
473
- for (const meta of metas.values()) {
474
- if (meta.indexWithinAncestor !== void 0) {
475
- ancestors.add(meta.indexWithinAncestor);
476
- }
477
- }
478
- const indexes = /* @__PURE__ */ new Map();
479
- const traverseInstances = (instances2, instanceId, latestIndexes2 = /* @__PURE__ */ new Map()) => {
480
- const instance = instances2.get(instanceId);
481
- if (instance === void 0) {
482
- return;
483
- }
484
- const meta = metas.get(instance.component);
485
- if (meta === void 0) {
486
- return;
487
- }
488
- if (ancestors.has(instance.component)) {
489
- latestIndexes2 = new Map(latestIndexes2);
490
- latestIndexes2.set(instance.component, /* @__PURE__ */ new Map());
491
- }
492
- if (meta.indexWithinAncestor !== void 0) {
493
- const ancestorIndexes = latestIndexes2.get(meta.indexWithinAncestor);
494
- if (ancestorIndexes !== void 0) {
495
- let index = ancestorIndexes.get(instance.component) ?? -1;
496
- index += 1;
497
- ancestorIndexes.set(instance.component, index);
498
- indexes.set(instance.id, index);
499
- }
500
- }
501
- for (const child of instance.children) {
502
- if (child.type === "id") {
503
- traverseInstances(instances2, child.value, latestIndexes2);
504
- }
505
- }
506
- };
507
- const latestIndexes = /* @__PURE__ */ new Map();
508
- for (const instanceId of rootIds) {
509
- traverseInstances(instances, instanceId, latestIndexes);
510
- }
511
- return indexes;
512
- };
513
-
514
470
  // src/component-generator.ts
515
471
  import {
516
472
  parseComponentName,
@@ -520,7 +476,8 @@ import {
520
476
  blockComponent,
521
477
  blockTemplateComponent,
522
478
  collectionComponent,
523
- descendantComponent
479
+ descendantComponent,
480
+ getIndexesWithinAncestors
524
481
  } from "@webstudio-is/sdk";
525
482
  var generateAction = ({
526
483
  scope,
@@ -818,34 +775,37 @@ var generateWebstudioComponent = ({
818
775
  instances,
819
776
  props,
820
777
  dataSources,
821
- indexesWithinAncestors,
778
+ metas,
822
779
  classesMap
823
780
  }) => {
824
781
  const instance = instances.get(rootInstanceId);
825
- if (instance === void 0) {
826
- return "";
827
- }
782
+ const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
783
+ rootInstanceId
784
+ ]);
828
785
  const usedDataSources = /* @__PURE__ */ new Map();
829
- const generatedJsx = generateJsxElement({
830
- context: "expression",
831
- scope,
832
- instance,
833
- props,
834
- dataSources,
835
- usedDataSources,
836
- indexesWithinAncestors,
837
- classesMap,
838
- children: generateJsxChildren({
786
+ let generatedJsx = "<></>\n";
787
+ if (instance) {
788
+ generatedJsx = generateJsxElement({
789
+ context: "expression",
839
790
  scope,
840
- children: instance.children,
841
- instances,
791
+ instance,
842
792
  props,
843
793
  dataSources,
844
794
  usedDataSources,
845
795
  indexesWithinAncestors,
846
- classesMap
847
- })
848
- });
796
+ classesMap,
797
+ children: generateJsxChildren({
798
+ scope,
799
+ children: instance.children,
800
+ instances,
801
+ props,
802
+ dataSources,
803
+ usedDataSources,
804
+ indexesWithinAncestors,
805
+ classesMap
806
+ })
807
+ });
808
+ }
849
809
  let generatedProps = "";
850
810
  let generatedParameters = "";
851
811
  const uniqueParameters = new Set(
@@ -909,7 +869,6 @@ export {
909
869
  generateRemixParams,
910
870
  generateRemixRoute,
911
871
  generateWebstudioComponent,
912
- getIndexesWithinAncestors,
913
872
  idAttribute,
914
873
  indexAttribute,
915
874
  isAttributeNameSafe,
package/lib/runtime.js CHANGED
@@ -7,7 +7,8 @@ import {
7
7
  var ReactSdkContext = createContext({
8
8
  assetBaseUrl: "/",
9
9
  imageLoader: ({ src }) => src,
10
- resources: {}
10
+ resources: {},
11
+ breakpoints: []
11
12
  });
12
13
  var useResource = (name) => {
13
14
  const { resources } = useContext(ReactSdkContext);
@@ -1,5 +1,4 @@
1
- import type { Instances, Instance, Props, Scope, DataSources, Prop } from "@webstudio-is/sdk";
2
- import type { IndexesWithinAncestors } from "./instance-utils";
1
+ import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors } from "@webstudio-is/sdk";
3
2
  export declare const generateJsxElement: ({ context, scope, instance, props, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
4
3
  context?: "expression" | "jsx";
5
4
  scope: Scope;
@@ -22,7 +21,7 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
22
21
  classesMap?: Map<string, Array<string>>;
23
22
  excludePlaceholders?: boolean;
24
23
  }) => string;
25
- export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, indexesWithinAncestors, classesMap, }: {
24
+ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, metas, classesMap, }: {
26
25
  scope: Scope;
27
26
  name: string;
28
27
  rootInstanceId: Instance["id"];
@@ -32,6 +31,6 @@ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId,
32
31
  instances: Instances;
33
32
  props: Props;
34
33
  dataSources: DataSources;
35
- indexesWithinAncestors: IndexesWithinAncestors;
36
34
  classesMap: Map<string, Array<string>>;
35
+ metas: Map<Instance["component"], WsComponentMeta>;
37
36
  }) => string;
@@ -22,5 +22,10 @@ export type Params = {
22
22
  export declare const ReactSdkContext: import("react").Context<Params & {
23
23
  imageLoader: ImageLoader;
24
24
  resources: Record<string, any>;
25
+ breakpoints: {
26
+ id: string;
27
+ minWidth?: number;
28
+ maxWidth?: number;
29
+ }[];
25
30
  }>;
26
31
  export declare const useResource: (name: string) => any;
@@ -1,5 +1,4 @@
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;
@@ -3,6 +3,5 @@ export * from "./components/components-utils";
3
3
  export * from "./embed-template";
4
4
  export * from "./props";
5
5
  export type * from "./context";
6
- export { getIndexesWithinAncestors } from "./instance-utils";
7
6
  export type * from "./hook";
8
7
  export { generateWebstudioComponent, generateJsxElement, generateJsxChildren, } from "./component-generator";
@@ -394,6 +394,7 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, uploadingIm
394
394
  };
395
395
  name?: string | undefined;
396
396
  description?: string | undefined;
397
+ enabled?: [string, boolean][] | undefined;
397
398
  }[];
398
399
  source?: "closest" | "nearest" | "root" | undefined;
399
400
  axis?: "block" | "x" | "inline" | "y" | undefined;
@@ -699,6 +700,7 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, uploadingIm
699
700
  };
700
701
  name?: string | undefined;
701
702
  description?: string | undefined;
703
+ enabled?: [string, boolean][] | undefined;
702
704
  }[];
703
705
  subject?: string | undefined;
704
706
  axis?: "block" | "x" | "inline" | "y" | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.205.0",
3
+ "version": "0.207.0",
4
4
  "description": "Webstudio JavaScript / TypeScript API",
5
5
  "author": "Webstudio <github@webstudio.is>",
6
6
  "homepage": "https://webstudio.is",
@@ -11,10 +11,10 @@
11
11
  "react": "18.3.0-canary-14898b6a9-20240318",
12
12
  "react-dom": "18.3.0-canary-14898b6a9-20240318",
13
13
  "strip-indent": "^4.0.0",
14
- "type-fest": "^4.32.0",
15
- "vitest": "^3.0.4",
14
+ "type-fest": "^4.37.0",
15
+ "vitest": "^3.0.8",
16
16
  "zod": "^3.22.4",
17
- "@webstudio-is/template": "0.205.0",
17
+ "@webstudio-is/template": "0.207.0",
18
18
  "@webstudio-is/tsconfig": "1.0.7"
19
19
  },
20
20
  "peerDependencies": {
@@ -26,11 +26,11 @@
26
26
  "change-case": "^5.4.4",
27
27
  "html-tags": "^4.0.0",
28
28
  "nanoid": "^5.0.9",
29
- "@webstudio-is/css-engine": "0.205.0",
30
- "@webstudio-is/image": "0.205.0",
31
- "@webstudio-is/sdk": "0.205.0",
32
- "@webstudio-is/icons": "^0.205.0",
33
- "@webstudio-is/fonts": "0.205.0"
29
+ "@webstudio-is/css-engine": "0.207.0",
30
+ "@webstudio-is/fonts": "0.207.0",
31
+ "@webstudio-is/icons": "^0.207.0",
32
+ "@webstudio-is/image": "0.207.0",
33
+ "@webstudio-is/sdk": "0.207.0"
34
34
  },
35
35
  "exports": {
36
36
  ".": {
package/placeholder.d.ts CHANGED
@@ -5,21 +5,22 @@ declare module "__CONSTANTS__" {
5
5
  }
6
6
 
7
7
  declare module "__CLIENT__" {
8
- import type {
9
- FontAsset,
10
- ImageAsset,
11
- ResourceRequest,
12
- System,
13
- } from "@webstudio-is/sdk";
8
+ import type { ResourceRequest, System } from "@webstudio-is/sdk";
14
9
 
15
10
  export const siteName: string;
16
11
 
17
- export const favIconAsset: ImageAsset | undefined;
12
+ export const favIconAsset: string | undefined;
13
+
14
+ export const breakpoints: {
15
+ id: string;
16
+ minWidth?: number;
17
+ maxWidth?: number;
18
+ }[];
18
19
 
19
20
  // Font assets on current page (can be preloaded)
20
- export const pageFontAssets: FontAsset[];
21
+ export const pageFontAssets: string[];
21
22
 
22
- export const pageBackgroundImageAssets: ImageAsset[];
23
+ export const pageBackgroundImageAssets: string[];
23
24
 
24
25
  export const CustomCode: () => ReactNode;
25
26
 
@@ -1,3 +0,0 @@
1
- import type { Instance, Instances, WsComponentMeta } from "@webstudio-is/sdk";
2
- export type IndexesWithinAncestors = Map<Instance["id"], number>;
3
- export declare const getIndexesWithinAncestors: (metas: Map<Instance["component"], WsComponentMeta>, instances: Instances, rootIds: Instance["id"][]) => IndexesWithinAncestors;
@@ -1 +0,0 @@
1
- export {};