@webstudio-is/react-sdk 0.205.0 → 0.206.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,13 +775,16 @@ var generateWebstudioComponent = ({
|
|
|
818
775
|
instances,
|
|
819
776
|
props,
|
|
820
777
|
dataSources,
|
|
821
|
-
|
|
778
|
+
metas,
|
|
822
779
|
classesMap
|
|
823
780
|
}) => {
|
|
824
781
|
const instance = instances.get(rootInstanceId);
|
|
825
782
|
if (instance === void 0) {
|
|
826
783
|
return "";
|
|
827
784
|
}
|
|
785
|
+
const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [
|
|
786
|
+
rootInstanceId
|
|
787
|
+
]);
|
|
828
788
|
const usedDataSources = /* @__PURE__ */ new Map();
|
|
829
789
|
const generatedJsx = generateJsxElement({
|
|
830
790
|
context: "expression",
|
|
@@ -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,
|
|
@@ -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,
|
|
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;
|
package/lib/types/hook.d.ts
CHANGED
|
@@ -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;
|
package/lib/types/index.d.ts
CHANGED
|
@@ -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";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.206.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
"type-fest": "^4.32.0",
|
|
15
15
|
"vitest": "^3.0.4",
|
|
16
16
|
"zod": "^3.22.4",
|
|
17
|
-
"@webstudio-is/template": "0.
|
|
17
|
+
"@webstudio-is/template": "0.206.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.
|
|
30
|
-
"@webstudio-is/
|
|
31
|
-
"@webstudio-is/
|
|
32
|
-
"@webstudio-is/
|
|
33
|
-
"@webstudio-is/
|
|
29
|
+
"@webstudio-is/css-engine": "0.206.0",
|
|
30
|
+
"@webstudio-is/fonts": "0.206.0",
|
|
31
|
+
"@webstudio-is/icons": "^0.206.0",
|
|
32
|
+
"@webstudio-is/image": "0.206.0",
|
|
33
|
+
"@webstudio-is/sdk": "0.206.0"
|
|
34
34
|
},
|
|
35
35
|
"exports": {
|
|
36
36
|
".": {
|
package/placeholder.d.ts
CHANGED
|
@@ -5,21 +5,16 @@ 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:
|
|
12
|
+
export const favIconAsset: string | undefined;
|
|
18
13
|
|
|
19
14
|
// Font assets on current page (can be preloaded)
|
|
20
|
-
export const pageFontAssets:
|
|
15
|
+
export const pageFontAssets: string[];
|
|
21
16
|
|
|
22
|
-
export const pageBackgroundImageAssets:
|
|
17
|
+
export const pageBackgroundImageAssets: string[];
|
|
23
18
|
|
|
24
19
|
export const CustomCode: () => ReactNode;
|
|
25
20
|
|
|
@@ -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 {};
|