@webstudio-is/react-sdk 0.295.0 → 0.297.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 +31 -33
- package/package.json +10 -11
package/lib/index.js
CHANGED
|
@@ -252,10 +252,7 @@ import {
|
|
|
252
252
|
} from "@webstudio-is/sdk";
|
|
253
253
|
import { transpileExpression } from "@webstudio-is/expression";
|
|
254
254
|
import { indexProperty, tagProperty } from "@webstudio-is/sdk/runtime";
|
|
255
|
-
import {
|
|
256
|
-
getJsxPropName,
|
|
257
|
-
mapAttributeNames
|
|
258
|
-
} from "@webstudio-is/content-engine/jsx-attributes";
|
|
255
|
+
import { getJsxPropName } from "@webstudio-is/content-engine/jsx-attributes";
|
|
259
256
|
var generateAction = ({
|
|
260
257
|
scope,
|
|
261
258
|
prop,
|
|
@@ -378,14 +375,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
378
375
|
let collectionDataValue;
|
|
379
376
|
let collectionItemValue;
|
|
380
377
|
let collectionItemKeyValue;
|
|
381
|
-
|
|
382
|
-
const instanceProps = Array.from(
|
|
383
|
-
Array.from(props.values()).filter((prop) => prop.instanceId === instance.id).reduce((uniqueProps, prop) => {
|
|
384
|
-
uniqueProps.set(prop.name, prop);
|
|
385
|
-
return uniqueProps;
|
|
386
|
-
}, /* @__PURE__ */ new Map()).values()
|
|
387
|
-
);
|
|
388
|
-
const instancePropNames = new Set(instanceProps.map((prop) => prop.name));
|
|
378
|
+
const classNameValues = [];
|
|
389
379
|
const projectedResourceProps = /* @__PURE__ */ new Map();
|
|
390
380
|
const componentPropNames = new Set(Object.keys(meta?.props ?? {}));
|
|
391
381
|
const acceptsHtmlAttributes = hasTags || instance.tag !== void 0 || instance.component === elementComponent;
|
|
@@ -394,36 +384,45 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
394
384
|
componentPropNames,
|
|
395
385
|
acceptsHtmlAttributes
|
|
396
386
|
});
|
|
397
|
-
const
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
387
|
+
const propsByGeneratedName = /* @__PURE__ */ new Map();
|
|
388
|
+
const classProps = /* @__PURE__ */ new Map();
|
|
389
|
+
for (const prop of props.values()) {
|
|
390
|
+
if (prop.instanceId !== instance.id || isAttributeNameSafe(prop.name) === false) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const name = getGeneratedPropName(prop.name);
|
|
394
|
+
if (name === "className") {
|
|
395
|
+
classProps.set(prop.name, prop);
|
|
396
|
+
continue;
|
|
397
|
+
}
|
|
398
|
+
propsByGeneratedName.set(name, prop);
|
|
399
|
+
}
|
|
400
|
+
const generatedPropNames = /* @__PURE__ */ new Set([
|
|
401
|
+
...propsByGeneratedName.keys(),
|
|
402
|
+
...classProps.size > 0 ? ["className"] : []
|
|
403
|
+
]);
|
|
404
|
+
for (const [name, prop] of [
|
|
405
|
+
...propsByGeneratedName,
|
|
406
|
+
...Array.from(classProps.values(), (prop2) => ["className", prop2])
|
|
407
|
+
]) {
|
|
406
408
|
const propValue = generatePropValue({
|
|
407
409
|
scope,
|
|
408
410
|
prop,
|
|
409
411
|
dataSources,
|
|
410
412
|
usedDataSources
|
|
411
413
|
});
|
|
412
|
-
if (isAttributeNameSafe(prop.name) === false) {
|
|
413
|
-
continue;
|
|
414
|
-
}
|
|
415
414
|
if (prop.type === "resource") {
|
|
416
415
|
const propMeta = meta?.props?.[prop.name];
|
|
417
416
|
const resource = resources?.get(prop.value);
|
|
418
417
|
if (propMeta?.type === "resource" && resource !== void 0) {
|
|
419
|
-
for (const
|
|
420
|
-
|
|
421
|
-
|
|
418
|
+
for (const propName of propMeta.generatedProps ?? []) {
|
|
419
|
+
const generatedPropName = getGeneratedPropName(propName);
|
|
420
|
+
if (generatedPropNames.has(generatedPropName) === false && isAttributeNameSafe(propName)) {
|
|
421
|
+
projectedResourceProps.set(generatedPropName, resource[propName]);
|
|
422
422
|
}
|
|
423
423
|
}
|
|
424
424
|
}
|
|
425
425
|
}
|
|
426
|
-
const name = generatedPropNames.get(prop.id) ?? prop.name;
|
|
427
426
|
if (prop.name === showAttribute) {
|
|
428
427
|
if (propValue === "true") {
|
|
429
428
|
continue;
|
|
@@ -447,7 +446,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
447
446
|
continue;
|
|
448
447
|
}
|
|
449
448
|
if (name === "className" && propValue !== void 0) {
|
|
450
|
-
|
|
449
|
+
classNameValues.push(propValue);
|
|
451
450
|
continue;
|
|
452
451
|
}
|
|
453
452
|
if (propValue !== void 0) {
|
|
@@ -455,15 +454,14 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
|
|
|
455
454
|
${name}={${propValue}}`;
|
|
456
455
|
}
|
|
457
456
|
}
|
|
458
|
-
for (const [
|
|
459
|
-
const name = getGeneratedPropName(propName);
|
|
457
|
+
for (const [name, value] of projectedResourceProps) {
|
|
460
458
|
generatedProps += `
|
|
461
459
|
${name}={${JSON.stringify(value)}}`;
|
|
462
460
|
}
|
|
463
461
|
const classMapArray = classesMap?.get(instance.id);
|
|
464
|
-
if (classMapArray ||
|
|
462
|
+
if (classMapArray || classNameValues.length > 0) {
|
|
465
463
|
let classNameTemplate = classMapArray ? classMapArray.join(" ") : "";
|
|
466
|
-
|
|
464
|
+
for (const classNameValue of classNameValues) {
|
|
467
465
|
if (classNameTemplate) {
|
|
468
466
|
classNameTemplate += " ";
|
|
469
467
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webstudio-is/react-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.297.0",
|
|
4
4
|
"description": "Webstudio JavaScript / TypeScript API",
|
|
5
5
|
"author": "Webstudio <github@webstudio.is>",
|
|
6
6
|
"homepage": "https://webstudio.is",
|
|
@@ -15,8 +15,8 @@
|
|
|
15
15
|
"typescript": "7.0.2",
|
|
16
16
|
"vitest": "^3.1.2",
|
|
17
17
|
"zod": "^4.4.3",
|
|
18
|
-
"@webstudio-is/
|
|
19
|
-
"@webstudio-is/
|
|
18
|
+
"@webstudio-is/template": "0.297.0",
|
|
19
|
+
"@webstudio-is/tsconfig": "1.0.7"
|
|
20
20
|
},
|
|
21
21
|
"peerDependencies": {
|
|
22
22
|
"react": "18.3.0-canary-14898b6a9-20240318",
|
|
@@ -25,14 +25,13 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"change-case": "^5.4.4",
|
|
28
|
-
"
|
|
29
|
-
"@webstudio-is/content-engine": "0.
|
|
30
|
-
"@webstudio-is/
|
|
31
|
-
"@webstudio-is/fonts": "0.
|
|
32
|
-
"@webstudio-is/
|
|
33
|
-
"@webstudio-is/
|
|
34
|
-
"@webstudio-is/image": "0.
|
|
35
|
-
"@webstudio-is/sdk": "0.295.0"
|
|
28
|
+
"@webstudio-is/css-engine": "0.297.0",
|
|
29
|
+
"@webstudio-is/content-engine": "0.297.0",
|
|
30
|
+
"@webstudio-is/expression": "0.297.0",
|
|
31
|
+
"@webstudio-is/fonts": "0.297.0",
|
|
32
|
+
"@webstudio-is/icons": "^0.297.0",
|
|
33
|
+
"@webstudio-is/sdk": "0.297.0",
|
|
34
|
+
"@webstudio-is/image": "0.297.0"
|
|
36
35
|
},
|
|
37
36
|
"exports": {
|
|
38
37
|
".": {
|