@react-native-windows/codegen 0.75.0 → 0.76.0-preview.1

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.
Files changed (41) hide show
  1. package/CHANGELOG.md +76 -10
  2. package/lib-commonjs/Cli.js +12 -1
  3. package/lib-commonjs/Cli.js.map +1 -1
  4. package/lib-commonjs/generators/AliasGen.js +1 -2
  5. package/lib-commonjs/generators/AliasGen.js.map +1 -1
  6. package/lib-commonjs/generators/AliasManaging.d.ts +3 -3
  7. package/lib-commonjs/generators/AliasManaging.js.map +1 -1
  8. package/lib-commonjs/generators/GenerateComponentWindows.d.ts +13 -0
  9. package/lib-commonjs/generators/GenerateComponentWindows.js +336 -0
  10. package/lib-commonjs/generators/GenerateComponentWindows.js.map +1 -0
  11. package/lib-commonjs/generators/GenerateNM2.js +2 -2
  12. package/lib-commonjs/generators/GenerateNM2.js.map +1 -1
  13. package/lib-commonjs/generators/GenerateTypeScript.js +1 -1
  14. package/lib-commonjs/generators/GenerateTypeScript.js.map +1 -1
  15. package/lib-commonjs/generators/ObjectTypes.d.ts +2 -2
  16. package/lib-commonjs/generators/ObjectTypes.js +3 -1
  17. package/lib-commonjs/generators/ObjectTypes.js.map +1 -1
  18. package/lib-commonjs/generators/ParamTypes.d.ts +2 -1
  19. package/lib-commonjs/generators/ParamTypes.js +46 -2
  20. package/lib-commonjs/generators/ParamTypes.js.map +1 -1
  21. package/lib-commonjs/generators/PropObjectTypes.d.ts +18 -0
  22. package/lib-commonjs/generators/PropObjectTypes.js +217 -0
  23. package/lib-commonjs/generators/PropObjectTypes.js.map +1 -0
  24. package/lib-commonjs/generators/ValidateMethods.d.ts +6 -1
  25. package/lib-commonjs/generators/ValidateMethods.js +30 -2
  26. package/lib-commonjs/generators/ValidateMethods.js.map +1 -1
  27. package/lib-commonjs/index.d.ts +3 -1
  28. package/lib-commonjs/index.js +16 -13
  29. package/lib-commonjs/index.js.map +1 -1
  30. package/package.json +8 -8
  31. package/src/Cli.ts +12 -1
  32. package/src/generators/AliasGen.ts +1 -1
  33. package/src/generators/AliasManaging.ts +12 -12
  34. package/src/generators/GenerateComponentWindows.ts +392 -0
  35. package/src/generators/GenerateNM2.ts +2 -2
  36. package/src/generators/GenerateTypeScript.ts +3 -2
  37. package/src/generators/ObjectTypes.ts +5 -2
  38. package/src/generators/ParamTypes.ts +90 -3
  39. package/src/generators/PropObjectTypes.ts +233 -0
  40. package/src/generators/ValidateMethods.ts +86 -5
  41. package/src/index.ts +25 -2
package/CHANGELOG.md CHANGED
@@ -1,26 +1,92 @@
1
1
  # Change Log - @react-native-windows/codegen
2
2
 
3
- This log was last generated on Mon, 19 Aug 2024 20:18:09 GMT and should not be manually modified.
3
+ <!-- This log was last generated on Mon, 30 Sep 2024 21:36:51 GMT and should not be manually modified. -->
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
- ## 0.75.0
7
+ ## 0.76.0-preview.1
8
8
 
9
- Mon, 19 Aug 2024 20:18:09 GMT
9
+ Mon, 30 Sep 2024 21:36:51 GMT
10
10
 
11
- ### Patches
11
+ ### Changes
12
12
 
13
- - Promote 0.75 to latest (tatianakapos@microsoft.com)
14
- - Bump @react-native-windows/fs to v0.75.0
13
+ - Promote 0.76 to preview (tatianakapos@microsoft.com)
14
+ - Bump @react-native-windows/fs to v0.76.0-preview.1
15
15
 
16
- ## 0.75.0-preview.1
16
+ ## 0.0.0-canary.104
17
17
 
18
- Mon, 15 Jul 2024 16:52:21 GMT
18
+ Thu, 26 Sep 2024 17:38:27 GMT
19
19
 
20
20
  ### Changes
21
21
 
22
- - Promote 0.75 to preview (tatianakapos@microsoft.com)
23
- - Bump @react-native-windows/fs to v0.75.0-preview.1
22
+ - Bump @react-native-windows/fs to v0.0.0-canary.56
23
+ - Bump @rnw-scripts/eslint-config to v1.2.27
24
+ - Bump @rnw-scripts/jest-unittest-config to v1.5.9
25
+ - Bump @rnw-scripts/just-task to v2.3.44
26
+
27
+ ## 0.0.0-canary.103
28
+
29
+ Mon, 16 Sep 2024 21:21:15 GMT
30
+
31
+ ### Changes
32
+
33
+ - [Fabric] Add FocusNavigationDirection and allow overriding of default command handling (30809111+acoates-ms@users.noreply.github.com)
34
+
35
+ ## 0.0.0-canary.102
36
+
37
+ Sat, 07 Sep 2024 05:14:11 GMT
38
+
39
+ ### Changes
40
+
41
+ - Integrate 8/31 (34109996+chiaramooney@users.noreply.github.com)
42
+
43
+ ## 0.0.0-canary.101
44
+
45
+ Fri, 06 Sep 2024 05:14:01 GMT
46
+
47
+ ### Changes
48
+
49
+ - [Fabric] Add native component codegen (30809111+acoates-ms@users.noreply.github.com)
50
+
51
+ ## 0.0.0-canary.100
52
+
53
+ Wed, 14 Aug 2024 05:14:30 GMT
54
+
55
+ ### Changes
56
+
57
+ - Add support for turbomodule eventemitters, and codegen (30809111+acoates-ms@users.noreply.github.com)
58
+
59
+ ## 0.0.0-canary.99
60
+
61
+ Thu, 08 Aug 2024 05:16:48 GMT
62
+
63
+ ### Changes
64
+
65
+ - Integrate 7/1 (jthysell@microsoft.com)
66
+ - Bump @react-native-windows/fs to v0.0.0-canary.55
67
+ - Bump @rnw-scripts/eslint-config to v1.2.26
68
+ - Bump @rnw-scripts/just-task to v2.3.43
69
+
70
+ ## 0.0.0-canary.98
71
+
72
+ Wed, 24 Jul 2024 05:24:36 GMT
73
+
74
+ ### Changes
75
+
76
+ - integrate 0.75.0-nightly-20240618-5df5ed1a8 (tatianakapos@microsoft.com)
77
+ - Bump @react-native-windows/fs to v0.0.0-canary.54
78
+ - Bump @rnw-scripts/eslint-config to v1.2.25
79
+ - Bump @rnw-scripts/just-task to v2.3.42
80
+
81
+ ## 0.0.0-canary.97
82
+
83
+ Wed, 10 Jul 2024 05:15:30 GMT
84
+
85
+ ### Changes
86
+
87
+ - Bump @react-native-windows/fs to v0.0.0-canary.53
88
+ - Bump @rnw-scripts/eslint-config to v1.2.24
89
+ - Bump @rnw-scripts/just-task to v2.3.41
24
90
 
25
91
  ## 0.0.0-canary.96
26
92
 
@@ -71,6 +71,17 @@ const argv = yargs_1.default.options({
71
71
  describe: 'generate data types in a separate file',
72
72
  default: false,
73
73
  },
74
+ componentsWindows: {
75
+ type: 'boolean',
76
+ describe: 'generate component cpp files for custom native components',
77
+ default: false,
78
+ },
79
+ internalComponents: {
80
+ type: 'boolean',
81
+ describe: 'generate non-ABI cpp/h for internal usage of built in native components [Only used within RNW itself]',
82
+ default: false,
83
+ hidden: true,
84
+ }
74
85
  }).argv;
75
86
  if ((argv.file && argv.files) || (!argv.file && !argv.files)) {
76
87
  console.error('You must specify either --file or --files.');
@@ -86,7 +97,7 @@ if (argv.cppStringType !== 'std::string' &&
86
97
  // until yargs.options get improved in the future
87
98
  const changesNecessary = (0, index_1.runCodeGen)(argv);
88
99
  if (argv.test && changesNecessary) {
89
- console.error('There is a change in the output of codegen. Rerun "react-native codegen-windows" to regenerate.');
100
+ console.error('There is a change in the output of codegen. Rerun "npx @react-native-community/cli codegen-windows" to regenerate.');
90
101
  process.exit(2);
91
102
  }
92
103
  //# sourceMappingURL=Cli.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,0BAA0B;KACrC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,0CAA0C;QACpD,OAAO,EAAE,KAAK;KACf;IACD,cAAc,EAAE;Q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AAC,CAAC;CACjB;AAED,yCAAyC;AACzC,yDAAyD;AACzD,iDAAiD;AACjD,MAAM,gBAAgB,GAAG,IAAA,kBAAU,EAAiB,IAAI,CAAC,CAAC;AAE1D,IAAI,IAAI,CAAC,IAAI,IAAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,kGAAkG,CACnG,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, runCodeGen} from './index';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'string',\n array: true,\n describe: 'glob patterns for files which contains specs',\n },\n modulesTypeScriptTypes: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n modulesCxx: {\n type: 'boolean',\n describe: 'generate C++ JSI turbo module spec files',\n default: false,\n },\n modulesWindows: {\n type: 'boolean',\n describe: 'generate turbo module spec files for REACT_MODULE',\n default: false,\n },\n methodOnly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\n default: false,\n },\n outputDirectory: {\n type: 'string',\n describe: 'output directory',\n default: 'codegen',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\n default: false,\n },\n namespace: {\n type: 'string',\n describe: 'C++/C# Namespace to put generated native modules in',\n default: 'MyNamespace',\n },\n libraryName: {\n type: 'string',\n required: true,\n describe: 'Used for part of the path generated within the codegen dir',\n },\n cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\n },\n separateDataTypes: {\n type: 'boolean',\n describe: 'generate data types in a separate file',\n default: false,\n },\n}).argv;\n\nif ((argv.file && argv.files) || (!argv.file && !argv.files)) {\n console.error('You must specify either --file or --files.');\n process.exit(1);\n}\n\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"react-native codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
1
+ {"version":3,"file":"Cli.js","sourceRoot":"","sources":["../src/Cli.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;AAEH,kDAA0B;AAC1B,mCAAmD;AAEnD,MAAM,IAAI,GAAG,eAAK,CAAC,OAAO,CAAC;IACzB,IAAI,EAAE;QACJ,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,0BAA0B;KACrC;IACD,KAAK,EAAE;QACL,IAAI,EAAE,QAAQ;QACd,KAAK,EAAE,IAAI;QACX,QAAQ,EAAE,8CAA8C;KACzD;IACD,sBAAsB,EAAE;QACtB,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,sDAAsD;QAChE,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,0CAA0C;QACpD,OAAO,EAAE,KAAK;KACf;IACD,cAAc,EAAE;QACd,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,mDAAmD;QAC7D,OAAO,EAAE,KAAK;KACf;IACD,UAAU,EAAE;QACV,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,wDAAwD;QAClE,OAAO,EAAE,KAAK;KACf;IACD,eAAe,EAAE;QACf,IAAI,EAAE,QAAQ;QACd,QAAQ,EAAE,kBAAkB;QAC5B,OAAO,EAAE,SAAS;KACnB;IACD,IAAI,EAAE;QACJ,IAAI,EAAE,SAAS;QACf,QAAQ,EAAE,+CAA+C;QACzD,OAAO,EAAE,KAAK;KACf;IACD,SAA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AAI,gBAAgB,EAAE;IACjC,OAAO,CAAC,KAAK,CACX,qHAAqH,CACtH,CAAC;IACF,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;CACjB","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n *\n * @format\n */\n\nimport yargs from 'yargs';\nimport {CodeGenOptions, runCodeGen} from './index';\n\nconst argv = yargs.options({\n file: {\n type: 'string',\n describe: 'file which contains spec',\n },\n files: {\n type: 'string',\n array: true,\n describe: 'glob patterns for files which contains specs',\n },\n modulesTypeScriptTypes: {\n type: 'boolean',\n describe: 'generate turbo module definition files in TypeScript',\n default: false,\n },\n modulesCxx: {\n type: 'boolean',\n describe: 'generate C++ JSI turbo module spec files',\n default: false,\n },\n modulesWindows: {\n type: 'boolean',\n describe: 'generate turbo module spec files for REACT_MODULE',\n default: false,\n },\n methodOnly: {\n type: 'boolean',\n describe: 'generate only method metadata in C++ turbo module spec',\n default: false,\n },\n outputDirectory: {\n type: 'string',\n describe: 'output directory',\n default: 'codegen',\n },\n test: {\n type: 'boolean',\n describe: 'Verify that the generated output is unchanged',\n default: false,\n },\n namespace: {\n type: 'string',\n describe: 'C++/C# Namespace to put generated native modules in',\n default: 'MyNamespace',\n },\n libraryName: {\n type: 'string',\n required: true,\n describe: 'Used for part of the path generated within the codegen dir',\n },\n cppStringType: {\n choices: ['std::string', 'std::wstring'],\n describe:\n 'C++ string type in generated code, should be \"std::string\" or \"std::wstring\"',\n default: 'std::string',\n },\n separateDataTypes: {\n type: 'boolean',\n describe: 'generate data types in a separate file',\n default: false,\n },\n componentsWindows: {\n type: 'boolean',\n describe: 'generate component cpp files for custom native components',\n default: false,\n },\n internalComponents: {\n type: 'boolean',\n describe: 'generate non-ABI cpp/h for internal usage of built in native components [Only used within RNW itself]',\n default: false,\n hidden: true,\n }\n}).argv;\n\nif ((argv.file && argv.files) || (!argv.file && !argv.files)) {\n console.error('You must specify either --file or --files.');\n process.exit(1);\n}\n\nif (\n argv.cppStringType !== 'std::string' &&\n argv.cppStringType !== 'std::wstring'\n) {\n console.error('cppStringType should be \"std::string\" or \"std::wstring\".');\n process.exit(1);\n}\n\n// type casting is necessary here because\n// cppStringType does not become union of string literals\n// until yargs.options get improved in the future\nconst changesNecessary = runCodeGen(<CodeGenOptions>argv);\n\nif (argv.test && changesNecessary) {\n console.error(\n 'There is a change in the output of codegen. Rerun \"npx @react-native-community/cli codegen-windows\" to regenerate.',\n );\n process.exit(2);\n}\n"]}
@@ -35,8 +35,7 @@ function createAliasMap(nativeModuleAliases) {
35
35
  }
36
36
  exports.createAliasMap = createAliasMap;
37
37
  function getArrayTypeName(type) {
38
- var _a;
39
- if (type.type === 'ArrayTypeAnnotation' && ((_a = type.elementType) === null || _a === void 0 ? void 0 : _a.type) === 'TypeAliasTypeAnnotation') {
38
+ if (type.type === 'ArrayTypeAnnotation' && type.elementType.type === 'TypeAliasTypeAnnotation') {
40
39
  return type.elementType.name;
41
40
  }
42
41
  return '';
@@ -1 +1 @@
1
- {"version":3,"file":"AliasGen.js","sourceRoot":"","sources":["../../src/generators/AliasGen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,mDAA0D;AAC1D,+CAAgE;AAEhE,SAAS,gCAAgC,CACvC,IAAsC,EACtC,OAAiB,EACjB,aAAqB,EACrB,MAAc,EACd,OAA0B;IAE1B,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,EAAE,EAAE;QAClE,IAAI,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC;QACnC,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,wBAAwB,EAAE;YAC/D,QAAQ,GAAG,EAAC,IAAI,EAAE,wBAAwB,EAAE,cAAc,EAAE,QAAQ,EAAC,CAAC;SACvE;QACD,OAAO,GAAG,MAAM,GAAG,IAAA,4BAAc,EAC/B,QAAQ,EACR,OAAO,EACP,GAAG,aAAa,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B,uCAAuC;IACvC,KAAK,MAAM,SAAS,IAAI,IAAI,EAAE;QAC5B,wDAAwD;QACxD,uCAAuC;QACvC,sCAAsC;QACtC,mBAAmB,CAAC,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,EAAE,UAAU,CAAC,CAAC;QACxE,+DAA+D;QAC/D,iDAAiD;QACjD,2EAA2E;QAC3E,mCAAmC,CACjC,OAAO,EACP,SAAS,EACT,UAAU,EACV,OAAO,CACR,CAAC;QACF,2CAA2C;QAC3C,qCAAqC;QACrC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,SAAS,CAAC,EAAE;YACnC,UAAU,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;SAC5B;KACF;AACH,CAAC;AAED,SAAgB,eAAe,CAC7B,OAAiB,EACjB,OAA0B;IAE1B,MAAM,SAAS,GAAiB,EAAE,CAAC;IACnC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAE7E,0DAA0D;IAC1D,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,gBAAgB,GAAG,EAAE,CAAC;IAC1B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;QAClC,WAAW,GAAG,GAAG,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;QACjE,gBAAgB,GAAG,GAAG,gBAAgB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;KAC5E;IACD,OAAO,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAhBD,0CAgBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {CppCodegenOptions, translateField} from './ObjectTypes';\n\nfunction translateObjectMembersDefinition(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n options: CppCodegenOptions,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n let propType = prop.typeAnnotation;\n if (prop.optional && propType.type !== 'NullableTypeAnnotation') {\n propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};\n }\n return `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n options,\n )} ${prop.name};`;\n })\n .join('\\n');\n}\n\nfunction translateObjectMembersReflection(\n type: NativeModuleObjectTypeAnnotation,\n aliasCppName: string,\n prefix: string,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n return `${prefix}{L\"${prop.name}\", &${aliasCppName}::${prop.name}},`;\n })\n .join('\\n');\n}\n\nexport function createAliasMap(nativeModuleAliases: {\n [name: string]: NativeModuleObjectTypeAnnotation;\n}): AliasMap {\n const aliases: AliasMap = {types: {}, jobs: Object.keys(nativeModuleAliases)};\n for (const aliasName of aliases.jobs) {\n aliases.types[aliasName] = nativeModuleAliases[aliasName];\n }\n return aliases;\n}\n\ninterface AliasCode {\n definition: string;\n reflection: string;\n}\n\ninterface AliasCodeMap {\n [name: string]: AliasCode;\n}\n\nfunction getArrayTypeName(\n type: Nullable<NativeModuleBaseTypeAnnotation>): string {\n if (type.type === 'ArrayTypeAnnotation' && type.elementType?.type === 'TypeAliasTypeAnnotation') {\n return type.elementType.name;\n }\n\n return '';\n}\n\nfunction checkTypes(\n aliases: AliasMap,\n type: NativeModuleObjectTypeAnnotation,\n aliasOrder: string[]): void {\n for (const prop of type.properties) {\n const propType = prop.typeAnnotation;\n let propName = '';\n\n if (propType.type === 'TypeAliasTypeAnnotation') {\n propName = propType.name;\n }\n\n if (propType.type === 'ArrayTypeAnnotation') {\n propName = getArrayTypeName(propType);\n }\n\n if (propName !== '' && !aliasOrder.includes(prop.name) && !aliases.jobs.includes(propName)) {\n aliases.jobs.push(propName);\n }\n }\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n options: CppCodegenOptions,\n aliasOrder: string[],\n): void {\n const aliasCppName = getAliasCppName(aliasName);\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n\n checkTypes(aliases, aliasType, aliasOrder);\n\n const definition = `\nstruct ${aliasCppName} {\n${translateObjectMembersDefinition(\n aliasType,\n aliases,\n aliasName,\n ' ',\n options,\n)}\n};\n`;\n const reflection = `\ninline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {\n winrt::Microsoft::ReactNative::FieldMap fieldMap {\n${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}\n };\n return fieldMap;\n}\n`;\n aliasCode[aliasName] = {definition, reflection};\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n options: CppCodegenOptions,\n): void {\n // retrieve and clean all ungenerated aliases\n const jobs = aliases.jobs;\n aliases.jobs = [];\n\n // generate each one in its found order\n for (const aliasName of jobs) {\n // generate a new struct and all fields will be examined\n // new anonymous objects could be found\n // they will be stored in aliases.jobs\n generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder);\n // nested C++ structs must be put before the current C++ struct\n // as they will be used in the current C++ struct\n // the order will be perfectly and easily ensured by doing this recursively\n generateNestedAliasesInCorrectOrder(\n aliases,\n aliasCode,\n aliasOrder,\n options,\n );\n // all referenced C++ structs are generated\n // put the current one following them\n if (!aliasOrder.includes(aliasName)) {\n aliasOrder.push(aliasName);\n }\n }\n}\n\nexport function generateAliases(\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);\n\n // aliasOrder now has the correct order of C++ struct code\n let customTypes = '';\n let customReflection = '';\n for (const aliasName of aliasOrder) {\n customTypes = `${customTypes}${aliasCode[aliasName].definition}`;\n customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;\n }\n return [customTypes, customReflection];\n}\n"]}
1
+ {"version":3,"file":"AliasGen.js","sourceRoot":"","sources":["../../src/generators/AliasGen.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAQb,mDAA0D;AAC1D,+CAAgE;AAEhE,SAAS,gCAAgC,CACvC,IAAsC,EACtC,OAAiB,EACjB,aAAqB,EACrB,MAAc,EACd,OAA0B;IAE1B,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,EAAE,EAAE;QAClE,IAAI,QAAQ,GAAG,IAAI,CAAC,cAAc,CAAC;QACnC,IAAI,IAAI,CAAC,QAAQ,IAAI,QAAQ,CAAC,IAAI,KAAK,wBAAwB,EAAE;YAC/D,QAAQ,GAAG,EAAC,IAAI,EAAE,wBAAwB,EAAE,cAAc,EAAE,QAAQ,EAAC,CAAC;SACvE;QACD,OAAO,GAAG,MAAM,GAAG,IAAA,4BAAc,EAC/B,QAAQ,EACR,OAAO,EACP,GAAG,aAAa,IAAI,IAAI,CAAC,IAAI,EAAE,EAC/B,OAAO,CACR,IAAI,IAAI,CAAC,IAAI,GAAG,CAAC;IACpB,CAAC,CAAC;SACD,IAAI,CAAC,IAAI,CAAC,CAAC;AAChB,CAAC;AAED,SAAS,gCAAgC,CACvC,IAAsC,EACtC,YAAoB,EACpB,MAAc;IAEd,OAAO,IAAI,CAAC,UAAU;SACnB,GAAG,CAAC,CAAC,IAA0D,EAAE,EAAE;QAClE,OAAO,GAAG,MAAM,MAAM,IAAI,CAAC,IAAI,OAAO,YAAY,KAAK,IAAI,CAAC,IAAI,IAAI,CAAC;IACvE,CAAC,CAAC;SACD,I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AAC,SAAS,CAAC,CAAC;SAC5B;KACF;AACH,CAAC;AAED,SAAgB,eAAe,CAC7B,OAAiB,EACjB,OAA0B;IAE1B,MAAM,SAAS,GAAiB,EAAE,CAAC;IACnC,MAAM,UAAU,GAAa,EAAE,CAAC;IAChC,mCAAmC,CAAC,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,OAAO,CAAC,CAAC;IAE7E,0DAA0D;IAC1D,IAAI,WAAW,GAAG,EAAE,CAAC;IACrB,IAAI,gBAAgB,GAAG,EAAE,CAAC;IAC1B,KAAK,MAAM,SAAS,IAAI,UAAU,EAAE;QAClC,WAAW,GAAG,GAAG,WAAW,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;QACjE,gBAAgB,GAAG,GAAG,gBAAgB,GAAG,SAAS,CAAC,SAAS,CAAC,CAAC,UAAU,EAAE,CAAC;KAC5E;IACD,OAAO,CAAC,WAAW,EAAE,gBAAgB,CAAC,CAAC;AACzC,CAAC;AAhBD,0CAgBC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n NativeModuleBaseTypeAnnotation,\n NativeModuleObjectTypeAnnotation,\n NamedShape,\n Nullable,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {AliasMap, getAliasCppName} from './AliasManaging';\nimport {CppCodegenOptions, translateField} from './ObjectTypes';\n\nfunction translateObjectMembersDefinition(\n type: NativeModuleObjectTypeAnnotation,\n aliases: AliasMap,\n baseAliasName: string,\n prefix: string,\n options: CppCodegenOptions,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n let propType = prop.typeAnnotation;\n if (prop.optional && propType.type !== 'NullableTypeAnnotation') {\n propType = {type: 'NullableTypeAnnotation', typeAnnotation: propType};\n }\n return `${prefix}${translateField(\n propType,\n aliases,\n `${baseAliasName}_${prop.name}`,\n options,\n )} ${prop.name};`;\n })\n .join('\\n');\n}\n\nfunction translateObjectMembersReflection(\n type: NativeModuleObjectTypeAnnotation,\n aliasCppName: string,\n prefix: string,\n) {\n return type.properties\n .map((prop: NamedShape<Nullable<NativeModuleBaseTypeAnnotation>>) => {\n return `${prefix}{L\"${prop.name}\", &${aliasCppName}::${prop.name}},`;\n })\n .join('\\n');\n}\n\nexport function createAliasMap(nativeModuleAliases: {\n [name: string]: NativeModuleObjectTypeAnnotation;\n}): AliasMap {\n const aliases: AliasMap = {types: {}, jobs: Object.keys(nativeModuleAliases)};\n for (const aliasName of aliases.jobs) {\n aliases.types[aliasName] = nativeModuleAliases[aliasName];\n }\n return aliases;\n}\n\ninterface AliasCode {\n definition: string;\n reflection: string;\n}\n\ninterface AliasCodeMap {\n [name: string]: AliasCode;\n}\n\nfunction getArrayTypeName(\n type: Nullable<NativeModuleBaseTypeAnnotation>): string {\n if (type.type === 'ArrayTypeAnnotation' && type.elementType.type === 'TypeAliasTypeAnnotation') {\n return type.elementType.name;\n }\n\n return '';\n}\n\nfunction checkTypes(\n aliases: AliasMap,\n type: NativeModuleObjectTypeAnnotation,\n aliasOrder: string[]): void {\n for (const prop of type.properties) {\n const propType = prop.typeAnnotation;\n let propName = '';\n\n if (propType.type === 'TypeAliasTypeAnnotation') {\n propName = propType.name;\n }\n\n if (propType.type === 'ArrayTypeAnnotation') {\n propName = getArrayTypeName(propType);\n }\n\n if (propName !== '' && !aliasOrder.includes(prop.name) && !aliases.jobs.includes(propName)) {\n aliases.jobs.push(propName);\n }\n }\n}\n\nfunction generateSingleAlias(\n aliases: AliasMap,\n aliasName: string,\n aliasCode: AliasCodeMap,\n options: CppCodegenOptions,\n aliasOrder: string[],\n): void {\n const aliasCppName = getAliasCppName(aliasName);\n const aliasType = <NativeModuleObjectTypeAnnotation>aliases.types[aliasName];\n\n checkTypes(aliases, aliasType, aliasOrder);\n\n const definition = `\nstruct ${aliasCppName} {\n${translateObjectMembersDefinition(\n aliasType,\n aliases,\n aliasName,\n ' ',\n options,\n)}\n};\n`;\n const reflection = `\ninline winrt::Microsoft::ReactNative::FieldMap GetStructInfo(${aliasCppName}*) noexcept {\n winrt::Microsoft::ReactNative::FieldMap fieldMap {\n${translateObjectMembersReflection(aliasType, aliasCppName, ' ')}\n };\n return fieldMap;\n}\n`;\n aliasCode[aliasName] = {definition, reflection};\n}\n\nfunction generateNestedAliasesInCorrectOrder(\n aliases: AliasMap,\n aliasCode: AliasCodeMap,\n aliasOrder: string[],\n options: CppCodegenOptions,\n): void {\n // retrieve and clean all ungenerated aliases\n const jobs = aliases.jobs;\n aliases.jobs = [];\n\n // generate each one in its found order\n for (const aliasName of jobs) {\n // generate a new struct and all fields will be examined\n // new anonymous objects could be found\n // they will be stored in aliases.jobs\n generateSingleAlias(aliases, aliasName, aliasCode, options, aliasOrder);\n // nested C++ structs must be put before the current C++ struct\n // as they will be used in the current C++ struct\n // the order will be perfectly and easily ensured by doing this recursively\n generateNestedAliasesInCorrectOrder(\n aliases,\n aliasCode,\n aliasOrder,\n options,\n );\n // all referenced C++ structs are generated\n // put the current one following them\n if (!aliasOrder.includes(aliasName)) {\n aliasOrder.push(aliasName);\n }\n }\n}\n\nexport function generateAliases(\n aliases: AliasMap,\n options: CppCodegenOptions,\n): [string, string] {\n const aliasCode: AliasCodeMap = {};\n const aliasOrder: string[] = [];\n generateNestedAliasesInCorrectOrder(aliases, aliasCode, aliasOrder, options);\n\n // aliasOrder now has the correct order of C++ struct code\n let customTypes = '';\n let customReflection = '';\n for (const aliasName of aliasOrder) {\n customTypes = `${customTypes}${aliasCode[aliasName].definition}`;\n customReflection = `${customReflection}${aliasCode[aliasName].reflection}`;\n }\n return [customTypes, customReflection];\n}\n"]}
@@ -6,10 +6,10 @@
6
6
  import type { NativeModuleObjectTypeAnnotation } from '@react-native/codegen/lib/CodegenSchema';
7
7
  export declare function setPreferredModuleName(moduleName: string): void;
8
8
  export declare function getAliasCppName(typeName: string): string;
9
- export interface AliasMap {
9
+ export interface AliasMap<T = NativeModuleObjectTypeAnnotation> {
10
10
  types: {
11
- [name: string]: NativeModuleObjectTypeAnnotation | undefined;
11
+ [name: string]: T | undefined;
12
12
  };
13
13
  jobs: string[];
14
14
  }
15
- export declare function getAnonymousAliasCppName(aliases: AliasMap, baseAliasName: string, objectType: NativeModuleObjectTypeAnnotation): string;
15
+ export declare function getAnonymousAliasCppName<T = NativeModuleObjectTypeAnnotation>(aliases: AliasMap<T>, baseAliasName: string, objectType: T): string;
@@ -1 +1 @@
1
- {"version":3,"file":"AliasManaging.js","sourceRoot":"","sources":["../../src/generators/AliasManaging.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAIb,IAAI,mBAAmB,GAAW,EAAE,CAAC;AAErC,SAAgB,sBAAsB,CAAC,UAAkB;IACvD,mBAAmB,GAAG,UAAU,CAAC;AACnC,CAAC;AAFD,wDAEC;AAED,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO,GAAG,mBAAmB,QAAQ,QAAQ,EAAE,CAAC;AAClD,CAAC;AAFD,0CAEC;AAOD,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAKnD,SAAS,oBAAoB,CAC3B,OAAiB,EACjB,aAAqB,EACrB,QAAwB;IAExB,QAAQ,CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAgB,wBAAwB,CACtC,OAAiB,EACjB,aAAqB,EACrB,UAA4C;IAE5C,iDAAiD;IACjD,6CAA6C;IAC7C,yBAAyB;IACzB,uFAAuF;IACvF,MAAM,QAAQ,GAAmB,UAAU,CAAC;IAC5C,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACxC,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;KAC7B;IAED,iDAAiD;IACjD,+BAA+B;IAC/B,8DAA8D;IAC9D,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE;QAC9C,OAAO,eAAe,CACpB,oBAAoB,CAAC,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CACvD,CAAC;KACH;IAED,qCAAqC;IACrC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC,KAAK,SAAS,EAAE;QAC9D,KAAK,EAAE,CAAC;KACT;IAED,OAAO,eAAe,CACpB,oBAAoB,CAAC,OAAO,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,CACpE,CAAC;AACJ,CAAC;AAjCD,4DAiCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleObjectTypeAnnotation} from '@react-native/codegen/lib/CodegenSchema';\n\nlet preferredModuleName: string = '';\n\nexport function setPreferredModuleName(moduleName: string): void {\n preferredModuleName = moduleName;\n}\n\nexport function getAliasCppName(typeName: string): string {\n return `${preferredModuleName}Spec_${typeName}`;\n}\n\nexport interface AliasMap {\n types: {[name: string]: NativeModuleObjectTypeAnnotation | undefined};\n jobs: string[];\n}\n\nconst ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';\ninterface ExtendedObject extends NativeModuleObjectTypeAnnotation {\n '$RNW-TURBOMODULE-ALIAS'?: string;\n}\n\nfunction recordAnonymousAlias(\n aliases: AliasMap,\n baseAliasName: string,\n extended: ExtendedObject,\n): string {\n extended[ExtendedObjectKey] = baseAliasName;\n aliases.types[baseAliasName] = extended;\n aliases.jobs.push(baseAliasName);\n return baseAliasName;\n}\n\nexport function getAnonymousAliasCppName(\n aliases: AliasMap,\n baseAliasName: string,\n objectType: NativeModuleObjectTypeAnnotation,\n): string {\n // someone found an anonymous object literal type\n // if the ExtendedObjectKey flag has been set\n // then it is a known one\n // this happens because method signatures are generate twice in spec and error messages\n const extended = <ExtendedObject>objectType;\n const key = extended[ExtendedObjectKey];\n if (key !== undefined) {\n return getAliasCppName(key);\n }\n\n // if the ExtendedObjectKey flag has not been set\n // it means it is a unknown one\n // associate the name with this object literal type and return\n if (aliases.types[baseAliasName] === undefined) {\n return getAliasCppName(\n recordAnonymousAlias(aliases, baseAliasName, extended),\n );\n }\n\n // sometimes names could be anonymous\n let index = 2;\n while (aliases.types[`${baseAliasName}${index}`] !== undefined) {\n index++;\n }\n\n return getAliasCppName(\n recordAnonymousAlias(aliases, `${baseAliasName}${index}`, extended),\n );\n}\n"]}
1
+ {"version":3,"file":"AliasManaging.js","sourceRoot":"","sources":["../../src/generators/AliasManaging.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AAIb,IAAI,mBAAmB,GAAW,EAAE,CAAC;AAErC,SAAgB,sBAAsB,CAAC,UAAkB;IACvD,mBAAmB,GAAG,UAAU,CAAC;AACnC,CAAC;AAFD,wDAEC;AAED,SAAgB,eAAe,CAAC,QAAgB;IAC9C,OAAO,GAAG,mBAAmB,QAAQ,QAAQ,EAAE,CAAC;AAClD,CAAC;AAFD,0CAEC;AAOD,MAAM,iBAAiB,GAAG,wBAAwB,CAAC;AAKnD,SAAS,oBAAoB,CAC3B,OAAoB,EACpB,aAAqB,EACrB,QAA2B;IAE3B,QAAQ,CAAC,iBAAiB,CAAC,GAAG,aAAa,CAAC;IAC5C,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,GAAG,QAAQ,CAAC;IACxC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;IACjC,OAAO,aAAa,CAAC;AACvB,CAAC;AAED,SAAgB,wBAAwB,CACtC,OAAoB,EACpB,aAAqB,EACrB,UAAa;IAEb,iDAAiD;IACjD,6CAA6C;IAC7C,yBAAyB;IACzB,uFAAuF;IACvF,MAAM,QAAQ,GAAsB,UAAU,CAAC;IAC/C,MAAM,GAAG,GAAG,QAAQ,CAAC,iBAAiB,CAAC,CAAC;IACxC,IAAI,GAAG,KAAK,SAAS,EAAE;QACrB,OAAO,eAAe,CAAC,GAAG,CAAC,CAAC;KAC7B;IAED,iDAAiD;IACjD,+BAA+B;IAC/B,8DAA8D;IAC9D,IAAI,OAAO,CAAC,KAAK,CAAC,aAAa,CAAC,KAAK,SAAS,EAAE;QAC9C,OAAO,eAAe,CACpB,oBAAoB,CAAI,OAAO,EAAE,aAAa,EAAE,QAAQ,CAAC,CAC1D,CAAC;KACH;IAED,qCAAqC;IACrC,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,OAAO,OAAO,CAAC,KAAK,CAAC,GAAG,aAAa,GAAG,KAAK,EAAE,CAAC,KAAK,SAAS,EAAE;QAC9D,KAAK,EAAE,CAAC;KACT;IAED,OAAO,eAAe,CACpB,oBAAoB,CAAC,OAAO,EAAE,GAAG,aAAa,GAAG,KAAK,EAAE,EAAE,QAAQ,CAAC,CACpE,CAAC;AACJ,CAAC;AAjCD,4DAiCC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {NativeModuleObjectTypeAnnotation} from '@react-native/codegen/lib/CodegenSchema';\n\nlet preferredModuleName: string = '';\n\nexport function setPreferredModuleName(moduleName: string): void {\n preferredModuleName = moduleName;\n}\n\nexport function getAliasCppName(typeName: string): string {\n return `${preferredModuleName}Spec_${typeName}`;\n}\n\nexport interface AliasMap<T = NativeModuleObjectTypeAnnotation> {\n types: {[name: string]: T | undefined};\n jobs: string[];\n}\n\nconst ExtendedObjectKey = '$RNW-TURBOMODULE-ALIAS';\ntype ExtendedObject<T> = {\n '$RNW-TURBOMODULE-ALIAS'?: string;\n} & T;\n\nfunction recordAnonymousAlias<T = NativeModuleObjectTypeAnnotation>(\n aliases: AliasMap<T>,\n baseAliasName: string,\n extended: ExtendedObject<T>,\n): string {\n extended[ExtendedObjectKey] = baseAliasName;\n aliases.types[baseAliasName] = extended;\n aliases.jobs.push(baseAliasName);\n return baseAliasName;\n}\n\nexport function getAnonymousAliasCppName<T = NativeModuleObjectTypeAnnotation>(\n aliases: AliasMap<T>,\n baseAliasName: string,\n objectType: T,\n): string {\n // someone found an anonymous object literal type\n // if the ExtendedObjectKey flag has been set\n // then it is a known one\n // this happens because method signatures are generate twice in spec and error messages\n const extended = <ExtendedObject<T>>objectType;\n const key = extended[ExtendedObjectKey];\n if (key !== undefined) {\n return getAliasCppName(key);\n }\n\n // if the ExtendedObjectKey flag has not been set\n // it means it is a unknown one\n // associate the name with this object literal type and return\n if (aliases.types[baseAliasName] === undefined) {\n return getAliasCppName(\n recordAnonymousAlias<T>(aliases, baseAliasName, extended),\n );\n }\n\n // sometimes names could be anonymous\n let index = 2;\n while (aliases.types[`${baseAliasName}${index}`] !== undefined) {\n index++;\n }\n\n return getAliasCppName(\n recordAnonymousAlias(aliases, `${baseAliasName}${index}`, extended),\n );\n}\n"]}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ import type { SchemaType } from '@react-native/codegen/lib/CodegenSchema';
7
+ import type { CppStringTypes } from './ObjectTypes';
8
+ export type { CppStringTypes } from './ObjectTypes';
9
+ type FilesOutput = Map<string, string>;
10
+ export declare function createComponentGenerator({ namespace, cppStringType, }: {
11
+ namespace: string;
12
+ cppStringType: CppStringTypes;
13
+ }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
@@ -0,0 +1,336 @@
1
+ /**
2
+ * Copyright (c) Microsoft Corporation.
3
+ * Licensed under the MIT License.
4
+ * @format
5
+ */
6
+ 'use strict';
7
+ Object.defineProperty(exports, "__esModule", { value: true });
8
+ exports.createComponentGenerator = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ const PropObjectTypes_1 = require("./PropObjectTypes");
11
+ const headerTemplate = `/*
12
+ * This file is auto-generated from ::_COMPONENT_NAME_::NativeComponent spec file in flow / TypeScript.
13
+ */
14
+ #pragma once
15
+
16
+ #include <JSValueComposition.h>
17
+ #include <NativeModules.h>
18
+ #include <winrt/Microsoft.ReactNative.Composition.h>
19
+ #include <winrt/Microsoft.UI.Composition.h>`;
20
+ const propsTemplate = `REACT_STRUCT(::_PROPS_NAME_::)
21
+ struct ::_PROPS_NAME_:: : winrt::implements<::_PROPS_NAME_::, winrt::Microsoft::ReactNative::IComponentProps> {
22
+ ::_PROPS_NAME_::(winrt::Microsoft::ReactNative::ViewProps props) : ViewProps(props) {}
23
+
24
+ void SetProp(uint32_t hash, winrt::hstring propName, winrt::Microsoft::ReactNative::IJSValueReader value) noexcept {
25
+ winrt::Microsoft::ReactNative::ReadProp(hash, propName, value, *this);
26
+ }
27
+
28
+ ::_PROPS_FIELDS_::
29
+ const winrt::Microsoft::ReactNative::ViewProps ViewProps;
30
+ };`;
31
+ const propsObjectTemplate = `REACT_STRUCT(::_OBJECT_NAME_::)
32
+ struct ::_OBJECT_NAME_:: {
33
+ ::_OBJECT_FIELDS_::};
34
+ `;
35
+ const eventsObjectTemplate = `REACT_STRUCT(::_OBJECT_NAME_::)
36
+ struct ::_OBJECT_NAME_:: {
37
+ ::_OBJECT_FIELDS_::};
38
+ `;
39
+ const eventEmitterMethodTemplate = ` void ::_EVENT_NAME_::(::_EVENT_OBJECT_TYPE_:: &value) const {
40
+ m_eventEmitter.DispatchEvent(L"::_EVENT_NAME_NO_ON_::", [value](const winrt::Microsoft::ReactNative::IJSValueWriter writer) {
41
+ winrt::Microsoft::ReactNative::WriteValue(writer, value);
42
+ });
43
+ }`;
44
+ const eventEmitterTemplate = `::_COMPONENT_EVENT_OBJECT_TYPES_::
45
+
46
+ struct ::_EVENT_EMITTER_NAME_:: {
47
+ ::_EVENT_EMITTER_NAME_::(const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter)
48
+ : m_eventEmitter(eventEmitter) {}
49
+
50
+ ::_EVENT_EMITTER_USINGS_::
51
+
52
+ ::_EVENT_EMITTER_METHODS_::
53
+
54
+ private:
55
+ winrt::Microsoft::ReactNative::EventEmitter m_eventEmitter{nullptr};
56
+ };`;
57
+ const baseStructTemplate = `
58
+ template<typename TUserData>
59
+ struct Base::_COMPONENT_NAME_:: {
60
+
61
+ virtual void UpdateProps(
62
+ const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
63
+ const winrt::com_ptr<::_COMPONENT_NAME_::Props> &newProps,
64
+ const winrt::com_ptr<::_COMPONENT_NAME_::Props> &/*oldProps*/) noexcept {
65
+ m_props = newProps;
66
+ }
67
+
68
+ // UpdateState will only be called if this method is overridden
69
+ virtual void UpdateState(
70
+ const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
71
+ const winrt::Microsoft::ReactNative::IComponentState &/*newState*/) noexcept {
72
+ }
73
+
74
+ virtual void UpdateEventEmitter(const std::shared_ptr<::_COMPONENT_NAME_::EventEmitter> &eventEmitter) noexcept {
75
+ m_eventEmitter = eventEmitter;
76
+ }
77
+
78
+ // MountChildComponentView will only be called if this method is overridden
79
+ virtual void MountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
80
+ const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &/*args*/) noexcept {
81
+ }
82
+
83
+ // UnmountChildComponentView will only be called if this method is overridden
84
+ virtual void UnmountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
85
+ const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &/*args*/) noexcept {
86
+ }
87
+
88
+ // Initialize will only be called if this method is overridden
89
+ virtual void Initialize(const winrt::Microsoft::ReactNative::ComponentView &/*view*/) noexcept {
90
+ }
91
+
92
+ // CreateVisual will only be called if this method is overridden
93
+ virtual winrt::Microsoft::UI::Composition::Visual CreateVisual(const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
94
+ return view.as<winrt::Microsoft::ReactNative::Composition::ComponentView>().Compositor().CreateSpriteVisual();
95
+ }
96
+
97
+ // FinalizeUpdate will only be called if this method is overridden
98
+ virtual void FinalizeUpdate(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
99
+ winrt::Microsoft::ReactNative::ComponentViewUpdateMask /*mask*/) noexcept {
100
+ }
101
+
102
+ ::_COMPONENT_VIEW_COMMAND_HANDLERS_::
103
+
104
+ ::_COMPONENT_VIEW_COMMAND_HANDLER_::
105
+
106
+ const std::shared_ptr<::_COMPONENT_NAME_::EventEmitter>& EventEmitter() const { return m_eventEmitter; }
107
+ const winrt::com_ptr<::_COMPONENT_NAME_::Props>& Props() const { return m_props; }
108
+
109
+ private:
110
+ winrt::com_ptr<::_COMPONENT_NAME_::Props> m_props;
111
+ std::shared_ptr<::_COMPONENT_NAME_::EventEmitter> m_eventEmitter;
112
+ };
113
+ `;
114
+ const registerTemplate = `
115
+ template <typename TUserData>
116
+ void Register::_COMPONENT_NAME_::NativeComponent(
117
+ winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder,
118
+ std::function<void(const winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder&)> builderCallback) noexcept {
119
+ packageBuilder.as<winrt::Microsoft::ReactNative::IReactPackageBuilderFabric>().AddViewComponent(
120
+ L"::_COMPONENT_NAME_::", [builderCallback](winrt::Microsoft::ReactNative::IReactViewComponentBuilder const &builder) noexcept {
121
+ auto compBuilder = builder.as<winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder>();
122
+
123
+ builder.SetCreateProps(
124
+ [](winrt::Microsoft::ReactNative::ViewProps props) noexcept { return winrt::make<::_COMPONENT_NAME_::Props>(props); });
125
+
126
+ builder.SetUpdatePropsHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
127
+ const winrt::Microsoft::ReactNative::IComponentProps &newProps,
128
+ const winrt::Microsoft::ReactNative::IComponentProps &oldProps) noexcept {
129
+ auto userData = view.UserData().as<TUserData>();
130
+ userData->UpdateProps(view, newProps ? newProps.as<::_COMPONENT_NAME_::Props>() : nullptr, oldProps ? oldProps.as<::_COMPONENT_NAME_::Props>() : nullptr);
131
+ });
132
+
133
+ builder.SetUpdateEventEmitterHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
134
+ const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter) noexcept {
135
+ auto userData = view.UserData().as<TUserData>();
136
+ userData->UpdateEventEmitter(std::make_shared<::_COMPONENT_NAME_::EventEmitter>(eventEmitter));
137
+ });
138
+
139
+ if constexpr (&TUserData::FinalizeUpdate != &Base::_COMPONENT_NAME_::<TUserData>::FinalizeUpdate) {
140
+ builder.SetFinalizeUpdateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
141
+ winrt::Microsoft::ReactNative::ComponentViewUpdateMask mask) noexcept {
142
+ auto userData = view.UserData().as<TUserData>();
143
+ userData->FinalizeUpdate(view, mask);
144
+ });
145
+ }
146
+
147
+ if constexpr (&TUserData::UpdateState != &Base::_COMPONENT_NAME_::<TUserData>::UpdateState) {
148
+ builder.SetUpdateStateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
149
+ const winrt::Microsoft::ReactNative::IComponentState &newState) noexcept {
150
+ auto userData = view.UserData().as<TUserData>();
151
+ userData->member(view, newState);
152
+ });
153
+ }
154
+
155
+ ::_REGISTER_CUSTOM_COMMAND_HANDLER_::
156
+
157
+ if constexpr (&TUserData::MountChildComponentView != &Base::_COMPONENT_NAME_::<TUserData>::MountChildComponentView) {
158
+ builder.SetMountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
159
+ const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &args) noexcept {
160
+ auto userData = view.UserData().as<TUserData>();
161
+ return userData->MountChildComponentView(view, args);
162
+ });
163
+ }
164
+
165
+ if constexpr (&TUserData::UnmountChildComponentView != &Base::_COMPONENT_NAME_::<TUserData>::UnmountChildComponentView) {
166
+ builder.SetUnmountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
167
+ const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &args) noexcept {
168
+ auto userData = view.UserData().as<TUserData>();
169
+ return userData->UnmountChildComponentView(view, args);
170
+ });
171
+ }
172
+
173
+ compBuilder.SetViewComponentViewInitializer([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
174
+ auto userData = winrt::make_self<TUserData>();
175
+ if constexpr (&TUserData::Initialize != &Base::_COMPONENT_NAME_::<TUserData>::Initialize) {
176
+ userData->Initialize(view);
177
+ }
178
+ view.UserData(*userData);
179
+ });
180
+
181
+ if constexpr (&TUserData::CreateVisual != &Base::_COMPONENT_NAME_::<TUserData>::CreateVisual) {
182
+ compBuilder.SetCreateVisualHandler([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
183
+ auto userData = view.UserData().as<TUserData>();
184
+ return userData->CreateVisual(view);
185
+ });
186
+ }
187
+
188
+ // Allow app to further customize the builder
189
+ if (builderCallback) {
190
+ builderCallback(compBuilder);
191
+ }
192
+ });
193
+ }
194
+ `;
195
+ const fileTemplate = `
196
+ ${headerTemplate}
197
+
198
+ namespace ::_NAMESPACE_:: {
199
+
200
+ ::_COMPONENT_PROP_OBJECT_TYPES_::
201
+ ::_COMPONENT_PROP_TYPES_::
202
+
203
+ ::_COMPONENT_EVENT_EMITTER_::
204
+
205
+ ::_BASE_COMPONENT_STRUCT_::
206
+
207
+ ::_COMPONENT_REGISTRATION_::
208
+ } // namespace ::_NAMESPACE_::
209
+ `;
210
+ function capitalizeFirstLetter(s) {
211
+ return s.charAt(0).toUpperCase() + s.slice(1);
212
+ }
213
+ function createComponentGenerator({ namespace, cppStringType, }) {
214
+ return (_libraryName, schema, _moduleSpecName) => {
215
+ const files = new Map();
216
+ const cppCodegenOptions = { cppStringType };
217
+ for (const componentName of Object.keys(schema.modules)) {
218
+ const component = schema.modules[componentName];
219
+ (0, AliasManaging_1.setPreferredModuleName)(componentName);
220
+ if (component.type === 'Component') {
221
+ console.log(`Generating ${componentName}.g.h`);
222
+ const componentShape = component.components[componentName];
223
+ componentShape.extendsProps.forEach(propsBaseType => {
224
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
225
+ if (propsBaseType.type !== 'ReactNativeBuiltInType' || propsBaseType.knownTypeName !== 'ReactNativeCoreViewProps') {
226
+ throw new Error('Currently only supports props extending from ViewProps');
227
+ }
228
+ });
229
+ // Props
230
+ const propObjectAliases = { types: {}, jobs: [] };
231
+ const propsName = `${componentName}Props`;
232
+ const propsFields = componentShape.props.map(prop => {
233
+ const propType = (0, PropObjectTypes_1.translateComponentPropsFieldType)(prop.typeAnnotation, propObjectAliases, `${propsName}_${prop.name}`, cppCodegenOptions);
234
+ return ` REACT_FIELD(${prop.name})\n ${(prop.optional && !propType.alreadySupportsOptionalOrHasDefault) ? `std::optional<${propType.type}>` : propType.type} ${prop.name}${propType.initializer};\n`;
235
+ }).join('\n');
236
+ const propObjectTypes = propObjectAliases.jobs.map(propObjectTypeName => {
237
+ const propObjectType = propObjectAliases.types[propObjectTypeName];
238
+ const propsObjectFields = propObjectType.properties.map(property => {
239
+ const propType = (0, PropObjectTypes_1.translateComponentPropsFieldType)(property.typeAnnotation, propObjectAliases, `${propsName}_${property.name}`, cppCodegenOptions);
240
+ return ` REACT_FIELD(${property.name})\n ${(property.optional && !propType.alreadySupportsOptionalOrHasDefault) ? `std::optional<${propType.type}>` : propType.type} ${property.name}${propType.initializer};\n`;
241
+ }).join('\n');
242
+ return propsObjectTemplate.replace(/::_OBJECT_NAME_::/g, (0, AliasManaging_1.getAliasCppName)(propObjectTypeName)).replace(/::_OBJECT_FIELDS_::/g, propsObjectFields);
243
+ }).join('\n');
244
+ // Events
245
+ const eventObjectAliases = { types: {}, jobs: [] };
246
+ const eventEmitterName = `${componentName}EventEmitter`;
247
+ const eventEmitterMethods = componentShape.events.filter(event => event.typeAnnotation.argument).map(event => {
248
+ var _a;
249
+ if ((_a = event.typeAnnotation.argument) === null || _a === void 0 ? void 0 : _a.baseTypes) {
250
+ throw new Error('Events with base type arguments not currently supported');
251
+ }
252
+ // Called to collect the eventObjectAliases
253
+ (0, PropObjectTypes_1.translateComponentEventType)(event.typeAnnotation.argument, eventObjectAliases, `${event.name}`, cppCodegenOptions);
254
+ // onSomething -> something
255
+ let eventNameLower = event.name.replace('on', '');
256
+ eventNameLower = eventNameLower[0].toLowerCase() + eventNameLower.slice(1);
257
+ return eventEmitterMethodTemplate
258
+ .replace(/::_EVENT_NAME_::/g, event.name)
259
+ .replace(/::_EVENT_NAME_NO_ON_::/g, eventNameLower)
260
+ .replace(/::_EVENT_OBJECT_TYPE_::/g, event.name.replace('on', 'On'));
261
+ }).join('\n\n');
262
+ const eventObjects = eventObjectAliases.jobs.map(eventObjectTypeName => {
263
+ const eventObjectType = eventObjectAliases.types[eventObjectTypeName];
264
+ const eventObjectFields = eventObjectType.properties.map(property => {
265
+ const eventPropType = (0, PropObjectTypes_1.translateComponentEventType)(property.typeAnnotation, eventObjectAliases, eventObjectTypeName, cppCodegenOptions);
266
+ return ` REACT_FIELD(${property.name})\n ${(property.optional && !eventPropType.alreadySupportsOptionalOrHasDefault) ? `std::optional<${eventPropType.type}>` : eventPropType.type} ${property.name}${eventPropType.initializer};\n`;
267
+ }).join('\n');
268
+ return eventsObjectTemplate.replace(/::_OBJECT_NAME_::/g, `${componentName}_${eventObjectTypeName.replace('on', 'On')}`).replace(/::_OBJECT_FIELDS_::/g, eventObjectFields);
269
+ }).join('\n');
270
+ const eventObjectUsings = eventObjectAliases.jobs.map(eventObjectTypeName => {
271
+ return ` using ${eventObjectTypeName.replace('on', 'On')} = ${componentName}_${eventObjectTypeName.replace('on', 'On')};`;
272
+ }).join('\n');
273
+ const eventEmitter = eventEmitterTemplate
274
+ .replace(/::_COMPONENT_EVENT_OBJECT_TYPES_::/g, eventObjects)
275
+ .replace(/::_EVENT_EMITTER_METHODS_::/g, eventEmitterMethods)
276
+ .replace(/::_EVENT_EMITTER_USINGS_::/g, eventObjectUsings);
277
+ // Commands
278
+ const commandAliases = { types: {}, jobs: [] };
279
+ const hasAnyCommands = (componentShape.commands.length !== 0);
280
+ const commandHandlers = hasAnyCommands ? componentShape.commands.map(command => {
281
+ const commandArgs = command.typeAnnotation.params.map(param => {
282
+ const commandArgType = (0, PropObjectTypes_1.translateCommandParamType)(param.typeAnnotation, commandAliases, `${componentName}_${command.name}`, cppCodegenOptions);
283
+ return `${(param.optional && !commandArgType.alreadySupportsOptionalOrHasDefault) ? `std::optional<${commandArgType.type}>` : commandArgType.type} ${param.name}`;
284
+ }).join(', ');
285
+ return ` // You must provide an implementation of this method to handle the "${command.name}" command
286
+ virtual void Handle${capitalizeFirstLetter(command.name)}Command(${commandArgs}) noexcept = 0;`;
287
+ }).join('\n\n') : '';
288
+ const commandHandler = hasAnyCommands ? `void HandleCommand(const winrt::Microsoft::ReactNative::ComponentView &view, const winrt::Microsoft::ReactNative::HandleCommandArgs& args) noexcept {
289
+ auto userData = view.UserData().as<TUserData>();
290
+ auto commandName = args.CommandName();
291
+ ${componentShape.commands.map(command => {
292
+ const commaSeparatedCommandArgs = command.typeAnnotation.params.map(param => param.name).join(', ');
293
+ return ` if (commandName == L"${command.name}") {
294
+ ${command.typeAnnotation.params.length !== 0 ? ` ${command.typeAnnotation.params.map(param => {
295
+ const commandArgType = (0, PropObjectTypes_1.translateCommandParamType)(param.typeAnnotation, commandAliases, `${componentName}_${command.name}`, cppCodegenOptions);
296
+ return `${(param.optional && !commandArgType.alreadySupportsOptionalOrHasDefault) ? `std::optional<${commandArgType.type}>` : commandArgType.type} ${param.name};`;
297
+ }).join('\n')}
298
+ winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), ${commaSeparatedCommandArgs});` : ''}
299
+ userData->Handle${capitalizeFirstLetter(command.name)}Command(${commaSeparatedCommandArgs});
300
+ return;
301
+ }`;
302
+ }).join('\n\n')}
303
+ }` : '';
304
+ const registerCommandHandler = hasAnyCommands ? ` builder.SetCustomCommandHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
305
+ const winrt::Microsoft::ReactNative::HandleCommandArgs& args) noexcept {
306
+ auto userData = view.UserData().as<TUserData>();
307
+ userData->HandleCommand(view, args);
308
+ });` : '';
309
+ const baseType = baseStructTemplate
310
+ .replace(/::_COMPONENT_VIEW_COMMAND_HANDLERS_::/g, commandHandlers)
311
+ .replace(/::_COMPONENT_VIEW_COMMAND_HANDLER_::/g, commandHandler);
312
+ // Registration
313
+ const componentRegistration = registerTemplate.replace(/::_REGISTER_CUSTOM_COMMAND_HANDLER_::/g, registerCommandHandler);
314
+ // Final output
315
+ const replaceContent = function (template) {
316
+ return template
317
+ .replace(/::_COMPONENT_PROP_OBJECT_TYPES_::/g, propObjectTypes)
318
+ .replace(/::_COMPONENT_PROP_TYPES_::/g, propsTemplate)
319
+ .replace(/::_COMPONENT_EVENT_EMITTER_::/g, eventEmitter)
320
+ .replace(/::_BASE_COMPONENT_STRUCT_::/g, baseType)
321
+ .replace(/::_COMPONENT_REGISTRATION_::/g, componentRegistration)
322
+ .replace(/::_EVENT_EMITTER_NAME_::/g, eventEmitterName)
323
+ .replace(/::_PROPS_NAME_::/g, propsName)
324
+ .replace(/::_COMPONENT_NAME_::/g, componentName)
325
+ .replace(/::_PROPS_FIELDS_::/g, propsFields)
326
+ .replace(/::_NAMESPACE_::/g, namespace)
327
+ .replace(/\n\n\n+/g, '\n\n');
328
+ };
329
+ files.set(`${componentName}.g.h`, replaceContent(fileTemplate));
330
+ }
331
+ }
332
+ return files;
333
+ };
334
+ }
335
+ exports.createComponentGenerator = createComponentGenerator;
336
+ //# sourceMappingURL=GenerateComponentWindows.js.map