@webstudio-is/react-sdk 0.219.0 → 0.220.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
@@ -393,6 +393,7 @@ var generateJsxElement = ({
393
393
  context = "jsx",
394
394
  scope,
395
395
  metas,
396
+ tagsOverrides,
396
397
  instance,
397
398
  props,
398
399
  dataSources,
@@ -404,7 +405,8 @@ var generateJsxElement = ({
404
405
  if (instance.component === descendantComponent) {
405
406
  return "";
406
407
  }
407
- const hasTags = Object.keys(metas.get(instance.component)?.presetStyle ?? {}).length > 0;
408
+ const meta = metas.get(instance.component);
409
+ const hasTags = Object.keys(meta?.presetStyle ?? {}).length > 0;
408
410
  let generatedProps = "";
409
411
  const index = indexesWithinAncestors.get(instance.id);
410
412
  if (index !== void 0) {
@@ -433,7 +435,7 @@ ${tagProperty}=${JSON.stringify(instance.tag)}`;
433
435
  continue;
434
436
  }
435
437
  let name = prop.name;
436
- if (instance.component === elementComponent || hasTags) {
438
+ if (hasTags && !meta?.props?.[prop.name]) {
437
439
  name = standardAttributesToReactProps[prop.name] ?? prop.name;
438
440
  }
439
441
  if (prop.name === showAttribute) {
@@ -495,21 +497,19 @@ ${name}={${propValue}}`;
495
497
  `;
496
498
  } else if (instance.component === blockComponent) {
497
499
  generatedElement += children;
498
- } else if (instance.component === elementComponent) {
499
- const tagName = instance.tag ?? "div";
500
- if (instance.children.length === 0) {
501
- generatedElement += `<${tagName}${generatedProps} />
502
- `;
500
+ } else {
501
+ let componentVariable;
502
+ if (instance.component === elementComponent) {
503
+ componentVariable = instance.tag ?? "div";
504
+ const componentDescriptor = tagsOverrides?.[componentVariable];
505
+ if (componentDescriptor !== void 0) {
506
+ const [_importSource, importSpecifier] = componentDescriptor.split(":");
507
+ componentVariable = scope.getName(componentDescriptor, importSpecifier);
508
+ }
503
509
  } else {
504
- generatedElement += `<${tagName}${generatedProps}>
505
- `;
506
- generatedElement += children;
507
- generatedElement += `</${tagName}>
508
- `;
510
+ const [_namespace, shortName] = parseComponentName(instance.component);
511
+ componentVariable = scope.getName(instance.component, shortName);
509
512
  }
510
- } else {
511
- const [_namespace, shortName] = parseComponentName(instance.component);
512
- const componentVariable = scope.getName(instance.component, shortName);
513
513
  if (instance.children.length === 0) {
514
514
  generatedElement += `<${componentVariable}${generatedProps} />
515
515
  `;
@@ -547,6 +547,7 @@ ${name}={${propValue}}`;
547
547
  var generateJsxChildren = ({
548
548
  scope,
549
549
  metas,
550
+ tagsOverrides,
550
551
  children,
551
552
  instances,
552
553
  props,
@@ -588,6 +589,7 @@ var generateJsxChildren = ({
588
589
  context: "jsx",
589
590
  scope,
590
591
  metas,
592
+ tagsOverrides,
591
593
  instance,
592
594
  props,
593
595
  dataSources,
@@ -598,6 +600,7 @@ var generateJsxChildren = ({
598
600
  classesMap,
599
601
  scope,
600
602
  metas,
603
+ tagsOverrides,
601
604
  children: instance.children,
602
605
  instances,
603
606
  props,
@@ -622,6 +625,7 @@ var generateWebstudioComponent = ({
622
625
  props,
623
626
  dataSources,
624
627
  metas,
628
+ tagsOverrides,
625
629
  classesMap
626
630
  }) => {
627
631
  const instance = instances.get(rootInstanceId);
@@ -635,6 +639,7 @@ var generateWebstudioComponent = ({
635
639
  context: "expression",
636
640
  scope,
637
641
  metas,
642
+ tagsOverrides,
638
643
  instance,
639
644
  props,
640
645
  dataSources,
@@ -644,6 +649,7 @@ var generateWebstudioComponent = ({
644
649
  children: generateJsxChildren({
645
650
  scope,
646
651
  metas,
652
+ tagsOverrides,
647
653
  children: instance.children,
648
654
  instances,
649
655
  props,
@@ -1,8 +1,12 @@
1
1
  import type { Instances, Instance, Props, Scope, DataSources, Prop, WsComponentMeta, IndexesWithinAncestors } from "@webstudio-is/sdk";
2
- export declare const generateJsxElement: ({ context, scope, metas, instance, props, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
2
+ export declare const generateJsxElement: ({ context, scope, metas, tagsOverrides, instance, props, dataSources, usedDataSources, indexesWithinAncestors, children, classesMap, }: {
3
3
  context?: "expression" | "jsx";
4
4
  scope: Scope;
5
5
  metas: Map<Instance["component"], WsComponentMeta>;
6
+ /**
7
+ * Record<tag, componentDescriptor>
8
+ */
9
+ tagsOverrides?: Record<string, string>;
6
10
  instance: Instance;
7
11
  props: Props;
8
12
  dataSources: DataSources;
@@ -11,9 +15,10 @@ export declare const generateJsxElement: ({ context, scope, metas, instance, pro
11
15
  children: string;
12
16
  classesMap?: Map<string, Array<string>>;
13
17
  }) => string;
14
- export declare const generateJsxChildren: ({ scope, metas, children, instances, props, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, }: {
18
+ export declare const generateJsxChildren: ({ scope, metas, tagsOverrides, children, instances, props, dataSources, usedDataSources, indexesWithinAncestors, classesMap, excludePlaceholders, }: {
15
19
  scope: Scope;
16
20
  metas: Map<Instance["component"], WsComponentMeta>;
21
+ tagsOverrides?: Record<string, string>;
17
22
  children: Instance["children"];
18
23
  instances: Instances;
19
24
  props: Props;
@@ -23,7 +28,7 @@ export declare const generateJsxChildren: ({ scope, metas, children, instances,
23
28
  classesMap?: Map<string, Array<string>>;
24
29
  excludePlaceholders?: boolean;
25
30
  }) => string;
26
- export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, metas, classesMap, }: {
31
+ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId, parameters, instances, props, dataSources, metas, tagsOverrides, classesMap, }: {
27
32
  scope: Scope;
28
33
  name: string;
29
34
  rootInstanceId: Instance["id"];
@@ -35,4 +40,8 @@ export declare const generateWebstudioComponent: ({ scope, name, rootInstanceId,
35
40
  dataSources: DataSources;
36
41
  classesMap: Map<string, Array<string>>;
37
42
  metas: Map<Instance["component"], WsComponentMeta>;
43
+ /**
44
+ * Record<tag, componentDescriptor>
45
+ */
46
+ tagsOverrides?: Record<string, string>;
38
47
  }) => string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webstudio-is/react-sdk",
3
- "version": "0.219.0",
3
+ "version": "0.220.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.37.0",
15
15
  "vitest": "^3.1.2",
16
16
  "zod": "^3.24.2",
17
- "@webstudio-is/template": "0.219.0",
17
+ "@webstudio-is/template": "0.220.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.1.5",
29
- "@webstudio-is/css-engine": "0.219.0",
30
- "@webstudio-is/fonts": "0.219.0",
31
- "@webstudio-is/image": "0.219.0",
32
- "@webstudio-is/icons": "^0.219.0",
33
- "@webstudio-is/sdk": "0.219.0"
29
+ "@webstudio-is/css-engine": "0.220.0",
30
+ "@webstudio-is/icons": "^0.220.0",
31
+ "@webstudio-is/sdk": "0.220.0",
32
+ "@webstudio-is/fonts": "0.220.0",
33
+ "@webstudio-is/image": "0.220.0"
34
34
  },
35
35
  "exports": {
36
36
  ".": {