@webstudio-is/react-sdk 0.117.0 → 0.118.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 +41 -99
- package/lib/types/component-generator.d.ts +0 -39
- package/lib/types/embed-template.d.ts +2 -15
- package/lib/types/expression.d.ts +0 -13
- package/lib/types/props.d.ts +0 -14
- package/package.json +7 -7
package/lib/index.js
CHANGED
|
@@ -618,45 +618,6 @@ var generateDataSources = ({
|
|
|
618
618
|
}
|
|
619
619
|
}
|
|
620
620
|
for (const prop of props.values()) {
|
|
621
|
-
if (prop.type === "dataSource") {
|
|
622
|
-
const dataSource = dataSources.get(prop.value);
|
|
623
|
-
if (dataSource?.type !== "expression") {
|
|
624
|
-
continue;
|
|
625
|
-
}
|
|
626
|
-
const name = scope.getName(prop.id, prop.name);
|
|
627
|
-
output.set(prop.id, name);
|
|
628
|
-
const code = validateExpression(dataSource.code, {
|
|
629
|
-
optional: true,
|
|
630
|
-
transformIdentifier: (identifier) => {
|
|
631
|
-
const depId = decodeDataSourceVariable(identifier);
|
|
632
|
-
const dep = depId ? dataSources.get(depId) : void 0;
|
|
633
|
-
if (dep) {
|
|
634
|
-
return scope.getName(dep.id, dep.name);
|
|
635
|
-
}
|
|
636
|
-
console.error(`Unknown dependency "${identifier}"`);
|
|
637
|
-
return identifier;
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
body += `let ${name} = (${code});
|
|
641
|
-
`;
|
|
642
|
-
}
|
|
643
|
-
if (prop.type === "expression") {
|
|
644
|
-
const name = scope.getName(prop.id, prop.name);
|
|
645
|
-
output.set(prop.id, name);
|
|
646
|
-
const code = validateExpression(prop.value, {
|
|
647
|
-
transformIdentifier: (identifier) => {
|
|
648
|
-
const depId = decodeDataSourceVariable(identifier);
|
|
649
|
-
const dep = depId ? dataSources.get(depId) : void 0;
|
|
650
|
-
if (dep) {
|
|
651
|
-
return scope.getName(dep.id, dep.name);
|
|
652
|
-
}
|
|
653
|
-
console.error(`Unknown dependency "${identifier}"`);
|
|
654
|
-
return identifier;
|
|
655
|
-
}
|
|
656
|
-
});
|
|
657
|
-
body += `let ${name} = (${code});
|
|
658
|
-
`;
|
|
659
|
-
}
|
|
660
621
|
if (prop.type === "action") {
|
|
661
622
|
const name = scope.getName(prop.id, prop.name);
|
|
662
623
|
output.set(prop.id, name);
|
|
@@ -1265,6 +1226,36 @@ var generateUtilsExport = (siteData) => {
|
|
|
1265
1226
|
|
|
1266
1227
|
// src/component-generator.ts
|
|
1267
1228
|
import { parseComponentName } from "@webstudio-is/sdk";
|
|
1229
|
+
var generatePropValue = ({
|
|
1230
|
+
scope,
|
|
1231
|
+
prop,
|
|
1232
|
+
dataSources
|
|
1233
|
+
}) => {
|
|
1234
|
+
if (prop.type === "asset" || prop.type === "page") {
|
|
1235
|
+
return;
|
|
1236
|
+
}
|
|
1237
|
+
if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
|
|
1238
|
+
return JSON.stringify(prop.value);
|
|
1239
|
+
}
|
|
1240
|
+
if (prop.type === "expression") {
|
|
1241
|
+
return validateExpression(prop.value, {
|
|
1242
|
+
// transpile to safely executable member expressions
|
|
1243
|
+
optional: true,
|
|
1244
|
+
transformIdentifier: (identifier) => {
|
|
1245
|
+
const depId = decodeDataSourceVariable(identifier);
|
|
1246
|
+
const dep = depId ? dataSources.get(depId) : void 0;
|
|
1247
|
+
if (dep) {
|
|
1248
|
+
return scope.getName(dep.id, dep.name);
|
|
1249
|
+
}
|
|
1250
|
+
return identifier;
|
|
1251
|
+
}
|
|
1252
|
+
});
|
|
1253
|
+
}
|
|
1254
|
+
if (prop.type === "action") {
|
|
1255
|
+
return scope.getName(prop.id, prop.name);
|
|
1256
|
+
}
|
|
1257
|
+
prop;
|
|
1258
|
+
};
|
|
1268
1259
|
var generateJsxElement = ({
|
|
1269
1260
|
scope,
|
|
1270
1261
|
instance,
|
|
@@ -1273,7 +1264,7 @@ var generateJsxElement = ({
|
|
|
1273
1264
|
indexesWithinAncestors,
|
|
1274
1265
|
children
|
|
1275
1266
|
}) => {
|
|
1276
|
-
let
|
|
1267
|
+
let conditionValue;
|
|
1277
1268
|
let generatedProps = "";
|
|
1278
1269
|
generatedProps += `
|
|
1279
1270
|
${idAttribute}=${JSON.stringify(instance.id)}`;
|
|
@@ -1290,74 +1281,25 @@ ${indexAttribute}="${index}"`;
|
|
|
1290
1281
|
if (prop.instanceId !== instance.id) {
|
|
1291
1282
|
continue;
|
|
1292
1283
|
}
|
|
1284
|
+
const propValue = generatePropValue({ scope, prop, dataSources });
|
|
1293
1285
|
if (prop.name === showAttribute) {
|
|
1294
|
-
if (
|
|
1295
|
-
return "";
|
|
1296
|
-
}
|
|
1297
|
-
if (prop.type === "dataSource") {
|
|
1298
|
-
const dataSourceId = prop.value;
|
|
1299
|
-
const dataSource = dataSources.get(dataSourceId);
|
|
1300
|
-
if (dataSource === void 0) {
|
|
1301
|
-
continue;
|
|
1302
|
-
}
|
|
1303
|
-
if (dataSource.type === "variable") {
|
|
1304
|
-
conditionVariableName = scope.getName(dataSource.id, dataSource.name);
|
|
1305
|
-
}
|
|
1306
|
-
if (dataSource.type === "expression") {
|
|
1307
|
-
conditionVariableName = scope.getName(prop.id, prop.name);
|
|
1308
|
-
}
|
|
1309
|
-
}
|
|
1310
|
-
if (prop.type === "expression") {
|
|
1311
|
-
conditionVariableName = scope.getName(prop.id, prop.name);
|
|
1312
|
-
}
|
|
1313
|
-
continue;
|
|
1314
|
-
}
|
|
1315
|
-
if (prop.type === "string" || prop.type === "number" || prop.type === "boolean" || prop.type === "string[]" || prop.type === "json") {
|
|
1316
|
-
generatedProps += `
|
|
1317
|
-
${prop.name}={${JSON.stringify(prop.value)}}`;
|
|
1318
|
-
continue;
|
|
1319
|
-
}
|
|
1320
|
-
if (prop.type === "asset" || prop.type === "page") {
|
|
1321
|
-
continue;
|
|
1322
|
-
}
|
|
1323
|
-
if (prop.type === "dataSource") {
|
|
1324
|
-
const dataSourceId = prop.value;
|
|
1325
|
-
const dataSource = dataSources.get(dataSourceId);
|
|
1326
|
-
if (dataSource === void 0) {
|
|
1286
|
+
if (propValue === "true") {
|
|
1327
1287
|
continue;
|
|
1328
1288
|
}
|
|
1329
|
-
if (
|
|
1330
|
-
|
|
1331
|
-
dataSource.id,
|
|
1332
|
-
dataSource.name
|
|
1333
|
-
);
|
|
1334
|
-
generatedProps += `
|
|
1335
|
-
${prop.name}={${dataSourceVariable}}`;
|
|
1336
|
-
}
|
|
1337
|
-
if (dataSource.type === "expression") {
|
|
1338
|
-
const dataSourceVariable = scope.getName(prop.id, prop.name);
|
|
1339
|
-
generatedProps += `
|
|
1340
|
-
${prop.name}={${dataSourceVariable}}`;
|
|
1289
|
+
if (propValue === "false") {
|
|
1290
|
+
return "";
|
|
1341
1291
|
}
|
|
1292
|
+
conditionValue = propValue;
|
|
1342
1293
|
continue;
|
|
1343
1294
|
}
|
|
1344
|
-
if (
|
|
1345
|
-
const propVariable = scope.getName(prop.id, prop.name);
|
|
1346
|
-
generatedProps += `
|
|
1347
|
-
${prop.name}={${propVariable}}`;
|
|
1348
|
-
continue;
|
|
1349
|
-
}
|
|
1350
|
-
if (prop.type === "action") {
|
|
1351
|
-
const propVariable = scope.getName(prop.id, prop.name);
|
|
1295
|
+
if (propValue !== void 0) {
|
|
1352
1296
|
generatedProps += `
|
|
1353
|
-
${prop.name}={${
|
|
1354
|
-
continue;
|
|
1297
|
+
${prop.name}={${propValue}}`;
|
|
1355
1298
|
}
|
|
1356
|
-
prop;
|
|
1357
1299
|
}
|
|
1358
1300
|
let generatedElement = "";
|
|
1359
|
-
if (
|
|
1360
|
-
generatedElement += `{${
|
|
1301
|
+
if (conditionValue) {
|
|
1302
|
+
generatedElement += `{(${conditionValue}) &&
|
|
1361
1303
|
`;
|
|
1362
1304
|
}
|
|
1363
1305
|
const [_namespace, shortName] = parseComponentName(instance.component);
|
|
@@ -1372,7 +1314,7 @@ ${prop.name}={${propVariable}}`;
|
|
|
1372
1314
|
generatedElement += `</${componentVariable}>
|
|
1373
1315
|
`;
|
|
1374
1316
|
}
|
|
1375
|
-
if (
|
|
1317
|
+
if (conditionValue) {
|
|
1376
1318
|
generatedElement += `}
|
|
1377
1319
|
`;
|
|
1378
1320
|
}
|
|
@@ -58,13 +58,6 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
|
|
|
58
58
|
id: string;
|
|
59
59
|
instanceId: string;
|
|
60
60
|
required?: boolean | undefined;
|
|
61
|
-
} | {
|
|
62
|
-
value: string;
|
|
63
|
-
type: "dataSource";
|
|
64
|
-
name: string;
|
|
65
|
-
id: string;
|
|
66
|
-
instanceId: string;
|
|
67
|
-
required?: boolean | undefined;
|
|
68
61
|
} | {
|
|
69
62
|
value: string;
|
|
70
63
|
type: "expression";
|
|
@@ -105,12 +98,6 @@ export declare const generateJsxElement: ({ scope, instance, props, dataSources,
|
|
|
105
98
|
name: string;
|
|
106
99
|
id: string;
|
|
107
100
|
scopeInstanceId?: string | undefined;
|
|
108
|
-
} | {
|
|
109
|
-
code: string;
|
|
110
|
-
type: "expression";
|
|
111
|
-
name: string;
|
|
112
|
-
id: string;
|
|
113
|
-
scopeInstanceId?: string | undefined;
|
|
114
101
|
}>;
|
|
115
102
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
116
103
|
children: string;
|
|
@@ -190,13 +177,6 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
|
|
|
190
177
|
id: string;
|
|
191
178
|
instanceId: string;
|
|
192
179
|
required?: boolean | undefined;
|
|
193
|
-
} | {
|
|
194
|
-
value: string;
|
|
195
|
-
type: "dataSource";
|
|
196
|
-
name: string;
|
|
197
|
-
id: string;
|
|
198
|
-
instanceId: string;
|
|
199
|
-
required?: boolean | undefined;
|
|
200
180
|
} | {
|
|
201
181
|
value: string;
|
|
202
182
|
type: "expression";
|
|
@@ -237,12 +217,6 @@ export declare const generateJsxChildren: ({ scope, children, instances, props,
|
|
|
237
217
|
name: string;
|
|
238
218
|
id: string;
|
|
239
219
|
scopeInstanceId?: string | undefined;
|
|
240
|
-
} | {
|
|
241
|
-
code: string;
|
|
242
|
-
type: "expression";
|
|
243
|
-
name: string;
|
|
244
|
-
id: string;
|
|
245
|
-
scopeInstanceId?: string | undefined;
|
|
246
220
|
}>;
|
|
247
221
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
248
222
|
}) => string;
|
|
@@ -317,13 +291,6 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
|
|
|
317
291
|
id: string;
|
|
318
292
|
instanceId: string;
|
|
319
293
|
required?: boolean | undefined;
|
|
320
|
-
} | {
|
|
321
|
-
value: string;
|
|
322
|
-
type: "dataSource";
|
|
323
|
-
name: string;
|
|
324
|
-
id: string;
|
|
325
|
-
instanceId: string;
|
|
326
|
-
required?: boolean | undefined;
|
|
327
294
|
} | {
|
|
328
295
|
value: string;
|
|
329
296
|
type: "expression";
|
|
@@ -364,12 +331,6 @@ export declare const generatePageComponent: ({ scope, rootInstanceId, instances,
|
|
|
364
331
|
name: string;
|
|
365
332
|
id: string;
|
|
366
333
|
scopeInstanceId?: string | undefined;
|
|
367
|
-
} | {
|
|
368
|
-
code: string;
|
|
369
|
-
type: "expression";
|
|
370
|
-
name: string;
|
|
371
|
-
id: string;
|
|
372
|
-
scopeInstanceId?: string | undefined;
|
|
373
334
|
}>;
|
|
374
335
|
indexesWithinAncestors: IndexesWithinAncestors;
|
|
375
336
|
}) => string;
|
|
@@ -2260,13 +2260,6 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
|
|
|
2260
2260
|
id: string;
|
|
2261
2261
|
instanceId: string;
|
|
2262
2262
|
required?: boolean | undefined;
|
|
2263
|
-
} | {
|
|
2264
|
-
value: string;
|
|
2265
|
-
type: "dataSource";
|
|
2266
|
-
name: string;
|
|
2267
|
-
id: string;
|
|
2268
|
-
instanceId: string;
|
|
2269
|
-
required?: boolean | undefined;
|
|
2270
2263
|
} | {
|
|
2271
2264
|
value: string;
|
|
2272
2265
|
type: "expression";
|
|
@@ -2286,7 +2279,7 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
|
|
|
2286
2279
|
instanceId: string;
|
|
2287
2280
|
required?: boolean | undefined;
|
|
2288
2281
|
})[];
|
|
2289
|
-
dataSources:
|
|
2282
|
+
dataSources: {
|
|
2290
2283
|
value: {
|
|
2291
2284
|
value: number;
|
|
2292
2285
|
type: "number";
|
|
@@ -2307,13 +2300,7 @@ export declare const generateDataFromEmbedTemplate: (treeTemplate: ({
|
|
|
2307
2300
|
name: string;
|
|
2308
2301
|
id: string;
|
|
2309
2302
|
scopeInstanceId?: string | undefined;
|
|
2310
|
-
}
|
|
2311
|
-
code: string;
|
|
2312
|
-
type: "expression";
|
|
2313
|
-
name: string;
|
|
2314
|
-
id: string;
|
|
2315
|
-
scopeInstanceId?: string | undefined;
|
|
2316
|
-
})[];
|
|
2303
|
+
}[];
|
|
2317
2304
|
styleSourceSelections: {
|
|
2318
2305
|
values: string[];
|
|
2319
2306
|
instanceId: string;
|
|
@@ -39,12 +39,6 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
|
|
|
39
39
|
name: string;
|
|
40
40
|
id: string;
|
|
41
41
|
scopeInstanceId?: string | undefined;
|
|
42
|
-
} | {
|
|
43
|
-
code: string;
|
|
44
|
-
type: "expression";
|
|
45
|
-
name: string;
|
|
46
|
-
id: string;
|
|
47
|
-
scopeInstanceId?: string | undefined;
|
|
48
42
|
}>;
|
|
49
43
|
props: Map<string, {
|
|
50
44
|
value: number;
|
|
@@ -101,13 +95,6 @@ export declare const generateDataSources: ({ scope, typed, dataSources, props, }
|
|
|
101
95
|
id: string;
|
|
102
96
|
instanceId: string;
|
|
103
97
|
required?: boolean | undefined;
|
|
104
|
-
} | {
|
|
105
|
-
value: string;
|
|
106
|
-
type: "dataSource";
|
|
107
|
-
name: string;
|
|
108
|
-
id: string;
|
|
109
|
-
instanceId: string;
|
|
110
|
-
required?: boolean | undefined;
|
|
111
98
|
} | {
|
|
112
99
|
value: string;
|
|
113
100
|
type: "expression";
|
package/lib/types/props.d.ts
CHANGED
|
@@ -108,13 +108,6 @@ export declare const normalizeProps: ({ props, assetBaseUrl, assets, pages, }: {
|
|
|
108
108
|
id: string;
|
|
109
109
|
instanceId: string;
|
|
110
110
|
required?: boolean | undefined;
|
|
111
|
-
} | {
|
|
112
|
-
value: string;
|
|
113
|
-
type: "dataSource";
|
|
114
|
-
name: string;
|
|
115
|
-
id: string;
|
|
116
|
-
instanceId: string;
|
|
117
|
-
required?: boolean | undefined;
|
|
118
111
|
} | {
|
|
119
112
|
value: string;
|
|
120
113
|
type: "expression";
|
|
@@ -189,13 +182,6 @@ export declare const getPropsByInstanceId: (props: Map<string, {
|
|
|
189
182
|
id: string;
|
|
190
183
|
instanceId: string;
|
|
191
184
|
required?: boolean | undefined;
|
|
192
|
-
} | {
|
|
193
|
-
value: string;
|
|
194
|
-
type: "dataSource";
|
|
195
|
-
name: string;
|
|
196
|
-
id: string;
|
|
197
|
-
instanceId: string;
|
|
198
|
-
required?: boolean | undefined;
|
|
199
185
|
} | {
|
|
200
186
|
value: string;
|
|
201
187
|
type: "expression";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.118.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"type-fest": "^4.3.1",
|
|
17
17
|
"typescript": "5.2.2",
|
|
18
18
|
"zod": "^3.21.4",
|
|
19
|
-
"@webstudio-is/
|
|
20
|
-
"@webstudio-is/
|
|
19
|
+
"@webstudio-is/tsconfig": "1.0.7",
|
|
20
|
+
"@webstudio-is/jest-config": "1.0.7"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"@remix-run/react": "^1.19.1",
|
|
@@ -33,10 +33,10 @@
|
|
|
33
33
|
"jsep": "^1.3.8",
|
|
34
34
|
"nanoid": "^5.0.1",
|
|
35
35
|
"title-case": "^4.1.0",
|
|
36
|
-
"@webstudio-is/css-engine": "0.
|
|
37
|
-
"@webstudio-is/
|
|
38
|
-
"@webstudio-is/
|
|
39
|
-
"@webstudio-is/sdk": "0.
|
|
36
|
+
"@webstudio-is/css-engine": "0.118.0",
|
|
37
|
+
"@webstudio-is/fonts": "0.118.0",
|
|
38
|
+
"@webstudio-is/image": "0.118.0",
|
|
39
|
+
"@webstudio-is/sdk": "0.118.0"
|
|
40
40
|
},
|
|
41
41
|
"exports": {
|
|
42
42
|
".": {
|