Skip to content

Commit 26fe209

Browse files
committed
Make it optional
1 parent 4c90c54 commit 26fe209

File tree

2 files changed

+4
-48
lines changed

2 files changed

+4
-48
lines changed

packages/react-sdk/src/component-generator.test.tsx

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ test("generate jsx element with children and without them", () => {
8585
usedDataSources: new Map(),
8686
indexesWithinAncestors: new Map(),
8787
metas: new Map(),
88-
tagsOverrides: {},
8988
children: [{ type: "id", value: "body" }],
9089
...renderData(<$.Body ws:id="body">Children</$.Body>),
9190
})
@@ -104,7 +103,6 @@ test("generate jsx element with children and without them", () => {
104103
usedDataSources: new Map(),
105104
indexesWithinAncestors: new Map(),
106105
metas: new Map(),
107-
tagsOverrides: {},
108106
children: [{ type: "id", value: "image" }],
109107
...renderData(<$.Image ws:id="image"></$.Image>),
110108
})
@@ -125,7 +123,6 @@ test("generate jsx element with namespaces components", () => {
125123
usedDataSources: new Map(),
126124
indexesWithinAncestors: new Map(),
127125
metas: new Map(),
128-
tagsOverrides: {},
129126
children: [{ type: "id", value: "body" }],
130127
...renderData(<library.Body ws:id="body"></library.Body>),
131128
})
@@ -142,7 +139,6 @@ test("generate jsx element with namespaces components", () => {
142139
usedDataSources: new Map(),
143140
indexesWithinAncestors: new Map(),
144141
metas: new Map(),
145-
tagsOverrides: {},
146142
children: [{ type: "id", value: "image" }],
147143
...renderData(<library.Image ws:id="image"></library.Image>),
148144
})
@@ -162,7 +158,6 @@ test("generate jsx element with literal props", () => {
162158
usedDataSources: new Map(),
163159
indexesWithinAncestors: new Map(),
164160
metas: new Map(),
165-
tagsOverrides: {},
166161
children: [{ type: "id", value: "body" }],
167162
...renderData(<$.Body ws:id="body" string="string" number={0}></$.Body>),
168163
})
@@ -181,7 +176,6 @@ test("generate jsx element with literal props", () => {
181176
usedDataSources: new Map(),
182177
indexesWithinAncestors: new Map(),
183178
metas: new Map(),
184-
tagsOverrides: {},
185179
children: [{ type: "id", value: "image" }],
186180
...renderData(
187181
<$.Image
@@ -209,7 +203,6 @@ test("ignore asset and page props", () => {
209203
usedDataSources: new Map(),
210204
indexesWithinAncestors: new Map(),
211205
metas: new Map(),
212-
tagsOverrides: {},
213206
children: [{ type: "id", value: "box" }],
214207
...renderData(
215208
<$.Box
@@ -236,7 +229,6 @@ test("generate jsx element with data sources and action", () => {
236229
usedDataSources: new Map(),
237230
indexesWithinAncestors: new Map(),
238231
metas: new Map(),
239-
tagsOverrides: {},
240232
children: [{ type: "id", value: "box" }],
241233
...renderData(
242234
<$.Box
@@ -269,7 +261,6 @@ test("generate jsx element with condition based on show prop", () => {
269261
usedDataSources: new Map(),
270262
indexesWithinAncestors: new Map(),
271263
metas: new Map(),
272-
tagsOverrides: {},
273264
children: [{ type: "id", value: "box" }],
274265
...renderData(<$.Box ws:id="box" data-ws-show={true}></$.Box>),
275266
})
@@ -286,7 +277,6 @@ test("generate jsx element with condition based on show prop", () => {
286277
usedDataSources: new Map(),
287278
indexesWithinAncestors: new Map(),
288279
metas: new Map(),
289-
tagsOverrides: {},
290280
children: [{ type: "id", value: "box" }],
291281
...renderData(<$.Box ws:id="box" data-ws-show={false}></$.Box>),
292282
})
@@ -298,7 +288,6 @@ test("generate jsx element with condition based on show prop", () => {
298288
usedDataSources: new Map(),
299289
indexesWithinAncestors: new Map(),
300290
metas: new Map(),
301-
tagsOverrides: {},
302291
children: [{ type: "id", value: "box" }],
303292
...renderData(
304293
<$.Box ws:id="box" data-ws-show={expression`${condition}`}></$.Box>
@@ -320,7 +309,6 @@ test("generate jsx children with text", () => {
320309
generateJsxChildren({
321310
scope: createScope(),
322311
metas: new Map(),
323-
tagsOverrides: {},
324312
children: [
325313
{ type: "text", value: "Some\ntext" },
326314
{ type: "text", value: 'Escaped "text"' },
@@ -348,7 +336,6 @@ test("exclude text placeholders", () => {
348336
generateJsxChildren({
349337
scope: createScope(),
350338
metas: new Map(),
351-
tagsOverrides: {},
352339
children: [
353340
{ type: "text", value: "Text" },
354341
{ type: "text", value: "Placeholder text", placeholder: true },
@@ -374,7 +361,6 @@ test("generate jsx children with expression", () => {
374361
generateJsxChildren({
375362
scope: createScope(),
376363
metas: new Map(),
377-
tagsOverrides: {},
378364
children: [
379365
{ type: "expression", value: "'Hello ' + $ws$dataSource$var" },
380366
],
@@ -406,7 +392,6 @@ test("generate jsx children with nested instances", () => {
406392
generateJsxChildren({
407393
scope: createScope(),
408394
metas: new Map(),
409-
tagsOverrides: {},
410395
children: [{ type: "id", value: "form" }],
411396
usedDataSources: new Map(),
412397
indexesWithinAncestors: new Map(),
@@ -436,7 +421,6 @@ test("deduplicate base and namespaced components with same short name", () => {
436421
generateJsxChildren({
437422
scope: createScope(),
438423
metas: new Map(),
439-
tagsOverrides: {},
440424
children: [
441425
{ type: "id", value: "button1" },
442426
{ type: "id", value: "button2" },
@@ -465,7 +449,6 @@ test("generate collection component as map", () => {
465449
generateJsxChildren({
466450
scope: createScope(),
467451
metas: new Map(),
468-
tagsOverrides: {},
469452
children: [{ type: "id", value: "list" }],
470453
usedDataSources: new Map(),
471454
indexesWithinAncestors: new Map(),
@@ -501,7 +484,6 @@ test("generate component with variables and actions", () => {
501484
rootInstanceId: "body",
502485
parameters: [],
503486
metas: new Map(),
504-
tagsOverrides: {},
505487
...renderData(
506488
<$.Body ws:id="body">
507489
<$.Input
@@ -541,7 +523,6 @@ test("merge classes if no className", () => {
541523
rootInstanceId: "body",
542524
parameters: [],
543525
metas: new Map(),
544-
tagsOverrides: {},
545526
...renderData(<$.Body ws:id="body"></$.Body>),
546527
})
547528
).toEqual(
@@ -565,7 +546,6 @@ test("add classes and merge classes", () => {
565546
rootInstanceId: "body",
566547
parameters: [],
567548
metas: new Map(),
568-
tagsOverrides: {},
569549
...renderData(<$.Body ws:id="body" className='cls2 "cls3"'></$.Body>),
570550
})
571551
).toEqual(
@@ -589,7 +569,6 @@ test("add classes", () => {
589569
rootInstanceId: "body",
590570
parameters: [],
591571
metas: new Map(),
592-
tagsOverrides: {},
593572
...renderData(<$.Body ws:id="body" className='cls2 "cls3"'></$.Body>),
594573
})
595574
).toEqual(
@@ -614,7 +593,6 @@ test("add bind classes and merge classes", () => {
614593
rootInstanceId: "body",
615594
parameters: [],
616595
metas: new Map(),
617-
tagsOverrides: {},
618596
...renderData(
619597
<$.Body
620598
ws:id="body"
@@ -646,7 +624,6 @@ test("avoid generating collection parameter variable as state", () => {
646624
rootInstanceId: "body",
647625
parameters: [],
648626
metas: new Map(),
649-
tagsOverrides: {},
650627
...renderData(
651628
<$.Body ws:id="body">
652629
<ws.collection
@@ -708,7 +685,6 @@ test("generate both page system and global system variables when present", () =>
708685
},
709686
],
710687
metas: new Map(),
711-
tagsOverrides: {},
712688
...data,
713689
})
714690
).toEqual(
@@ -741,7 +717,6 @@ test("generate resources loading", () => {
741717
rootInstanceId: "body",
742718
parameters: [],
743719
metas: new Map(),
744-
tagsOverrides: {},
745720
...renderData(
746721
<$.Body
747722
ws:id="body"
@@ -803,7 +778,6 @@ test("avoid generating unused variables", () => {
803778
},
804779
],
805780
metas: new Map(),
806-
tagsOverrides: {},
807781
...data,
808782
})
809783
).toMatchInlineSnapshot(`
@@ -825,7 +799,6 @@ test("avoid generating descendant component", () => {
825799
rootInstanceId: "body",
826800
parameters: [],
827801
metas: new Map(),
828-
tagsOverrides: {},
829802
...renderData(
830803
<$.Body ws:id="body">
831804
<ws.descendant></ws.descendant>
@@ -852,7 +825,6 @@ test("generate conditional collection", () => {
852825
rootInstanceId: "body",
853826
parameters: [],
854827
metas: new Map(),
855-
tagsOverrides: {},
856828
...renderData(
857829
<$.Body ws:id="body">
858830
<ws.collection
@@ -892,7 +864,6 @@ test("generate conditional body", () => {
892864
rootInstanceId: "body",
893865
parameters: [],
894866
metas: new Map(),
895-
tagsOverrides: {},
896867
...renderData(
897868
<$.Body ws:id="body" data-ws-show={expression`${condition}`}></$.Body>
898869
),
@@ -927,7 +898,6 @@ test("generate resource prop", () => {
927898
rootInstanceId: "body",
928899
parameters: [],
929900
metas: new Map(),
930-
tagsOverrides: {},
931901
...renderData(
932902
<$.Body ws:id="body">
933903
<$.Form ws:id="form1" action={myResource}></$.Form>
@@ -957,7 +927,6 @@ test("skip unsafe properties", () => {
957927
rootInstanceId: "body",
958928
parameters: [],
959929
metas: new Map(),
960-
tagsOverrides: {},
961930
...renderData(
962931
<$.Body
963932
ws:id="body"
@@ -990,7 +959,6 @@ test("variable names can be js identifiers", () => {
990959
rootInstanceId: "body",
991960
parameters: [],
992961
metas: new Map(),
993-
tagsOverrides: {},
994962
...renderData(
995963
<$.Body ws:id="body">
996964
<$.Input
@@ -1031,7 +999,6 @@ test("renders nothing if only templates are present in block", () => {
1031999
rootInstanceId: "body",
10321000
parameters: [],
10331001
metas: new Map(),
1034-
tagsOverrides: {},
10351002
...renderData(
10361003
<$.Body ws:id="body">
10371004
<ws.block ws:id="block">
@@ -1065,7 +1032,6 @@ test("renders only block children", () => {
10651032
rootInstanceId: "body",
10661033
parameters: [],
10671034
metas: new Map(),
1068-
tagsOverrides: {},
10691035
...renderData(
10701036
<$.Body ws:id="body">
10711037
<ws.block ws:id="block">
@@ -1101,7 +1067,6 @@ test("generate unset variables as undefined", () => {
11011067
rootInstanceId: "body",
11021068
parameters: [],
11031069
metas: new Map(),
1104-
tagsOverrides: {},
11051070
...renderData(
11061071
<$.Body ws:id="body">
11071072
<$.Box>{expression`a + b`}</$.Box>
@@ -1141,7 +1106,6 @@ test("generate global variables", () => {
11411106
rootInstanceId: "body",
11421107
parameters: [],
11431108
metas: new Map(),
1144-
tagsOverrides: {},
11451109
...data,
11461110
})
11471111
).toEqual(
@@ -1178,7 +1142,6 @@ test("ignore unused global variables", () => {
11781142
rootInstanceId: "body",
11791143
parameters: [],
11801144
metas: new Map(),
1181-
tagsOverrides: {},
11821145
...data,
11831146
})
11841147
).toEqual(
@@ -1206,7 +1169,6 @@ test("generate prop with index within ancestor", () => {
12061169
["TabsTrigger", { indexWithinAncestor: "Tabs" }],
12071170
["TabsContent", { indexWithinAncestor: "Tabs" }],
12081171
]),
1209-
tagsOverrides: {},
12101172
...renderData(
12111173
<$.Body ws:id="body">
12121174
<$.Tabs>
@@ -1264,7 +1226,6 @@ test("ignore ws:block-template when generate index attribute", () => {
12641226
metas: new Map<string, WsComponentMeta>([
12651227
["TabsTrigger", { indexWithinAncestor: "Tabs" }],
12661228
]),
1267-
tagsOverrides: {},
12681229
...renderData(
12691230
<$.Body ws:id="bodyId">
12701231
<$.Tabs>
@@ -1308,7 +1269,6 @@ test("render empty component when no instances found", () => {
13081269
rootInstanceId: "",
13091270
parameters: [],
13101271
metas: new Map(),
1311-
tagsOverrides: {},
13121272
...renderData(<$.Body ws:id="bodyId"></$.Body>),
13131273
})
13141274
).toEqual(
@@ -1331,7 +1291,6 @@ test("render tag property on components", () => {
13311291
rootInstanceId: "bodyId",
13321292
parameters: [],
13331293
metas: new Map(),
1334-
tagsOverrides: {},
13351294
...renderData(
13361295
<$.Body ws:id="bodyId">
13371296
<$.Box ws:id="spanId" ws:tag="span"></$.Box>
@@ -1361,7 +1320,6 @@ test("render ws:element component with div tag by default", () => {
13611320
rootInstanceId: "bodyId",
13621321
parameters: [],
13631322
metas: new Map(),
1364-
tagsOverrides: {},
13651323
...renderData(
13661324
<$.Body ws:id="bodyId">
13671325
<ws.element id="element1">
@@ -1396,7 +1354,6 @@ test("render ws:element component with ws:tag", () => {
13961354
rootInstanceId: "bodyId",
13971355
parameters: [],
13981356
metas: new Map(),
1399-
tagsOverrides: {},
14001357
...renderData(
14011358
<$.Body ws:id="bodyId">
14021359
<ws.element ws:tag="p" id="paragraph">
@@ -1466,7 +1423,6 @@ test("convert attributes to react compatible when render components with tags",
14661423
rootInstanceId: "bodyId",
14671424
parameters: [],
14681425
metas: new Map([["Box", { presetStyle: { div: [] } }]]),
1469-
tagsOverrides: {},
14701426
...renderData(
14711427
<$.Body ws:id="bodyId">
14721428
<$.Box class="my-class" for="my-id" autocomplete="off"></$.Box>

packages/react-sdk/src/component-generator.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ export const generateJsxElement = ({
160160
/**
161161
* Record<tag, componentDescriptor>
162162
*/
163-
tagsOverrides: Record<string, string>;
163+
tagsOverrides?: Record<string, string>;
164164
instance: Instance;
165165
props: Props;
166166
dataSources: DataSources;
@@ -290,7 +290,7 @@ export const generateJsxElement = ({
290290
if (instance.component === elementComponent) {
291291
componentVariable = instance.tag ?? "div";
292292
// replace html tag with component if available
293-
const componentDescriptor = tagsOverrides[componentVariable];
293+
const componentDescriptor = tagsOverrides?.[componentVariable];
294294
if (componentDescriptor !== undefined) {
295295
const [_importSource, importSpecifier] = componentDescriptor.split(":");
296296
componentVariable = scope.getName(componentDescriptor, importSpecifier);
@@ -355,7 +355,7 @@ export const generateJsxChildren = ({
355355
scope: Scope;
356356
metas: Map<Instance["component"], WsComponentMeta>;
357357
// Record<tag, componentDescriptor>
358-
tagsOverrides: Record<string, string>;
358+
tagsOverrides?: Record<string, string>;
359359
children: Instance["children"];
360360
instances: Instances;
361361
props: Props;
@@ -451,7 +451,7 @@ export const generateWebstudioComponent = ({
451451
/**
452452
* Record<tag, componentDescriptor>
453453
*/
454-
tagsOverrides: Record<string, string>;
454+
tagsOverrides?: Record<string, string>;
455455
}) => {
456456
const instance = instances.get(rootInstanceId);
457457
const indexesWithinAncestors = getIndexesWithinAncestors(metas, instances, [

0 commit comments

Comments
 (0)