@webstudio-is/react-sdk 0.112.0 → 0.113.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 +42 -56
- package/lib/types/embed-template.d.ts +16 -28
- package/package.json +5 -5
package/lib/index.js
CHANGED
|
@@ -777,27 +777,15 @@ var EmbedTemplateText = z2.object({
|
|
|
777
777
|
type: z2.literal("text"),
|
|
778
778
|
value: z2.string()
|
|
779
779
|
});
|
|
780
|
-
var
|
|
781
|
-
z2.
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
])
|
|
789
|
-
}),
|
|
790
|
-
z2.object({
|
|
791
|
-
type: z2.literal("expression"),
|
|
792
|
-
code: z2.string()
|
|
793
|
-
})
|
|
794
|
-
]);
|
|
780
|
+
var EmbedTemplateVariable = z2.object({
|
|
781
|
+
initialValue: z2.union([
|
|
782
|
+
z2.string(),
|
|
783
|
+
z2.number(),
|
|
784
|
+
z2.boolean(),
|
|
785
|
+
z2.array(z2.string())
|
|
786
|
+
])
|
|
787
|
+
});
|
|
795
788
|
var EmbedTemplateProp = z2.union([
|
|
796
|
-
z2.object({
|
|
797
|
-
type: z2.literal("dataSource"),
|
|
798
|
-
name: z2.string(),
|
|
799
|
-
dataSourceName: z2.string()
|
|
800
|
-
}),
|
|
801
789
|
z2.object({
|
|
802
790
|
type: z2.literal("number"),
|
|
803
791
|
name: z2.string(),
|
|
@@ -818,6 +806,11 @@ var EmbedTemplateProp = z2.union([
|
|
|
818
806
|
name: z2.string(),
|
|
819
807
|
value: z2.array(z2.string())
|
|
820
808
|
}),
|
|
809
|
+
z2.object({
|
|
810
|
+
type: z2.literal("expression"),
|
|
811
|
+
name: z2.string(),
|
|
812
|
+
code: z2.string()
|
|
813
|
+
}),
|
|
821
814
|
z2.object({
|
|
822
815
|
type: z2.literal("action"),
|
|
823
816
|
name: z2.string(),
|
|
@@ -842,7 +835,7 @@ var EmbedTemplateInstance = z2.lazy(
|
|
|
842
835
|
type: z2.literal("instance"),
|
|
843
836
|
component: z2.string(),
|
|
844
837
|
label: z2.optional(z2.string()),
|
|
845
|
-
|
|
838
|
+
variables: z2.optional(z2.record(z2.string(), EmbedTemplateVariable)),
|
|
846
839
|
props: z2.optional(z2.array(EmbedTemplateProp)),
|
|
847
840
|
tokens: z2.optional(z2.array(z2.string())),
|
|
848
841
|
styles: z2.optional(z2.array(EmbedTemplateStyleDecl)),
|
|
@@ -852,7 +845,7 @@ var EmbedTemplateInstance = z2.lazy(
|
|
|
852
845
|
var WsEmbedTemplate = z2.lazy(
|
|
853
846
|
() => z2.array(z2.union([EmbedTemplateInstance, EmbedTemplateText]))
|
|
854
847
|
);
|
|
855
|
-
var
|
|
848
|
+
var getVariablValue = (value) => {
|
|
856
849
|
if (typeof value === "string") {
|
|
857
850
|
return { type: "string", value };
|
|
858
851
|
}
|
|
@@ -873,40 +866,47 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
|
|
|
873
866
|
for (const item of treeTemplate) {
|
|
874
867
|
if (item.type === "instance") {
|
|
875
868
|
const instanceId = generateId();
|
|
876
|
-
if (item.
|
|
877
|
-
for (const [name,
|
|
869
|
+
if (item.variables) {
|
|
870
|
+
for (const [name, variable] of Object.entries(item.variables)) {
|
|
878
871
|
if (dataSourceByRef.has(name)) {
|
|
879
872
|
throw Error(`${name} data source already defined`);
|
|
880
873
|
}
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
874
|
+
dataSourceByRef.set(name, {
|
|
875
|
+
type: "variable",
|
|
876
|
+
id: generateId(),
|
|
877
|
+
scopeInstanceId: instanceId,
|
|
878
|
+
name,
|
|
879
|
+
value: getVariablValue(variable.initialValue)
|
|
880
|
+
});
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
if (item.props) {
|
|
884
|
+
for (const prop of item.props) {
|
|
885
|
+
const propId = generateId();
|
|
886
|
+
if (prop.type === "expression") {
|
|
887
|
+
const dataSource = {
|
|
892
888
|
type: "expression",
|
|
893
889
|
id: generateId(),
|
|
894
890
|
scopeInstanceId: instanceId,
|
|
895
|
-
name,
|
|
891
|
+
name: "expression",
|
|
896
892
|
// replace all references with variable names
|
|
897
|
-
code: validateExpression(
|
|
893
|
+
code: validateExpression(prop.code, {
|
|
898
894
|
transformIdentifier: (ref) => {
|
|
899
895
|
const id = dataSourceByRef.get(ref)?.id ?? ref;
|
|
900
896
|
return encodeDataSourceVariable(id);
|
|
901
897
|
}
|
|
902
898
|
})
|
|
899
|
+
};
|
|
900
|
+
dataSourceByRef.set(propId, dataSource);
|
|
901
|
+
props.push({
|
|
902
|
+
id: propId,
|
|
903
|
+
instanceId,
|
|
904
|
+
type: "dataSource",
|
|
905
|
+
name: prop.name,
|
|
906
|
+
value: dataSource.id
|
|
903
907
|
});
|
|
908
|
+
continue;
|
|
904
909
|
}
|
|
905
|
-
}
|
|
906
|
-
}
|
|
907
|
-
if (item.props) {
|
|
908
|
-
for (const prop of item.props) {
|
|
909
|
-
const propId = generateId();
|
|
910
910
|
if (prop.type === "action") {
|
|
911
911
|
props.push({
|
|
912
912
|
id: propId,
|
|
@@ -934,20 +934,6 @@ var createInstancesFromTemplate = (treeTemplate, instances, props, dataSourceByR
|
|
|
934
934
|
});
|
|
935
935
|
continue;
|
|
936
936
|
}
|
|
937
|
-
if (prop.type === "dataSource") {
|
|
938
|
-
const dataSource = dataSourceByRef.get(prop.dataSourceName);
|
|
939
|
-
if (dataSource === void 0) {
|
|
940
|
-
throw Error(`${prop.dataSourceName} data source is not defined`);
|
|
941
|
-
}
|
|
942
|
-
props.push({
|
|
943
|
-
id: propId,
|
|
944
|
-
instanceId,
|
|
945
|
-
type: "dataSource",
|
|
946
|
-
name: prop.name,
|
|
947
|
-
value: dataSource.id
|
|
948
|
-
});
|
|
949
|
-
continue;
|
|
950
|
-
}
|
|
951
937
|
props.push({ id: propId, instanceId, ...prop });
|
|
952
938
|
}
|
|
953
939
|
}
|
|
@@ -14,39 +14,15 @@ declare const EmbedTemplateText: z.ZodObject<{
|
|
|
14
14
|
type: "text";
|
|
15
15
|
}>;
|
|
16
16
|
type EmbedTemplateText = z.infer<typeof EmbedTemplateText>;
|
|
17
|
-
declare const
|
|
18
|
-
type: z.ZodLiteral<"variable">;
|
|
17
|
+
declare const EmbedTemplateVariable: z.ZodObject<{
|
|
19
18
|
initialValue: z.ZodUnion<[z.ZodString, z.ZodNumber, z.ZodBoolean, z.ZodArray<z.ZodString, "many">]>;
|
|
20
19
|
}, "strip", z.ZodTypeAny, {
|
|
21
|
-
type: "variable";
|
|
22
20
|
initialValue: (string | number | boolean | string[]) & (string | number | boolean | string[] | undefined);
|
|
23
21
|
}, {
|
|
24
|
-
type: "variable";
|
|
25
22
|
initialValue: (string | number | boolean | string[]) & (string | number | boolean | string[] | undefined);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
code: z.ZodString;
|
|
29
|
-
}, "strip", z.ZodTypeAny, {
|
|
30
|
-
code: string;
|
|
31
|
-
type: "expression";
|
|
32
|
-
}, {
|
|
33
|
-
code: string;
|
|
34
|
-
type: "expression";
|
|
35
|
-
}>]>;
|
|
36
|
-
type EmbedTemplateDataSource = z.infer<typeof EmbedTemplateDataSource>;
|
|
23
|
+
}>;
|
|
24
|
+
type EmbedTemplateVariable = z.infer<typeof EmbedTemplateVariable>;
|
|
37
25
|
export declare const EmbedTemplateProp: z.ZodUnion<[z.ZodObject<{
|
|
38
|
-
type: z.ZodLiteral<"dataSource">;
|
|
39
|
-
name: z.ZodString;
|
|
40
|
-
dataSourceName: z.ZodString;
|
|
41
|
-
}, "strip", z.ZodTypeAny, {
|
|
42
|
-
type: "dataSource";
|
|
43
|
-
name: string;
|
|
44
|
-
dataSourceName: string;
|
|
45
|
-
}, {
|
|
46
|
-
type: "dataSource";
|
|
47
|
-
name: string;
|
|
48
|
-
dataSourceName: string;
|
|
49
|
-
}>, z.ZodObject<{
|
|
50
26
|
type: z.ZodLiteral<"number">;
|
|
51
27
|
name: z.ZodString;
|
|
52
28
|
value: z.ZodNumber;
|
|
@@ -94,6 +70,18 @@ export declare const EmbedTemplateProp: z.ZodUnion<[z.ZodObject<{
|
|
|
94
70
|
value: string[];
|
|
95
71
|
type: "string[]";
|
|
96
72
|
name: string;
|
|
73
|
+
}>, z.ZodObject<{
|
|
74
|
+
type: z.ZodLiteral<"expression">;
|
|
75
|
+
name: z.ZodString;
|
|
76
|
+
code: z.ZodString;
|
|
77
|
+
}, "strip", z.ZodTypeAny, {
|
|
78
|
+
code: string;
|
|
79
|
+
type: "expression";
|
|
80
|
+
name: string;
|
|
81
|
+
}, {
|
|
82
|
+
code: string;
|
|
83
|
+
type: "expression";
|
|
84
|
+
name: string;
|
|
97
85
|
}>, z.ZodObject<{
|
|
98
86
|
type: z.ZodLiteral<"action">;
|
|
99
87
|
name: z.ZodString;
|
|
@@ -2175,7 +2163,7 @@ export type EmbedTemplateInstance = {
|
|
|
2175
2163
|
type: "instance";
|
|
2176
2164
|
component: string;
|
|
2177
2165
|
label?: string;
|
|
2178
|
-
|
|
2166
|
+
variables?: Record<string, EmbedTemplateVariable>;
|
|
2179
2167
|
props?: EmbedTemplateProp[];
|
|
2180
2168
|
tokens?: string[];
|
|
2181
2169
|
styles?: EmbedTemplateStyleDecl[];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.113.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"jsep": "^1.3.8",
|
|
33
33
|
"nanoid": "^5.0.1",
|
|
34
34
|
"title-case": "^4.1.0",
|
|
35
|
-
"@webstudio-is/css-engine": "0.
|
|
36
|
-
"@webstudio-is/fonts": "0.
|
|
37
|
-
"@webstudio-is/image": "0.
|
|
38
|
-
"@webstudio-is/sdk": "0.
|
|
35
|
+
"@webstudio-is/css-engine": "0.113.0",
|
|
36
|
+
"@webstudio-is/fonts": "0.113.0",
|
|
37
|
+
"@webstudio-is/image": "0.113.0",
|
|
38
|
+
"@webstudio-is/sdk": "0.113.0"
|
|
39
39
|
},
|
|
40
40
|
"exports": {
|
|
41
41
|
".": {
|