@react-native-windows/codegen 0.74.2 → 0.74.3
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/CHANGELOG.md +13 -5
- package/lib-commonjs/Cli.js +11 -0
- package/lib-commonjs/Cli.js.map +1 -1
- package/lib-commonjs/generators/AliasManaging.d.ts +3 -3
- package/lib-commonjs/generators/AliasManaging.js.map +1 -1
- package/lib-commonjs/generators/GenerateComponentWindows.d.ts +13 -0
- package/lib-commonjs/generators/GenerateComponentWindows.js +389 -0
- package/lib-commonjs/generators/GenerateComponentWindows.js.map +1 -0
- package/lib-commonjs/generators/PropObjectTypes.d.ts +18 -0
- package/lib-commonjs/generators/PropObjectTypes.js +198 -0
- package/lib-commonjs/generators/PropObjectTypes.js.map +1 -0
- package/lib-commonjs/index.d.ts +3 -1
- package/lib-commonjs/index.js +16 -13
- package/lib-commonjs/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Cli.ts +12 -0
- package/src/generators/AliasManaging.ts +12 -12
- package/src/generators/GenerateComponentWindows.ts +523 -0
- package/src/generators/PropObjectTypes.ts +214 -0
- package/src/index.ts +33 -11
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
import type { PropTypeAnnotation, ObjectTypeAnnotation, EventTypeAnnotation, CommandParamTypeAnnotation } from '@react-native/codegen/lib/CodegenSchema';
|
|
2
|
+
import type { CppCodegenOptions } from './ObjectTypes';
|
|
3
|
+
import {
|
|
4
|
+
AliasMap,
|
|
5
|
+
getAnonymousAliasCppName,
|
|
6
|
+
} from './AliasManaging';
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line complexity
|
|
10
|
+
export function translateComponentPropsFieldType(type: PropTypeAnnotation,
|
|
11
|
+
aliases: AliasMap<ObjectTypeAnnotation<PropTypeAnnotation>>,
|
|
12
|
+
baseAliasName: string,
|
|
13
|
+
options: CppCodegenOptions): { type: string, initializer: string, alreadySupportsOptionalOrHasDefault?: boolean } {
|
|
14
|
+
switch (type.type) {
|
|
15
|
+
case 'StringTypeAnnotation':
|
|
16
|
+
return { type: options.cppStringType, initializer: type.default ? `{${type.default}}` : '', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
17
|
+
case 'FloatTypeAnnotation':
|
|
18
|
+
return { type: 'float', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
19
|
+
case 'DoubleTypeAnnotation':
|
|
20
|
+
return { type: 'double', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
21
|
+
case 'Int32TypeAnnotation':
|
|
22
|
+
return { type: 'int32_t', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
23
|
+
case 'BooleanTypeAnnotation':
|
|
24
|
+
return { type: 'bool', initializer: type.default ? `{${type.default}}` : '{}', alreadySupportsOptionalOrHasDefault: !!type.default };
|
|
25
|
+
case 'ArrayTypeAnnotation':
|
|
26
|
+
|
|
27
|
+
let arrayTemplateArg = '';
|
|
28
|
+
switch (type.elementType.type) {
|
|
29
|
+
case 'BooleanTypeAnnotation':
|
|
30
|
+
arrayTemplateArg = 'bool';
|
|
31
|
+
break;
|
|
32
|
+
case 'DoubleTypeAnnotation':
|
|
33
|
+
arrayTemplateArg = 'double';
|
|
34
|
+
break;
|
|
35
|
+
case 'FloatTypeAnnotation':
|
|
36
|
+
arrayTemplateArg = 'float';
|
|
37
|
+
break;
|
|
38
|
+
case 'Int32TypeAnnotation':
|
|
39
|
+
arrayTemplateArg = 'int32_t';
|
|
40
|
+
break;
|
|
41
|
+
case 'StringTypeAnnotation':
|
|
42
|
+
arrayTemplateArg = options.cppStringType;
|
|
43
|
+
break;
|
|
44
|
+
case 'ArrayTypeAnnotation':
|
|
45
|
+
const innerType = translateComponentPropsFieldType(type.elementType, aliases, baseAliasName, options);
|
|
46
|
+
arrayTemplateArg = `std::vector<${innerType.type}>`;
|
|
47
|
+
break;
|
|
48
|
+
case 'ObjectTypeAnnotation':
|
|
49
|
+
arrayTemplateArg = translateComponentPropsFieldType(type.elementType, aliases, baseAliasName, options).type;
|
|
50
|
+
break;
|
|
51
|
+
case 'ReservedPropTypeAnnotation':
|
|
52
|
+
switch (type.elementType.name) {
|
|
53
|
+
case 'ColorPrimitive':
|
|
54
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::Color';
|
|
55
|
+
break;
|
|
56
|
+
case 'DimensionPrimitive':
|
|
57
|
+
case 'EdgeInsetsPrimitive':
|
|
58
|
+
case 'ImageRequestPrimitive':
|
|
59
|
+
case 'ImageSourcePrimitive':
|
|
60
|
+
case 'PointPrimitive':
|
|
61
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue'; // TODO - better handling for these types than JSValue
|
|
62
|
+
break;
|
|
63
|
+
default:
|
|
64
|
+
throw new Error(`Unhandled ReservedPropTypeAnnotation type: ${type.elementType.name}`);
|
|
65
|
+
}
|
|
66
|
+
break;
|
|
67
|
+
case 'StringEnumTypeAnnotation':
|
|
68
|
+
arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string
|
|
69
|
+
break;
|
|
70
|
+
default:
|
|
71
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return { type: `std::vector<${arrayTemplateArg}>`, initializer: '' };
|
|
75
|
+
case 'ReservedPropTypeAnnotation':
|
|
76
|
+
switch (type.name) {
|
|
77
|
+
case 'ColorPrimitive':
|
|
78
|
+
return { type: 'winrt::Microsoft::ReactNative::Color', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };
|
|
79
|
+
case 'DimensionPrimitive':
|
|
80
|
+
case 'EdgeInsetsPrimitive':
|
|
81
|
+
case 'ImageRequestPrimitive':
|
|
82
|
+
case 'ImageSourcePrimitive':
|
|
83
|
+
case 'PointPrimitive':
|
|
84
|
+
return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true }; // TODO - better handling for these types than JSValue
|
|
85
|
+
default:
|
|
86
|
+
throw new Error(`Unhandled ReservedPropTypeAnnotation type: ${type.name}`);
|
|
87
|
+
}
|
|
88
|
+
case 'ObjectTypeAnnotation': {
|
|
89
|
+
return { type: getAnonymousAliasCppName<ObjectTypeAnnotation<PropTypeAnnotation>>(aliases, baseAliasName, type), initializer: '' };
|
|
90
|
+
}
|
|
91
|
+
case 'MixedTypeAnnotation':
|
|
92
|
+
return { type: 'winrt::Microsoft::ReactNative::JSValue', initializer: '{nullptr}', alreadySupportsOptionalOrHasDefault: true };
|
|
93
|
+
case 'Int32EnumTypeAnnotation':
|
|
94
|
+
return { type: 'int32_t', initializer: '' }; // TODO - better enum type handling than just passing a string
|
|
95
|
+
case 'StringEnumTypeAnnotation':
|
|
96
|
+
return { type: options.cppStringType, initializer: '' }; // TODO - better enum type handling than just passing an int
|
|
97
|
+
default:
|
|
98
|
+
throw new Error(`Unhandled type: ${(type as any).type}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
export function translateComponentEventType(type: EventTypeAnnotation,
|
|
103
|
+
aliases: AliasMap<ObjectTypeAnnotation<EventTypeAnnotation>>,
|
|
104
|
+
baseAliasName: string,
|
|
105
|
+
options: CppCodegenOptions): { type: string, initializer: string, alreadySupportsOptionalOrHasDefault?: boolean } {
|
|
106
|
+
switch (type.type) {
|
|
107
|
+
case 'StringTypeAnnotation':
|
|
108
|
+
return { type: options.cppStringType, initializer: '' };
|
|
109
|
+
case 'FloatTypeAnnotation':
|
|
110
|
+
return { type: 'float', initializer: '{}' };
|
|
111
|
+
case 'DoubleTypeAnnotation':
|
|
112
|
+
return { type: 'double', initializer: '{}' };
|
|
113
|
+
case 'Int32TypeAnnotation':
|
|
114
|
+
return { type: 'int32_t', initializer: '{}' };
|
|
115
|
+
case 'BooleanTypeAnnotation':
|
|
116
|
+
return { type: 'bool', initializer: '{}' };
|
|
117
|
+
case 'ArrayTypeAnnotation':
|
|
118
|
+
{
|
|
119
|
+
let arrayTemplateArg = '';
|
|
120
|
+
switch (type.elementType.type) {
|
|
121
|
+
case 'BooleanTypeAnnotation':
|
|
122
|
+
arrayTemplateArg = 'bool';
|
|
123
|
+
break;
|
|
124
|
+
case 'DoubleTypeAnnotation':
|
|
125
|
+
arrayTemplateArg = 'double';
|
|
126
|
+
break;
|
|
127
|
+
case 'FloatTypeAnnotation':
|
|
128
|
+
arrayTemplateArg = 'float';
|
|
129
|
+
break;
|
|
130
|
+
case 'Int32TypeAnnotation':
|
|
131
|
+
arrayTemplateArg = 'int32_t';
|
|
132
|
+
break;
|
|
133
|
+
case 'StringTypeAnnotation':
|
|
134
|
+
arrayTemplateArg = options.cppStringType;
|
|
135
|
+
break;
|
|
136
|
+
case 'ArrayTypeAnnotation':
|
|
137
|
+
const innerType = translateComponentEventType(type.elementType, aliases, baseAliasName, options);
|
|
138
|
+
arrayTemplateArg = `std::vector<${innerType.type}>`;
|
|
139
|
+
break;
|
|
140
|
+
case 'ObjectTypeAnnotation':
|
|
141
|
+
arrayTemplateArg = translateComponentEventType(type.elementType, aliases, baseAliasName, options).type;
|
|
142
|
+
break;
|
|
143
|
+
case 'StringEnumTypeAnnotation':
|
|
144
|
+
arrayTemplateArg = options.cppStringType; // TODO - better enum type handling than just passing a string
|
|
145
|
+
break;
|
|
146
|
+
default:
|
|
147
|
+
throw new Error(`Unhandled type: ${type.type}`);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return { type: `std::vector<${arrayTemplateArg}>`, initializer: '{}' };
|
|
151
|
+
}
|
|
152
|
+
case 'ObjectTypeAnnotation': {
|
|
153
|
+
return { type: getAnonymousAliasCppName<ObjectTypeAnnotation<EventTypeAnnotation>>(aliases, baseAliasName, type), initializer: '' };
|
|
154
|
+
}
|
|
155
|
+
case 'StringEnumTypeAnnotation':
|
|
156
|
+
return { type: options.cppStringType, initializer: '' }; // TODO - better enum type handling than just passing a string
|
|
157
|
+
default:
|
|
158
|
+
throw new Error(`Unhandled type: ${(type as any).type}`);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
export function translateCommandParamType(type: CommandParamTypeAnnotation,
|
|
164
|
+
aliases: AliasMap<ObjectTypeAnnotation<CommandParamTypeAnnotation>>,
|
|
165
|
+
baseAliasName: string,
|
|
166
|
+
options: CppCodegenOptions): { type: string, initializer: string, alreadySupportsOptionalOrHasDefault?: boolean } {
|
|
167
|
+
switch (type.type) {
|
|
168
|
+
case 'StringTypeAnnotation':
|
|
169
|
+
return { type: options.cppStringType, initializer: '' };
|
|
170
|
+
case 'FloatTypeAnnotation':
|
|
171
|
+
return { type: 'float', initializer: '{}' };
|
|
172
|
+
case 'DoubleTypeAnnotation':
|
|
173
|
+
return { type: 'double', initializer: '{}' };
|
|
174
|
+
case 'Int32TypeAnnotation':
|
|
175
|
+
return { type: 'int32_t', initializer: '{}' };
|
|
176
|
+
case 'BooleanTypeAnnotation':
|
|
177
|
+
return { type: 'bool', initializer: '{}' };
|
|
178
|
+
case 'ArrayTypeAnnotation':
|
|
179
|
+
{
|
|
180
|
+
let arrayTemplateArg = '';
|
|
181
|
+
switch (type.elementType.type) {
|
|
182
|
+
case 'BooleanTypeAnnotation':
|
|
183
|
+
arrayTemplateArg = 'bool';
|
|
184
|
+
break;
|
|
185
|
+
case 'DoubleTypeAnnotation':
|
|
186
|
+
arrayTemplateArg = 'double';
|
|
187
|
+
break;
|
|
188
|
+
case 'FloatTypeAnnotation':
|
|
189
|
+
arrayTemplateArg = 'float';
|
|
190
|
+
break;
|
|
191
|
+
case 'Int32TypeAnnotation':
|
|
192
|
+
arrayTemplateArg = 'int32_t';
|
|
193
|
+
break;
|
|
194
|
+
case 'StringTypeAnnotation':
|
|
195
|
+
arrayTemplateArg = options.cppStringType;
|
|
196
|
+
break;
|
|
197
|
+
case 'GenericTypeAnnotation' as any: // TODO verify schema - Getting this type when running codegen on all the built in types
|
|
198
|
+
arrayTemplateArg = 'winrt::Microsoft::ReactNative::JSValue';
|
|
199
|
+
break;
|
|
200
|
+
default:
|
|
201
|
+
throw new Error(`Unhandled type: ${(type.elementType as any).type} - ${JSON.stringify(type.elementType, null, 2)}`);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return { type: `std::vector<${arrayTemplateArg}>`, initializer: '{}' };
|
|
205
|
+
}
|
|
206
|
+
case 'ReservedTypeAnnotation':
|
|
207
|
+
if ((type.name as any) !== 'RootTag') {
|
|
208
|
+
throw new Error(`Unhandled ReservedTypeAnnotation: ${type.name}`)
|
|
209
|
+
}
|
|
210
|
+
return { type: 'bool', initializer: '{-1}' };
|
|
211
|
+
default:
|
|
212
|
+
throw new Error(`Unhandled type: ${(type as any).type}`);
|
|
213
|
+
}
|
|
214
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,7 @@ import fs from '@react-native-windows/fs';
|
|
|
10
10
|
import globby from 'globby';
|
|
11
11
|
import type {CppStringTypes} from './generators/GenerateNM2';
|
|
12
12
|
import {createNM2Generator} from './generators/GenerateNM2';
|
|
13
|
+
import {createComponentGenerator} from './generators/GenerateComponentWindows';
|
|
13
14
|
import {
|
|
14
15
|
generateTypeScript,
|
|
15
16
|
setOptionalTurboModule,
|
|
@@ -49,6 +50,8 @@ export interface SharedOptions {
|
|
|
49
50
|
modulesCxx: boolean;
|
|
50
51
|
modulesTypeScriptTypes: boolean;
|
|
51
52
|
modulesWindows: boolean;
|
|
53
|
+
componentsWindows: boolean;
|
|
54
|
+
internalComponents: boolean;
|
|
52
55
|
namespace: string;
|
|
53
56
|
outputDirectory: string;
|
|
54
57
|
cppStringType: CppStringTypes;
|
|
@@ -214,6 +217,8 @@ export function generate(
|
|
|
214
217
|
modulesCxx,
|
|
215
218
|
modulesTypeScriptTypes,
|
|
216
219
|
modulesWindows,
|
|
220
|
+
internalComponents,
|
|
221
|
+
componentsWindows,
|
|
217
222
|
namespace,
|
|
218
223
|
outputDirectory,
|
|
219
224
|
cppStringType,
|
|
@@ -319,17 +324,30 @@ export function generate(
|
|
|
319
324
|
moduleName => schema.modules[moduleName].type === 'Component',
|
|
320
325
|
)
|
|
321
326
|
) {
|
|
322
|
-
const componentGenerators = [
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
327
|
+
const componentGenerators = [];
|
|
328
|
+
|
|
329
|
+
if (internalComponents) {
|
|
330
|
+
componentGenerators.push(
|
|
331
|
+
generatorComponentDescriptorH,
|
|
332
|
+
generatorEventEmitterCPP,
|
|
333
|
+
generatorEventEmitterH,
|
|
334
|
+
generatorPropsCPP,
|
|
335
|
+
generatorPropsH,
|
|
336
|
+
generatorShadowNodeCPP,
|
|
337
|
+
generatorShadowNodeH,
|
|
338
|
+
generatorStateCPP,
|
|
339
|
+
generatorStateH,
|
|
340
|
+
);
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
if (componentsWindows) {
|
|
344
|
+
const generateComponentWindows = createComponentGenerator({
|
|
345
|
+
namespace,
|
|
346
|
+
cppStringType,
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
componentGenerators.push(generateComponentWindows);
|
|
350
|
+
}
|
|
333
351
|
|
|
334
352
|
componentGenerators.forEach(generator => {
|
|
335
353
|
const generated: Map<string, string> = generator(
|
|
@@ -369,6 +387,8 @@ export function runCodeGen(options: CodeGenOptions): boolean {
|
|
|
369
387
|
modulesCxx,
|
|
370
388
|
modulesTypeScriptTypes,
|
|
371
389
|
modulesWindows,
|
|
390
|
+
componentsWindows,
|
|
391
|
+
internalComponents,
|
|
372
392
|
namespace,
|
|
373
393
|
outputDirectory,
|
|
374
394
|
cppStringType,
|
|
@@ -381,6 +401,8 @@ export function runCodeGen(options: CodeGenOptions): boolean {
|
|
|
381
401
|
modulesCxx,
|
|
382
402
|
modulesTypeScriptTypes,
|
|
383
403
|
modulesWindows,
|
|
404
|
+
componentsWindows,
|
|
405
|
+
internalComponents,
|
|
384
406
|
namespace,
|
|
385
407
|
outputDirectory,
|
|
386
408
|
cppStringType,
|