@webstudio-is/react-sdk 0.291.0 → 0.293.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 +34 -6
- package/lib/types/component-generator.d.ts +7 -4
- package/package.json +8 -8
package/lib/index.js
CHANGED
|
@@ -548,6 +548,7 @@ var generateJsxElement = ({
|
|
|
548
548
|
tagsOverrides,
|
|
549
549
|
instance,
|
|
550
550
|
props,
|
|
551
|
+
resources,
|
|
551
552
|
dataSources,
|
|
552
553
|
usedDataSources,
|
|
553
554
|
indexesWithinAncestors,
|
|
@@ -574,10 +575,18 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
574
575
|
let collectionItemValue;
|
|
575
576
|
let collectionItemKeyValue;
|
|
576
577
|
let classNameValue;
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
578
|
+
const instanceProps = Array.from(props.values()).filter(
|
|
579
|
+
(prop) => prop.instanceId === instance.id
|
|
580
|
+
);
|
|
581
|
+
const instancePropNames = new Set(instanceProps.map((prop) => prop.name));
|
|
582
|
+
const projectedResourceProps = /* @__PURE__ */ new Map();
|
|
583
|
+
const getGeneratedPropName = (name) => {
|
|
584
|
+
if (hasTags && !meta?.props?.[name]) {
|
|
585
|
+
return standardAttributesToReactProps[name] ?? name;
|
|
580
586
|
}
|
|
587
|
+
return name;
|
|
588
|
+
};
|
|
589
|
+
for (const prop of instanceProps) {
|
|
581
590
|
const propValue = generatePropValue({
|
|
582
591
|
scope,
|
|
583
592
|
prop,
|
|
@@ -587,10 +596,18 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
587
596
|
if (isAttributeNameSafe(prop.name) === false) {
|
|
588
597
|
continue;
|
|
589
598
|
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
599
|
+
if (prop.type === "resource") {
|
|
600
|
+
const propMeta = meta?.props?.[prop.name];
|
|
601
|
+
const resource = resources?.get(prop.value);
|
|
602
|
+
if (propMeta?.type === "resource" && resource !== void 0) {
|
|
603
|
+
for (const name2 of propMeta.generatedProps ?? []) {
|
|
604
|
+
if (instancePropNames.has(name2) === false && isAttributeNameSafe(name2)) {
|
|
605
|
+
projectedResourceProps.set(name2, resource[name2]);
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
}
|
|
593
609
|
}
|
|
610
|
+
const name = getGeneratedPropName(prop.name);
|
|
594
611
|
if (prop.name === showAttribute) {
|
|
595
612
|
if (propValue === "true") {
|
|
596
613
|
continue;
|
|
@@ -622,6 +639,11 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
622
639
|
${name}={${propValue}}`;
|
|
623
640
|
}
|
|
624
641
|
}
|
|
642
|
+
for (const [propName, value] of projectedResourceProps) {
|
|
643
|
+
const name = getGeneratedPropName(propName);
|
|
644
|
+
generatedProps += `
|
|
645
|
+
${name}={${JSON.stringify(value)}}`;
|
|
646
|
+
}
|
|
625
647
|
const classMapArray = classesMap?.get(instance.id);
|
|
626
648
|
if (classMapArray || classNameValue) {
|
|
627
649
|
let classNameTemplate = classMapArray ? classMapArray.join(" ") : "";
|
|
@@ -716,6 +738,7 @@ var generateJsxChildren = ({
|
|
|
716
738
|
children,
|
|
717
739
|
instances,
|
|
718
740
|
props,
|
|
741
|
+
resources,
|
|
719
742
|
dataSources,
|
|
720
743
|
usedDataSources,
|
|
721
744
|
indexesWithinAncestors,
|
|
@@ -757,6 +780,7 @@ var generateJsxChildren = ({
|
|
|
757
780
|
tagsOverrides,
|
|
758
781
|
instance,
|
|
759
782
|
props,
|
|
783
|
+
resources,
|
|
760
784
|
dataSources,
|
|
761
785
|
usedDataSources,
|
|
762
786
|
indexesWithinAncestors,
|
|
@@ -769,6 +793,7 @@ var generateJsxChildren = ({
|
|
|
769
793
|
children: instance.children,
|
|
770
794
|
instances,
|
|
771
795
|
props,
|
|
796
|
+
resources,
|
|
772
797
|
dataSources,
|
|
773
798
|
usedDataSources,
|
|
774
799
|
indexesWithinAncestors,
|
|
@@ -788,6 +813,7 @@ var generateWebstudioComponent = ({
|
|
|
788
813
|
parameters,
|
|
789
814
|
instances,
|
|
790
815
|
props,
|
|
816
|
+
resources,
|
|
791
817
|
dataSources,
|
|
792
818
|
metas,
|
|
793
819
|
tagsOverrides,
|
|
@@ -807,6 +833,7 @@ var generateWebstudioComponent = ({
|
|
|
807
833
|
tagsOverrides,
|
|
808
834
|
instance,
|
|
809
835
|
props,
|
|
836
|
+
resources,
|
|
810
837
|
dataSources,
|
|
811
838
|
usedDataSources,
|
|
812
839
|
indexesWithinAncestors,
|
|
@@ -818,6 +845,7 @@ var generateWebstudioComponent = ({
|
|
|
818
845
|
children: instance.children,
|
|
819
846
|
instances,
|
|
820
847
|
props,
|
|
848
|
+
resources,
|
|
821
849
|
dataSources,
|
|
822
850
|
usedDataSources,
|
|
823
851
|
indexesWithinAncestors,
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors } from "@webstudio-is/sdk";
|
|
2
|
-
export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides, instance, props, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
|
|
1
|
+
import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors, Resources } from "@webstudio-is/sdk";
|
|
2
|
+
export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides, instance, props, resources, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
|
|
3
3
|
context?: "expression" | "jsx";
|
|
4
4
|
scope: Scope;
|
|
5
5
|
metas: Map<Instance["component"], WsComponentMeta>;
|
|
@@ -9,26 +9,28 @@ export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides
|
|
|
9
9
|
tagsOverrides?: Record<string, string>;
|
|
10
10
|
instance: Instance;
|
|
11
11
|
props: Props;
|
|
12
|
+
resources?: Resources;
|
|
12
13
|
dataSources: DataSources;
|
|
13
14
|
usedDataSources: DataSources;
|
|
14
15
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
15
16
|
children: string;
|
|
16
17
|
classesMap?: Map<string, Array<string>>;
|
|
17
18
|
}) => string;
|
|
18
|
-
export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, }: {
|
|
19
|
+
export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, resources, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, }: {
|
|
19
20
|
scope: Scope;
|
|
20
21
|
metas: Map<Instance["component"], WsComponentMeta>;
|
|
21
22
|
tagsOverrides?: Record<string, string>;
|
|
22
23
|
children: Instance["children"];
|
|
23
24
|
instances: Instances;
|
|
24
25
|
props: Props;
|
|
26
|
+
resources?: Resources;
|
|
25
27
|
dataSources: DataSources;
|
|
26
28
|
usedDataSources: DataSources;
|
|
27
29
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
28
30
|
classesMap?: Map<string, Array<string>>;
|
|
29
31
|
excludePlaceholders?: boolean;
|
|
30
32
|
}) => string;
|
|
31
|
-
export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, metas, tagsOverrides, classesMap, }: {
|
|
33
|
+
export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, resources, dataSources, metas, tagsOverrides, classesMap, }: {
|
|
32
34
|
scope: Scope;
|
|
33
35
|
name: string;
|
|
34
36
|
rootInstanceId: Instance["id"];
|
|
@@ -37,6 +39,7 @@ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId,
|
|
|
37
39
|
}>[];
|
|
38
40
|
instances: Instances;
|
|
39
41
|
props: Props;
|
|
42
|
+
resources?: Resources;
|
|
40
43
|
dataSources: DataSources;
|
|
41
44
|
classesMap: Map<string, Array<string>>;
|
|
42
45
|
metas: Map<Instance["component"], WsComponentMeta>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.293.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
"typescript": "7.0.2",
|
|
16
16
|
"vitest": "^3.1.2",
|
|
17
17
|
"zod": "^4.4.3",
|
|
18
|
-
"@webstudio-is/template": "0.
|
|
18
|
+
"@webstudio-is/template": "0.293.0",
|
|
19
19
|
"@webstudio-is/tsconfig": "1.0.7"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
@@ -26,12 +26,12 @@
|
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"change-case": "^5.4.4",
|
|
28
28
|
"nanoid": "^5.1.5",
|
|
29
|
-
"@webstudio-is/css-engine": "0.
|
|
30
|
-
"@webstudio-is/expression": "0.
|
|
31
|
-
"@webstudio-is/
|
|
32
|
-
"@webstudio-is/
|
|
33
|
-
"@webstudio-is/icons": "^0.
|
|
34
|
-
"@webstudio-is/
|
|
29
|
+
"@webstudio-is/css-engine": "0.293.0",
|
|
30
|
+
"@webstudio-is/expression": "0.293.0",
|
|
31
|
+
"@webstudio-is/image": "0.293.0",
|
|
32
|
+
"@webstudio-is/sdk": "0.293.0",
|
|
33
|
+
"@webstudio-is/icons": "^0.293.0",
|
|
34
|
+
"@webstudio-is/fonts": "0.293.0"
|
|
35
35
|
},
|
|
36
36
|
"exports": {
|
|
37
37
|
".": {
|