@react-native-windows/codegen 0.0.0-canary.11 → 0.0.0-canary.110

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 (61) hide show
  1. package/CHANGELOG.md +950 -4
  2. package/README.md +1 -1
  3. package/bin.js +0 -0
  4. package/lib-commonjs/Cli.d.ts +7 -0
  5. package/lib-commonjs/Cli.js +103 -0
  6. package/lib-commonjs/Cli.js.map +1 -0
  7. package/lib-commonjs/generators/AliasGen.d.ts +12 -0
  8. package/lib-commonjs/generators/AliasGen.js +115 -0
  9. package/lib-commonjs/generators/AliasGen.js.map +1 -0
  10. package/lib-commonjs/generators/AliasManaging.d.ts +15 -0
  11. package/lib-commonjs/generators/AliasManaging.js +49 -0
  12. package/lib-commonjs/generators/AliasManaging.js.map +1 -0
  13. package/lib-commonjs/generators/GenerateComponentWindows.d.ts +13 -0
  14. package/lib-commonjs/generators/GenerateComponentWindows.js +406 -0
  15. package/lib-commonjs/generators/GenerateComponentWindows.js.map +1 -0
  16. package/lib-commonjs/generators/GenerateNM2.d.ts +15 -0
  17. package/lib-commonjs/generators/GenerateNM2.js +144 -0
  18. package/lib-commonjs/generators/GenerateNM2.js.map +1 -0
  19. package/lib-commonjs/generators/GenerateTypeScript.d.ts +11 -0
  20. package/lib-commonjs/generators/GenerateTypeScript.js +166 -0
  21. package/lib-commonjs/generators/GenerateTypeScript.js.map +1 -0
  22. package/lib-commonjs/generators/ObjectTypes.d.ts +13 -0
  23. package/lib-commonjs/generators/ObjectTypes.js +78 -0
  24. package/lib-commonjs/generators/ObjectTypes.js.map +1 -0
  25. package/lib-commonjs/generators/ParamTypes.d.ts +13 -0
  26. package/lib-commonjs/generators/ParamTypes.js +181 -0
  27. package/lib-commonjs/generators/ParamTypes.js.map +1 -0
  28. package/lib-commonjs/generators/PropObjectTypes.d.ts +18 -0
  29. package/lib-commonjs/generators/PropObjectTypes.js +217 -0
  30. package/lib-commonjs/generators/PropObjectTypes.js.map +1 -0
  31. package/lib-commonjs/generators/ReturnTypes.d.ts +10 -0
  32. package/lib-commonjs/generators/ReturnTypes.js +29 -0
  33. package/lib-commonjs/generators/ReturnTypes.js.map +1 -0
  34. package/lib-commonjs/generators/ValidateConstants.d.ts +8 -0
  35. package/lib-commonjs/generators/ValidateConstants.js +38 -0
  36. package/lib-commonjs/generators/ValidateConstants.js.map +1 -0
  37. package/lib-commonjs/generators/ValidateMethods.d.ts +14 -0
  38. package/lib-commonjs/generators/ValidateMethods.js +112 -0
  39. package/lib-commonjs/generators/ValidateMethods.js.map +1 -0
  40. package/lib-commonjs/index.d.ts +39 -0
  41. package/lib-commonjs/index.js +227 -0
  42. package/lib-commonjs/index.js.map +1 -0
  43. package/package.json +41 -21
  44. package/src/Cli.ts +69 -232
  45. package/src/generators/AliasGen.ts +195 -0
  46. package/src/generators/AliasManaging.ts +75 -0
  47. package/src/generators/GenerateComponentWindows.ts +540 -0
  48. package/src/generators/GenerateNM2.ts +128 -132
  49. package/src/generators/GenerateTypeScript.ts +250 -0
  50. package/src/generators/ObjectTypes.ts +88 -37
  51. package/src/generators/ParamTypes.ts +324 -44
  52. package/src/generators/PropObjectTypes.ts +233 -0
  53. package/src/generators/ReturnTypes.ts +38 -41
  54. package/src/generators/ValidateConstants.ts +50 -0
  55. package/src/generators/ValidateMethods.ts +270 -0
  56. package/src/index.ts +415 -0
  57. package/.eslintrc.js +0 -4
  58. package/.vscode/launch.json +0 -23
  59. package/CHANGELOG.json +0 -658
  60. package/jest.config.js +0 -1
  61. package/tsconfig.json +0 -5
@@ -0,0 +1,406 @@
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, const winrt::Microsoft::ReactNative::IComponentProps& cloneFrom)
23
+ : ViewProps(props)
24
+ {
25
+ if (cloneFrom) {
26
+ auto cloneFromProps = cloneFrom.as<::_PROPS_NAME_::>();
27
+ ::_PROP_INITIALIZERS_::
28
+ }
29
+ }
30
+
31
+ void SetProp(uint32_t hash, winrt::hstring propName, winrt::Microsoft::ReactNative::IJSValueReader value) noexcept {
32
+ winrt::Microsoft::ReactNative::ReadProp(hash, propName, value, *this);
33
+ }
34
+
35
+ ::_PROPS_FIELDS_::
36
+ const winrt::Microsoft::ReactNative::ViewProps ViewProps;
37
+ };`;
38
+ const propsObjectTemplate = `REACT_STRUCT(::_OBJECT_NAME_::)
39
+ struct ::_OBJECT_NAME_:: {
40
+ ::_OBJECT_FIELDS_::};
41
+ `;
42
+ const eventsObjectTemplate = `REACT_STRUCT(::_OBJECT_NAME_::)
43
+ struct ::_OBJECT_NAME_:: {
44
+ ::_OBJECT_FIELDS_::};
45
+ `;
46
+ const eventEmitterMethodTemplate = ` void ::_EVENT_NAME_::(::_EVENT_OBJECT_TYPE_:: &value) const {
47
+ m_eventEmitter.DispatchEvent(L"::_EVENT_NAME_NO_ON_::", [value](const winrt::Microsoft::ReactNative::IJSValueWriter writer) {
48
+ winrt::Microsoft::ReactNative::WriteValue(writer, value);
49
+ });
50
+ }`;
51
+ const eventEmitterTemplate = `::_COMPONENT_EVENT_OBJECT_TYPES_::
52
+
53
+ struct ::_EVENT_EMITTER_NAME_:: {
54
+ ::_EVENT_EMITTER_NAME_::(const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter)
55
+ : m_eventEmitter(eventEmitter) {}
56
+
57
+ ::_EVENT_EMITTER_USINGS_::
58
+
59
+ ::_EVENT_EMITTER_METHODS_::
60
+
61
+ private:
62
+ winrt::Microsoft::ReactNative::EventEmitter m_eventEmitter{nullptr};
63
+ };`;
64
+ const baseStructTemplate = `
65
+ template<typename TUserData>
66
+ struct Base::_COMPONENT_NAME_:: {
67
+
68
+ virtual void UpdateProps(
69
+ const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
70
+ const winrt::com_ptr<::_COMPONENT_NAME_::Props> &newProps,
71
+ const winrt::com_ptr<::_COMPONENT_NAME_::Props> &/*oldProps*/) noexcept {
72
+ m_props = newProps;
73
+ }
74
+
75
+ // UpdateState will only be called if this method is overridden
76
+ virtual void UpdateState(
77
+ const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
78
+ const winrt::Microsoft::ReactNative::IComponentState &/*newState*/) noexcept {
79
+ }
80
+
81
+ virtual void UpdateEventEmitter(const std::shared_ptr<::_COMPONENT_NAME_::EventEmitter> &eventEmitter) noexcept {
82
+ m_eventEmitter = eventEmitter;
83
+ }
84
+
85
+ // MountChildComponentView will only be called if this method is overridden
86
+ virtual void MountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
87
+ const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &/*args*/) noexcept {
88
+ }
89
+
90
+ // UnmountChildComponentView will only be called if this method is overridden
91
+ virtual void UnmountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
92
+ const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &/*args*/) noexcept {
93
+ }
94
+
95
+ // Initialize will only be called if this method is overridden
96
+ virtual void Initialize(const winrt::Microsoft::ReactNative::ComponentView &/*view*/) noexcept {
97
+ }
98
+
99
+ // CreateVisual will only be called if this method is overridden
100
+ virtual winrt::Microsoft::UI::Composition::Visual CreateVisual(const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
101
+ return view.as<winrt::Microsoft::ReactNative::Composition::ComponentView>().Compositor().CreateSpriteVisual();
102
+ }
103
+
104
+ // FinalizeUpdate will only be called if this method is overridden
105
+ virtual void FinalizeUpdate(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,
106
+ winrt::Microsoft::ReactNative::ComponentViewUpdateMask /*mask*/) noexcept {
107
+ }
108
+
109
+ ::_COMPONENT_VIEW_COMMAND_HANDLERS_::
110
+
111
+ ::_COMPONENT_VIEW_COMMAND_HANDLER_::
112
+
113
+ const std::shared_ptr<::_COMPONENT_NAME_::EventEmitter>& EventEmitter() const { return m_eventEmitter; }
114
+ const winrt::com_ptr<::_COMPONENT_NAME_::Props>& Props() const { return m_props; }
115
+
116
+ private:
117
+ winrt::com_ptr<::_COMPONENT_NAME_::Props> m_props;
118
+ std::shared_ptr<::_COMPONENT_NAME_::EventEmitter> m_eventEmitter;
119
+ };
120
+ `;
121
+ const registerTemplate = `
122
+ template <typename TUserData>
123
+ void Register::_COMPONENT_NAME_::NativeComponent(
124
+ winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder,
125
+ std::function<void(const winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder&)> builderCallback) noexcept {
126
+ packageBuilder.as<winrt::Microsoft::ReactNative::IReactPackageBuilderFabric>().AddViewComponent(
127
+ L"::_COMPONENT_NAME_::", [builderCallback](winrt::Microsoft::ReactNative::IReactViewComponentBuilder const &builder) noexcept {
128
+ auto compBuilder = builder.as<winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder>();
129
+
130
+ builder.SetCreateProps([](winrt::Microsoft::ReactNative::ViewProps props,
131
+ const winrt::Microsoft::ReactNative::IComponentProps& cloneFrom) noexcept {
132
+ return winrt::make<::_COMPONENT_NAME_::Props>(props, cloneFrom);
133
+ });
134
+
135
+ builder.SetUpdatePropsHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
136
+ const winrt::Microsoft::ReactNative::IComponentProps &newProps,
137
+ const winrt::Microsoft::ReactNative::IComponentProps &oldProps) noexcept {
138
+ auto userData = view.UserData().as<TUserData>();
139
+ userData->UpdateProps(view, newProps ? newProps.as<::_COMPONENT_NAME_::Props>() : nullptr, oldProps ? oldProps.as<::_COMPONENT_NAME_::Props>() : nullptr);
140
+ });
141
+
142
+ builder.SetUpdateEventEmitterHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
143
+ const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter) noexcept {
144
+ auto userData = view.UserData().as<TUserData>();
145
+ userData->UpdateEventEmitter(std::make_shared<::_COMPONENT_NAME_::EventEmitter>(eventEmitter));
146
+ });
147
+
148
+ if constexpr (&TUserData::FinalizeUpdate != &Base::_COMPONENT_NAME_::<TUserData>::FinalizeUpdate) {
149
+ builder.SetFinalizeUpdateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
150
+ winrt::Microsoft::ReactNative::ComponentViewUpdateMask mask) noexcept {
151
+ auto userData = view.UserData().as<TUserData>();
152
+ userData->FinalizeUpdate(view, mask);
153
+ });
154
+ }
155
+
156
+ if constexpr (&TUserData::UpdateState != &Base::_COMPONENT_NAME_::<TUserData>::UpdateState) {
157
+ builder.SetUpdateStateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
158
+ const winrt::Microsoft::ReactNative::IComponentState &newState) noexcept {
159
+ auto userData = view.UserData().as<TUserData>();
160
+ userData->member(view, newState);
161
+ });
162
+ }
163
+
164
+ ::_REGISTER_CUSTOM_COMMAND_HANDLER_::
165
+
166
+ if constexpr (&TUserData::MountChildComponentView != &Base::_COMPONENT_NAME_::<TUserData>::MountChildComponentView) {
167
+ builder.SetMountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
168
+ const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &args) noexcept {
169
+ auto userData = view.UserData().as<TUserData>();
170
+ return userData->MountChildComponentView(view, args);
171
+ });
172
+ }
173
+
174
+ if constexpr (&TUserData::UnmountChildComponentView != &Base::_COMPONENT_NAME_::<TUserData>::UnmountChildComponentView) {
175
+ builder.SetUnmountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
176
+ const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &args) noexcept {
177
+ auto userData = view.UserData().as<TUserData>();
178
+ return userData->UnmountChildComponentView(view, args);
179
+ });
180
+ }
181
+
182
+ compBuilder.SetViewComponentViewInitializer([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
183
+ auto userData = winrt::make_self<TUserData>();
184
+ if constexpr (&TUserData::Initialize != &Base::_COMPONENT_NAME_::<TUserData>::Initialize) {
185
+ userData->Initialize(view);
186
+ }
187
+ view.UserData(*userData);
188
+ });
189
+
190
+ if constexpr (&TUserData::CreateVisual != &Base::_COMPONENT_NAME_::<TUserData>::CreateVisual) {
191
+ compBuilder.SetCreateVisualHandler([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {
192
+ auto userData = view.UserData().as<TUserData>();
193
+ return userData->CreateVisual(view);
194
+ });
195
+ }
196
+
197
+ // Allow app to further customize the builder
198
+ if (builderCallback) {
199
+ builderCallback(compBuilder);
200
+ }
201
+ });
202
+ }
203
+ `;
204
+ const fileTemplate = `
205
+ ${headerTemplate}
206
+
207
+ namespace ::_NAMESPACE_:: {
208
+
209
+ ::_COMPONENT_PROP_OBJECT_TYPES_::
210
+ ::_COMPONENT_PROP_TYPES_::
211
+
212
+ ::_COMPONENT_EVENT_EMITTER_::
213
+
214
+ ::_BASE_COMPONENT_STRUCT_::
215
+
216
+ ::_COMPONENT_REGISTRATION_::
217
+ } // namespace ::_NAMESPACE_::
218
+ `;
219
+ function capitalizeFirstLetter(s) {
220
+ return s.charAt(0).toUpperCase() + s.slice(1);
221
+ }
222
+ function createComponentGenerator({ namespace, cppStringType, }) {
223
+ return (_libraryName, schema, _moduleSpecName) => {
224
+ const files = new Map();
225
+ const cppCodegenOptions = { cppStringType };
226
+ for (const componentName of Object.keys(schema.modules)) {
227
+ const component = schema.modules[componentName];
228
+ (0, AliasManaging_1.setPreferredModuleName)(componentName);
229
+ if (component.type === 'Component') {
230
+ console.log(`Generating ${componentName}.g.h`);
231
+ const componentShape = component.components[componentName];
232
+ componentShape.extendsProps.forEach(propsBaseType => {
233
+ if (
234
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
235
+ propsBaseType.type !== 'ReactNativeBuiltInType' ||
236
+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
237
+ propsBaseType.knownTypeName !== 'ReactNativeCoreViewProps') {
238
+ throw new Error('Currently only supports props extending from ViewProps');
239
+ }
240
+ });
241
+ // Props
242
+ const propObjectAliases = { types: {}, jobs: [] };
243
+ const propsName = `${componentName}Props`;
244
+ const propsFields = componentShape.props
245
+ .map(prop => {
246
+ const propType = (0, PropObjectTypes_1.translateComponentPropsFieldType)(prop.typeAnnotation, propObjectAliases, `${propsName}_${prop.name}`, cppCodegenOptions);
247
+ return ` REACT_FIELD(${prop.name})\n ${prop.optional && !propType.alreadySupportsOptionalOrHasDefault
248
+ ? `std::optional<${propType.type}>`
249
+ : propType.type} ${prop.name}${propType.initializer};\n`;
250
+ })
251
+ .join('\n');
252
+ const propInitializers = componentShape.props
253
+ .map(prop => {
254
+ return ` ${prop.name} = cloneFromProps->${prop.name};`;
255
+ })
256
+ .join('\n');
257
+ const propObjectTypes = propObjectAliases.jobs
258
+ .map(propObjectTypeName => {
259
+ const propObjectType = propObjectAliases.types[propObjectTypeName];
260
+ const propsObjectFields = propObjectType.properties
261
+ .map(property => {
262
+ const propType = (0, PropObjectTypes_1.translateComponentPropsFieldType)(property.typeAnnotation, propObjectAliases, `${propsName}_${property.name}`, cppCodegenOptions);
263
+ return ` REACT_FIELD(${property.name})\n ${property.optional &&
264
+ !propType.alreadySupportsOptionalOrHasDefault
265
+ ? `std::optional<${propType.type}>`
266
+ : propType.type} ${property.name}${propType.initializer};\n`;
267
+ })
268
+ .join('\n');
269
+ return propsObjectTemplate
270
+ .replace(/::_OBJECT_NAME_::/g, (0, AliasManaging_1.getAliasCppName)(propObjectTypeName))
271
+ .replace(/::_OBJECT_FIELDS_::/g, propsObjectFields);
272
+ })
273
+ .join('\n');
274
+ // Events
275
+ const eventObjectAliases = { types: {}, jobs: [] };
276
+ const eventEmitterName = `${componentName}EventEmitter`;
277
+ const eventEmitterMethods = componentShape.events
278
+ .filter(event => event.typeAnnotation.argument)
279
+ .map(event => {
280
+ var _a;
281
+ if ((_a = event.typeAnnotation.argument) === null || _a === void 0 ? void 0 : _a.baseTypes) {
282
+ throw new Error('Events with base type arguments not currently supported');
283
+ }
284
+ // Called to collect the eventObjectAliases
285
+ (0, PropObjectTypes_1.translateComponentEventType)(event.typeAnnotation.argument, eventObjectAliases, `${event.name}`, cppCodegenOptions);
286
+ // onSomething -> something
287
+ let eventNameLower = event.name.replace('on', '');
288
+ eventNameLower =
289
+ eventNameLower[0].toLowerCase() + eventNameLower.slice(1);
290
+ return eventEmitterMethodTemplate
291
+ .replace(/::_EVENT_NAME_::/g, event.name)
292
+ .replace(/::_EVENT_NAME_NO_ON_::/g, eventNameLower)
293
+ .replace(/::_EVENT_OBJECT_TYPE_::/g, event.name.replace('on', 'On'));
294
+ })
295
+ .join('\n\n');
296
+ const eventObjects = eventObjectAliases.jobs
297
+ .map(eventObjectTypeName => {
298
+ const eventObjectType = eventObjectAliases.types[eventObjectTypeName];
299
+ const eventObjectFields = eventObjectType.properties
300
+ .map(property => {
301
+ const eventPropType = (0, PropObjectTypes_1.translateComponentEventType)(property.typeAnnotation, eventObjectAliases, eventObjectTypeName, cppCodegenOptions);
302
+ return ` REACT_FIELD(${property.name})\n ${property.optional &&
303
+ !eventPropType.alreadySupportsOptionalOrHasDefault
304
+ ? `std::optional<${eventPropType.type}>`
305
+ : eventPropType.type} ${property.name}${eventPropType.initializer};\n`;
306
+ })
307
+ .join('\n');
308
+ return eventsObjectTemplate
309
+ .replace(/::_OBJECT_NAME_::/g, `${componentName}_${eventObjectTypeName.replace('on', 'On')}`)
310
+ .replace(/::_OBJECT_FIELDS_::/g, eventObjectFields);
311
+ })
312
+ .join('\n');
313
+ const eventObjectUsings = eventObjectAliases.jobs
314
+ .map(eventObjectTypeName => {
315
+ return ` using ${eventObjectTypeName.replace('on', 'On')} = ${componentName}_${eventObjectTypeName.replace('on', 'On')};`;
316
+ })
317
+ .join('\n');
318
+ const eventEmitter = eventEmitterTemplate
319
+ .replace(/::_COMPONENT_EVENT_OBJECT_TYPES_::/g, eventObjects)
320
+ .replace(/::_EVENT_EMITTER_METHODS_::/g, eventEmitterMethods)
321
+ .replace(/::_EVENT_EMITTER_USINGS_::/g, eventObjectUsings);
322
+ // Commands
323
+ const commandAliases = { types: {}, jobs: [] };
324
+ const hasAnyCommands = componentShape.commands.length !== 0;
325
+ const commandHandlers = hasAnyCommands
326
+ ? componentShape.commands
327
+ .map(command => {
328
+ const commandArgs = command.typeAnnotation.params
329
+ .map(param => {
330
+ const commandArgType = (0, PropObjectTypes_1.translateCommandParamType)(param.typeAnnotation, commandAliases, `${componentName}_${command.name}`, cppCodegenOptions);
331
+ return `${param.optional &&
332
+ !commandArgType.alreadySupportsOptionalOrHasDefault
333
+ ? `std::optional<${commandArgType.type}>`
334
+ : commandArgType.type} ${param.name}`;
335
+ })
336
+ .join(', ');
337
+ return ` // You must provide an implementation of this method to handle the "${command.name}" command
338
+ virtual void Handle${capitalizeFirstLetter(command.name)}Command(${commandArgs}) noexcept = 0;`;
339
+ })
340
+ .join('\n\n')
341
+ : '';
342
+ const commandHandler = hasAnyCommands
343
+ ? `void HandleCommand(const winrt::Microsoft::ReactNative::ComponentView &view, const winrt::Microsoft::ReactNative::HandleCommandArgs& args) noexcept {
344
+ auto userData = view.UserData().as<TUserData>();
345
+ auto commandName = args.CommandName();
346
+ ${componentShape.commands
347
+ .map(command => {
348
+ const commaSeparatedCommandArgs = command.typeAnnotation.params
349
+ .map(param => param.name)
350
+ .join(', ');
351
+ return ` if (commandName == L"${command.name}") {
352
+ ${command.typeAnnotation.params.length !== 0
353
+ ? ` ${command.typeAnnotation.params
354
+ .map(param => {
355
+ const commandArgType = (0, PropObjectTypes_1.translateCommandParamType)(param.typeAnnotation, commandAliases, `${componentName}_${command.name}`, cppCodegenOptions);
356
+ return `${param.optional &&
357
+ !commandArgType.alreadySupportsOptionalOrHasDefault
358
+ ? `std::optional<${commandArgType.type}>`
359
+ : commandArgType.type} ${param.name};`;
360
+ })
361
+ .join('\n')}
362
+ winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), ${commaSeparatedCommandArgs});`
363
+ : ''}
364
+ userData->Handle${capitalizeFirstLetter(command.name)}Command(${commaSeparatedCommandArgs});
365
+ return;
366
+ }`;
367
+ })
368
+ .join('\n\n')}
369
+ }`
370
+ : '';
371
+ const registerCommandHandler = hasAnyCommands
372
+ ? ` builder.SetCustomCommandHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,
373
+ const winrt::Microsoft::ReactNative::HandleCommandArgs& args) noexcept {
374
+ auto userData = view.UserData().as<TUserData>();
375
+ userData->HandleCommand(view, args);
376
+ });`
377
+ : '';
378
+ const baseType = baseStructTemplate
379
+ .replace(/::_COMPONENT_VIEW_COMMAND_HANDLERS_::/g, commandHandlers)
380
+ .replace(/::_COMPONENT_VIEW_COMMAND_HANDLER_::/g, commandHandler);
381
+ // Registration
382
+ const componentRegistration = registerTemplate.replace(/::_REGISTER_CUSTOM_COMMAND_HANDLER_::/g, registerCommandHandler);
383
+ // Final output
384
+ const replaceContent = function (template) {
385
+ return template
386
+ .replace(/::_COMPONENT_PROP_OBJECT_TYPES_::/g, propObjectTypes)
387
+ .replace(/::_COMPONENT_PROP_TYPES_::/g, propsTemplate)
388
+ .replace(/::_COMPONENT_EVENT_EMITTER_::/g, eventEmitter)
389
+ .replace(/::_BASE_COMPONENT_STRUCT_::/g, baseType)
390
+ .replace(/::_COMPONENT_REGISTRATION_::/g, componentRegistration)
391
+ .replace(/::_EVENT_EMITTER_NAME_::/g, eventEmitterName)
392
+ .replace(/::_PROPS_NAME_::/g, propsName)
393
+ .replace(/::_COMPONENT_NAME_::/g, componentName)
394
+ .replace(/::_PROP_INITIALIZERS_::/g, propInitializers)
395
+ .replace(/::_PROPS_FIELDS_::/g, propsFields)
396
+ .replace(/::_NAMESPACE_::/g, namespace)
397
+ .replace(/\n\n\n+/g, '\n\n');
398
+ };
399
+ files.set(`${componentName}.g.h`, replaceContent(fileTemplate));
400
+ }
401
+ }
402
+ return files;
403
+ };
404
+ }
405
+ exports.createComponentGenerator = createComponentGenerator;
406
+ //# sourceMappingURL=GenerateComponentWindows.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerateComponentWindows.js","sourceRoot":"","sources":["../../src/generators/GenerateComponentWindows.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,YAAY,CAAC;;;AASb,mDAAwE;AACxE,uDAI2B;AAQ3B,MAAM,cAAc,GAAG;;;;;;;;4CAQqB,CAAC;AAE7C,MAAM,aAAa,GAAG;;;;;;;;;;;;;;;;;GAiBnB,CAAC;AAEJ,MAAM,mBAAmB,GAAG;;;CAG3B,CAAC;AACF,MAAM,oBAAoB,GAAG;;;CAG5B,CAAC;AAEF,MAAM,0BAA0B,GAAG;;;;IAI/B,CAAC;AAEL,MAAM,oBAAoB,GAAG;;;;;;;;;;;;GAY1B,CAAC;AAEJ,MAAM,kBAAkB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAwD1B,CAAC;AAEF,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkFxB,CAAC;AAEF,MAAM,YAAY,GAAG;EACnB,cAAc;;;;;;;;;;;;;CAaf,CAAC;AAEF,SAAS,qBAAqB,C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CAAC;;;;YAIA;oBACF,CAAC,CAAC,EAAE,CAAC;gBAEP,MAAM,QAAQ,GAAG,kBAAkB;qBAChC,OAAO,CAAC,wCAAwC,EAAE,eAAe,CAAC;qBAClE,OAAO,CAAC,uCAAuC,EAAE,cAAc,CAAC,CAAC;gBAEpE,eAAe;gBACf,MAAM,qBAAqB,GAAG,gBAAgB,CAAC,OAAO,CACpD,wCAAwC,EACxC,sBAAsB,CACvB,CAAC;gBAEF,eAAe;gBACf,MAAM,cAAc,GAAG,UAAU,QAAgB;oBAC/C,OAAO,QAAQ;yBACZ,OAAO,CAAC,oCAAoC,EAAE,eAAe,CAAC;yBAC9D,OAAO,CAAC,6BAA6B,EAAE,aAAa,CAAC;yBACrD,OAAO,CAAC,gCAAgC,EAAE,YAAY,CAAC;yBACvD,OAAO,CAAC,8BAA8B,EAAE,QAAQ,CAAC;yBACjD,OAAO,CAAC,+BAA+B,EAAE,qBAAqB,CAAC;yBAC/D,OAAO,CAAC,2BAA2B,EAAE,gBAAgB,CAAC;yBACtD,OAAO,CAAC,mBAAmB,EAAE,SAAS,CAAC;yBACvC,OAAO,CAAC,uBAAuB,EAAE,aAAa,CAAC;yBAC/C,OAAO,CAAC,0BAA0B,EAAE,gBAAgB,CAAC;yBACrD,OAAO,CAAC,qBAAqB,EAAE,WAAW,CAAC;yBAC3C,OAAO,CAAC,kBAAkB,EAAE,SAAS,CAAC;yBACtC,OAAO,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC;gBACjC,CAAC,CAAC;gBAEF,KAAK,CAAC,GAAG,CAAC,GAAG,aAAa,MAAM,EAAE,cAAc,CAAC,YAAY,CAAC,CAAC,CAAC;aACjE;SACF;QAED,OAAO,KAAK,CAAC;IACf,CAAC,CAAC;AACJ,CAAC;AAnSD,4DAmSC","sourcesContent":["/**\n * Copyright (c) Microsoft Corporation.\n * Licensed under the MIT License.\n * @format\n */\n\n'use strict';\n\nimport type {\n SchemaType,\n EventTypeAnnotation,\n PropTypeAnnotation,\n ObjectTypeAnnotation,\n CommandParamTypeAnnotation,\n} from '@react-native/codegen/lib/CodegenSchema';\nimport {getAliasCppName, setPreferredModuleName} from './AliasManaging';\nimport {\n translateComponentPropsFieldType,\n translateComponentEventType,\n translateCommandParamType,\n} from './PropObjectTypes';\nimport type {CppStringTypes} from './ObjectTypes';\nimport type {AliasMap} from './AliasManaging';\n\nexport type {CppStringTypes} from './ObjectTypes';\n\ntype FilesOutput = Map<string, string>;\n\nconst headerTemplate = `/*\n * This file is auto-generated from ::_COMPONENT_NAME_::NativeComponent spec file in flow / TypeScript.\n */\n#pragma once\n\n#include <JSValueComposition.h>\n#include <NativeModules.h>\n#include <winrt/Microsoft.ReactNative.Composition.h>\n#include <winrt/Microsoft.UI.Composition.h>`;\n\nconst propsTemplate = `REACT_STRUCT(::_PROPS_NAME_::)\nstruct ::_PROPS_NAME_:: : winrt::implements<::_PROPS_NAME_::, winrt::Microsoft::ReactNative::IComponentProps> {\n ::_PROPS_NAME_::(winrt::Microsoft::ReactNative::ViewProps props, const winrt::Microsoft::ReactNative::IComponentProps& cloneFrom)\n : ViewProps(props)\n {\n if (cloneFrom) {\n auto cloneFromProps = cloneFrom.as<::_PROPS_NAME_::>();\n::_PROP_INITIALIZERS_:: \n }\n }\n\n void SetProp(uint32_t hash, winrt::hstring propName, winrt::Microsoft::ReactNative::IJSValueReader value) noexcept {\n winrt::Microsoft::ReactNative::ReadProp(hash, propName, value, *this);\n }\n\n::_PROPS_FIELDS_::\n const winrt::Microsoft::ReactNative::ViewProps ViewProps;\n};`;\n\nconst propsObjectTemplate = `REACT_STRUCT(::_OBJECT_NAME_::)\nstruct ::_OBJECT_NAME_:: {\n::_OBJECT_FIELDS_::};\n`;\nconst eventsObjectTemplate = `REACT_STRUCT(::_OBJECT_NAME_::)\nstruct ::_OBJECT_NAME_:: {\n::_OBJECT_FIELDS_::};\n`;\n\nconst eventEmitterMethodTemplate = ` void ::_EVENT_NAME_::(::_EVENT_OBJECT_TYPE_:: &value) const {\n m_eventEmitter.DispatchEvent(L\"::_EVENT_NAME_NO_ON_::\", [value](const winrt::Microsoft::ReactNative::IJSValueWriter writer) {\n winrt::Microsoft::ReactNative::WriteValue(writer, value);\n });\n }`;\n\nconst eventEmitterTemplate = `::_COMPONENT_EVENT_OBJECT_TYPES_::\n\nstruct ::_EVENT_EMITTER_NAME_:: {\n ::_EVENT_EMITTER_NAME_::(const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter)\n : m_eventEmitter(eventEmitter) {}\n\n::_EVENT_EMITTER_USINGS_::\n\n::_EVENT_EMITTER_METHODS_::\n\n private:\n winrt::Microsoft::ReactNative::EventEmitter m_eventEmitter{nullptr};\n};`;\n\nconst baseStructTemplate = `\ntemplate<typename TUserData>\nstruct Base::_COMPONENT_NAME_:: {\n\n virtual void UpdateProps(\n const winrt::Microsoft::ReactNative::ComponentView &/*view*/,\n const winrt::com_ptr<::_COMPONENT_NAME_::Props> &newProps,\n const winrt::com_ptr<::_COMPONENT_NAME_::Props> &/*oldProps*/) noexcept {\n m_props = newProps;\n }\n\n // UpdateState will only be called if this method is overridden\n virtual void UpdateState(\n const winrt::Microsoft::ReactNative::ComponentView &/*view*/,\n const winrt::Microsoft::ReactNative::IComponentState &/*newState*/) noexcept {\n }\n\n virtual void UpdateEventEmitter(const std::shared_ptr<::_COMPONENT_NAME_::EventEmitter> &eventEmitter) noexcept {\n m_eventEmitter = eventEmitter;\n }\n\n // MountChildComponentView will only be called if this method is overridden\n virtual void MountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,\n const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &/*args*/) noexcept {\n }\n\n // UnmountChildComponentView will only be called if this method is overridden\n virtual void UnmountChildComponentView(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,\n const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &/*args*/) noexcept {\n }\n\n // Initialize will only be called if this method is overridden\n virtual void Initialize(const winrt::Microsoft::ReactNative::ComponentView &/*view*/) noexcept {\n }\n\n // CreateVisual will only be called if this method is overridden\n virtual winrt::Microsoft::UI::Composition::Visual CreateVisual(const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {\n return view.as<winrt::Microsoft::ReactNative::Composition::ComponentView>().Compositor().CreateSpriteVisual();\n }\n\n // FinalizeUpdate will only be called if this method is overridden\n virtual void FinalizeUpdate(const winrt::Microsoft::ReactNative::ComponentView &/*view*/,\n winrt::Microsoft::ReactNative::ComponentViewUpdateMask /*mask*/) noexcept {\n }\n\n::_COMPONENT_VIEW_COMMAND_HANDLERS_::\n\n ::_COMPONENT_VIEW_COMMAND_HANDLER_::\n\n const std::shared_ptr<::_COMPONENT_NAME_::EventEmitter>& EventEmitter() const { return m_eventEmitter; }\n const winrt::com_ptr<::_COMPONENT_NAME_::Props>& Props() const { return m_props; }\n\nprivate:\n winrt::com_ptr<::_COMPONENT_NAME_::Props> m_props;\n std::shared_ptr<::_COMPONENT_NAME_::EventEmitter> m_eventEmitter;\n};\n`;\n\nconst registerTemplate = `\ntemplate <typename TUserData>\nvoid Register::_COMPONENT_NAME_::NativeComponent(\n winrt::Microsoft::ReactNative::IReactPackageBuilder const &packageBuilder,\n std::function<void(const winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder&)> builderCallback) noexcept {\n packageBuilder.as<winrt::Microsoft::ReactNative::IReactPackageBuilderFabric>().AddViewComponent(\n L\"::_COMPONENT_NAME_::\", [builderCallback](winrt::Microsoft::ReactNative::IReactViewComponentBuilder const &builder) noexcept {\n auto compBuilder = builder.as<winrt::Microsoft::ReactNative::Composition::IReactCompositionViewComponentBuilder>();\n\n builder.SetCreateProps([](winrt::Microsoft::ReactNative::ViewProps props,\n const winrt::Microsoft::ReactNative::IComponentProps& cloneFrom) noexcept {\n return winrt::make<::_COMPONENT_NAME_::Props>(props, cloneFrom); \n });\n\n builder.SetUpdatePropsHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n const winrt::Microsoft::ReactNative::IComponentProps &newProps,\n const winrt::Microsoft::ReactNative::IComponentProps &oldProps) noexcept {\n auto userData = view.UserData().as<TUserData>();\n userData->UpdateProps(view, newProps ? newProps.as<::_COMPONENT_NAME_::Props>() : nullptr, oldProps ? oldProps.as<::_COMPONENT_NAME_::Props>() : nullptr);\n });\n\n builder.SetUpdateEventEmitterHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n const winrt::Microsoft::ReactNative::EventEmitter &eventEmitter) noexcept {\n auto userData = view.UserData().as<TUserData>();\n userData->UpdateEventEmitter(std::make_shared<::_COMPONENT_NAME_::EventEmitter>(eventEmitter));\n });\n\n if constexpr (&TUserData::FinalizeUpdate != &Base::_COMPONENT_NAME_::<TUserData>::FinalizeUpdate) {\n builder.SetFinalizeUpdateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n winrt::Microsoft::ReactNative::ComponentViewUpdateMask mask) noexcept {\n auto userData = view.UserData().as<TUserData>();\n userData->FinalizeUpdate(view, mask);\n });\n } \n\n if constexpr (&TUserData::UpdateState != &Base::_COMPONENT_NAME_::<TUserData>::UpdateState) {\n builder.SetUpdateStateHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n const winrt::Microsoft::ReactNative::IComponentState &newState) noexcept {\n auto userData = view.UserData().as<TUserData>();\n userData->member(view, newState);\n });\n }\n\n::_REGISTER_CUSTOM_COMMAND_HANDLER_::\n\n if constexpr (&TUserData::MountChildComponentView != &Base::_COMPONENT_NAME_::<TUserData>::MountChildComponentView) {\n builder.SetMountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n const winrt::Microsoft::ReactNative::MountChildComponentViewArgs &args) noexcept {\n auto userData = view.UserData().as<TUserData>();\n return userData->MountChildComponentView(view, args);\n });\n }\n\n if constexpr (&TUserData::UnmountChildComponentView != &Base::_COMPONENT_NAME_::<TUserData>::UnmountChildComponentView) {\n builder.SetUnmountChildComponentViewHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n const winrt::Microsoft::ReactNative::UnmountChildComponentViewArgs &args) noexcept {\n auto userData = view.UserData().as<TUserData>();\n return userData->UnmountChildComponentView(view, args);\n });\n }\n\n compBuilder.SetViewComponentViewInitializer([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {\n auto userData = winrt::make_self<TUserData>();\n if constexpr (&TUserData::Initialize != &Base::_COMPONENT_NAME_::<TUserData>::Initialize) {\n userData->Initialize(view);\n }\n view.UserData(*userData);\n });\n\n if constexpr (&TUserData::CreateVisual != &Base::_COMPONENT_NAME_::<TUserData>::CreateVisual) {\n compBuilder.SetCreateVisualHandler([](const winrt::Microsoft::ReactNative::ComponentView &view) noexcept {\n auto userData = view.UserData().as<TUserData>();\n return userData->CreateVisual(view);\n });\n }\n\n // Allow app to further customize the builder\n if (builderCallback) {\n builderCallback(compBuilder);\n }\n });\n}\n`;\n\nconst fileTemplate = `\n${headerTemplate}\n\nnamespace ::_NAMESPACE_:: {\n\n::_COMPONENT_PROP_OBJECT_TYPES_::\n::_COMPONENT_PROP_TYPES_::\n\n::_COMPONENT_EVENT_EMITTER_::\n\n::_BASE_COMPONENT_STRUCT_::\n\n::_COMPONENT_REGISTRATION_::\n} // namespace ::_NAMESPACE_::\n`;\n\nfunction capitalizeFirstLetter(s: string) {\n return s.charAt(0).toUpperCase() + s.slice(1);\n}\n\nexport function createComponentGenerator({\n namespace,\n cppStringType,\n}: {\n namespace: string;\n cppStringType: CppStringTypes;\n}) {\n return (\n _libraryName: string,\n schema: SchemaType,\n _moduleSpecName: string,\n ): FilesOutput => {\n const files = new Map<string, string>();\n\n const cppCodegenOptions = {cppStringType};\n\n for (const componentName of Object.keys(schema.modules)) {\n const component = schema.modules[componentName];\n setPreferredModuleName(componentName);\n\n if (component.type === 'Component') {\n console.log(`Generating ${componentName}.g.h`);\n\n const componentShape = component.components[componentName];\n\n componentShape.extendsProps.forEach(propsBaseType => {\n if (\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n propsBaseType.type !== 'ReactNativeBuiltInType' ||\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n propsBaseType.knownTypeName !== 'ReactNativeCoreViewProps'\n ) {\n throw new Error(\n 'Currently only supports props extending from ViewProps',\n );\n }\n });\n\n // Props\n const propObjectAliases: AliasMap<\n ObjectTypeAnnotation<PropTypeAnnotation>\n > = {types: {}, jobs: []};\n const propsName = `${componentName}Props`;\n const propsFields = componentShape.props\n .map(prop => {\n const propType = translateComponentPropsFieldType(\n prop.typeAnnotation,\n propObjectAliases,\n `${propsName}_${prop.name}`,\n cppCodegenOptions,\n );\n return ` REACT_FIELD(${prop.name})\\n ${\n prop.optional && !propType.alreadySupportsOptionalOrHasDefault\n ? `std::optional<${propType.type}>`\n : propType.type\n } ${prop.name}${propType.initializer};\\n`;\n })\n .join('\\n');\n\n const propInitializers = componentShape.props\n .map(prop => {\n return ` ${prop.name} = cloneFromProps->${prop.name};`;\n })\n .join('\\n');\n\n const propObjectTypes = propObjectAliases.jobs\n .map(propObjectTypeName => {\n const propObjectType = propObjectAliases.types[propObjectTypeName]!;\n const propsObjectFields = propObjectType.properties\n .map(property => {\n const propType = translateComponentPropsFieldType(\n property.typeAnnotation,\n propObjectAliases,\n `${propsName}_${property.name}`,\n cppCodegenOptions,\n );\n return ` REACT_FIELD(${property.name})\\n ${\n property.optional &&\n !propType.alreadySupportsOptionalOrHasDefault\n ? `std::optional<${propType.type}>`\n : propType.type\n } ${property.name}${propType.initializer};\\n`;\n })\n .join('\\n');\n\n return propsObjectTemplate\n .replace(\n /::_OBJECT_NAME_::/g,\n getAliasCppName(propObjectTypeName),\n )\n .replace(/::_OBJECT_FIELDS_::/g, propsObjectFields);\n })\n .join('\\n');\n\n // Events\n const eventObjectAliases: AliasMap<\n ObjectTypeAnnotation<EventTypeAnnotation>\n > = {types: {}, jobs: []};\n const eventEmitterName = `${componentName}EventEmitter`;\n const eventEmitterMethods = componentShape.events\n .filter(event => event.typeAnnotation.argument)\n .map(event => {\n if (event.typeAnnotation.argument?.baseTypes) {\n throw new Error(\n 'Events with base type arguments not currently supported',\n );\n }\n\n // Called to collect the eventObjectAliases\n translateComponentEventType(\n event.typeAnnotation.argument!,\n eventObjectAliases,\n `${event.name}`,\n cppCodegenOptions,\n );\n\n // onSomething -> something\n let eventNameLower = event.name.replace('on', '');\n eventNameLower =\n eventNameLower[0].toLowerCase() + eventNameLower.slice(1);\n\n return eventEmitterMethodTemplate\n .replace(/::_EVENT_NAME_::/g, event.name)\n .replace(/::_EVENT_NAME_NO_ON_::/g, eventNameLower)\n .replace(\n /::_EVENT_OBJECT_TYPE_::/g,\n event.name.replace('on', 'On'),\n );\n })\n .join('\\n\\n');\n\n const eventObjects = eventObjectAliases.jobs\n .map(eventObjectTypeName => {\n const eventObjectType =\n eventObjectAliases.types[eventObjectTypeName]!;\n const eventObjectFields = eventObjectType.properties\n .map(property => {\n const eventPropType = translateComponentEventType(\n property.typeAnnotation,\n eventObjectAliases,\n eventObjectTypeName,\n cppCodegenOptions,\n );\n return ` REACT_FIELD(${property.name})\\n ${\n property.optional &&\n !eventPropType.alreadySupportsOptionalOrHasDefault\n ? `std::optional<${eventPropType.type}>`\n : eventPropType.type\n } ${property.name}${eventPropType.initializer};\\n`;\n })\n .join('\\n');\n return eventsObjectTemplate\n .replace(\n /::_OBJECT_NAME_::/g,\n `${componentName}_${eventObjectTypeName.replace('on', 'On')}`,\n )\n .replace(/::_OBJECT_FIELDS_::/g, eventObjectFields);\n })\n .join('\\n');\n\n const eventObjectUsings = eventObjectAliases.jobs\n .map(eventObjectTypeName => {\n return ` using ${eventObjectTypeName.replace(\n 'on',\n 'On',\n )} = ${componentName}_${eventObjectTypeName.replace('on', 'On')};`;\n })\n .join('\\n');\n\n const eventEmitter = eventEmitterTemplate\n .replace(/::_COMPONENT_EVENT_OBJECT_TYPES_::/g, eventObjects)\n .replace(/::_EVENT_EMITTER_METHODS_::/g, eventEmitterMethods)\n .replace(/::_EVENT_EMITTER_USINGS_::/g, eventObjectUsings);\n\n // Commands\n const commandAliases: AliasMap<\n ObjectTypeAnnotation<CommandParamTypeAnnotation>\n > = {types: {}, jobs: []};\n const hasAnyCommands = componentShape.commands.length !== 0;\n const commandHandlers = hasAnyCommands\n ? componentShape.commands\n .map(command => {\n const commandArgs = command.typeAnnotation.params\n .map(param => {\n const commandArgType = translateCommandParamType(\n param.typeAnnotation,\n commandAliases,\n `${componentName}_${command.name}`,\n cppCodegenOptions,\n );\n return `${\n param.optional &&\n !commandArgType.alreadySupportsOptionalOrHasDefault\n ? `std::optional<${commandArgType.type}>`\n : commandArgType.type\n } ${param.name}`;\n })\n .join(', ');\n\n return ` // You must provide an implementation of this method to handle the \"${\n command.name\n }\" command\n virtual void Handle${capitalizeFirstLetter(\n command.name,\n )}Command(${commandArgs}) noexcept = 0;`;\n })\n .join('\\n\\n')\n : '';\n\n const commandHandler = hasAnyCommands\n ? `void HandleCommand(const winrt::Microsoft::ReactNative::ComponentView &view, const winrt::Microsoft::ReactNative::HandleCommandArgs& args) noexcept {\n auto userData = view.UserData().as<TUserData>();\n auto commandName = args.CommandName();\n${componentShape.commands\n .map(command => {\n const commaSeparatedCommandArgs = command.typeAnnotation.params\n .map(param => param.name)\n .join(', ');\n return ` if (commandName == L\"${command.name}\") {\n${\n command.typeAnnotation.params.length !== 0\n ? ` ${command.typeAnnotation.params\n .map(param => {\n const commandArgType = translateCommandParamType(\n param.typeAnnotation,\n commandAliases,\n `${componentName}_${command.name}`,\n cppCodegenOptions,\n );\n return `${\n param.optional &&\n !commandArgType.alreadySupportsOptionalOrHasDefault\n ? `std::optional<${commandArgType.type}>`\n : commandArgType.type\n } ${param.name};`;\n })\n .join('\\n')}\n winrt::Microsoft::ReactNative::ReadArgs(args.CommandArgs(), ${commaSeparatedCommandArgs});`\n : ''\n}\n userData->Handle${capitalizeFirstLetter(\n command.name,\n )}Command(${commaSeparatedCommandArgs});\n return;\n }`;\n })\n .join('\\n\\n')}\n }`\n : '';\n\n const registerCommandHandler = hasAnyCommands\n ? ` builder.SetCustomCommandHandler([](const winrt::Microsoft::ReactNative::ComponentView &view,\n const winrt::Microsoft::ReactNative::HandleCommandArgs& args) noexcept {\n auto userData = view.UserData().as<TUserData>();\n userData->HandleCommand(view, args);\n });`\n : '';\n\n const baseType = baseStructTemplate\n .replace(/::_COMPONENT_VIEW_COMMAND_HANDLERS_::/g, commandHandlers)\n .replace(/::_COMPONENT_VIEW_COMMAND_HANDLER_::/g, commandHandler);\n\n // Registration\n const componentRegistration = registerTemplate.replace(\n /::_REGISTER_CUSTOM_COMMAND_HANDLER_::/g,\n registerCommandHandler,\n );\n\n // Final output\n const replaceContent = function (template: string): string {\n return template\n .replace(/::_COMPONENT_PROP_OBJECT_TYPES_::/g, propObjectTypes)\n .replace(/::_COMPONENT_PROP_TYPES_::/g, propsTemplate)\n .replace(/::_COMPONENT_EVENT_EMITTER_::/g, eventEmitter)\n .replace(/::_BASE_COMPONENT_STRUCT_::/g, baseType)\n .replace(/::_COMPONENT_REGISTRATION_::/g, componentRegistration)\n .replace(/::_EVENT_EMITTER_NAME_::/g, eventEmitterName)\n .replace(/::_PROPS_NAME_::/g, propsName)\n .replace(/::_COMPONENT_NAME_::/g, componentName)\n .replace(/::_PROP_INITIALIZERS_::/g, propInitializers)\n .replace(/::_PROPS_FIELDS_::/g, propsFields)\n .replace(/::_NAMESPACE_::/g, namespace)\n .replace(/\\n\\n\\n+/g, '\\n\\n');\n };\n\n files.set(`${componentName}.g.h`, replaceContent(fileTemplate));\n }\n }\n\n return files;\n };\n}\n"]}
@@ -0,0 +1,15 @@
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 createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }: {
11
+ methodOnly: boolean;
12
+ namespace: string;
13
+ cppStringType: CppStringTypes;
14
+ separateDataTypes: boolean;
15
+ }): (_libraryName: string, schema: SchemaType, _moduleSpecName: string) => FilesOutput;
@@ -0,0 +1,144 @@
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.createNM2Generator = void 0;
9
+ const AliasManaging_1 = require("./AliasManaging");
10
+ const AliasGen_1 = require("./AliasGen");
11
+ const ValidateConstants_1 = require("./ValidateConstants");
12
+ const ValidateMethods_1 = require("./ValidateMethods");
13
+ const headerTemplate = `/*
14
+ * This file is auto-generated from a NativeModule spec file in js.
15
+ *
16
+ * This is a C++ Spec class that should be used with MakeTurboModuleProvider to register native modules
17
+ * in a way that also verifies at compile time that the native module matches the interface required
18
+ * by the TurboModule JS spec.
19
+ */
20
+ #pragma once`;
21
+ const specTemplate = `::_MODULE_CUSTOM_TYPES_REFLECTION_::
22
+ struct ::_MODULE_NAME_::Spec : winrt::Microsoft::ReactNative::TurboModuleSpec {
23
+ ::_MODULE_MEMBERS_TUPLES_::
24
+
25
+ template <class TModule>
26
+ static constexpr void ValidateModule() noexcept {
27
+ ::_MODULE_MEMBERS_CHECKS_::
28
+
29
+ ::_MODULE_MEMBERS_ERRORS_::
30
+ }`;
31
+ const typeOnlyTemplate = `
32
+ ${headerTemplate}
33
+
34
+ #include <string>
35
+ #include <optional>
36
+ #include <functional>
37
+ #include <vector>
38
+
39
+ namespace ::_NAMESPACE_:: {
40
+ ::_MODULE_CUSTOM_TYPES_::
41
+ } // namespace ::_NAMESPACE_::
42
+ `;
43
+ const moduleOnlyTemplate = `
44
+ ${headerTemplate}
45
+
46
+ ::_TYPE_DEFINITION_INCLUDE_::
47
+ #include <NativeModules.h>
48
+ #include <tuple>
49
+
50
+ namespace ::_NAMESPACE_:: {
51
+ ${specTemplate}
52
+ };
53
+
54
+ } // namespace ::_NAMESPACE_::
55
+ `;
56
+ const allInOneTemplate = `
57
+ ${headerTemplate}
58
+
59
+ #include <NativeModules.h>
60
+ #include <tuple>
61
+
62
+ namespace ::_NAMESPACE_:: {
63
+ ::_MODULE_CUSTOM_TYPES_::
64
+ ${specTemplate}
65
+ };
66
+
67
+ } // namespace ::_NAMESPACE_::
68
+ `;
69
+ function createNM2Generator({ methodOnly, namespace, cppStringType, separateDataTypes, }) {
70
+ return (_libraryName, schema, _moduleSpecName) => {
71
+ const files = new Map();
72
+ for (const moduleName of Object.keys(schema.modules)) {
73
+ const nativeModule = schema.modules[moduleName];
74
+ // from 0.65 facebook's react-native-codegen
75
+ // the module name has the Native prefix comparing to 0.63
76
+ // when reading files we provided
77
+ const preferredModuleName = moduleName.startsWith('Native')
78
+ ? moduleName.substr(6)
79
+ : moduleName;
80
+ (0, AliasManaging_1.setPreferredModuleName)(preferredModuleName);
81
+ if (nativeModule.type === 'NativeModule') {
82
+ console.log(`Generating Native${preferredModuleName}Spec.g.h`);
83
+ // copy all explicit to a map
84
+ const aliases = (0, AliasGen_1.createAliasMap)(nativeModule.aliasMap);
85
+ // prepare methods
86
+ const methods = (0, ValidateMethods_1.generateValidateMethods)(nativeModule, aliases, {
87
+ cppStringType,
88
+ });
89
+ let tuples = `
90
+ static constexpr auto methods = std::tuple{
91
+ ${methods.traversedPropertyTuples}${methods.traversedEventEmitterTuples ? '\n' : ''}${methods.traversedEventEmitterTuples}
92
+ };`;
93
+ let checks = `
94
+ constexpr auto methodCheckResults = CheckMethods<TModule, ::_MODULE_NAME_::Spec>();`;
95
+ let errors = methods.traversedProperties +
96
+ (methods.traversedEventEmitters ? '\n' : '') +
97
+ methods.traversedEventEmitters;
98
+ // prepare constants
99
+ const constants = (0, ValidateConstants_1.generateValidateConstants)(nativeModule, aliases);
100
+ if (constants !== undefined && !methodOnly) {
101
+ tuples = `
102
+ static constexpr auto constants = std::tuple{
103
+ ${constants[0]}
104
+ };${tuples}`;
105
+ checks = `
106
+ constexpr auto constantCheckResults = CheckConstants<TModule, ::_MODULE_NAME_::Spec>();${checks}`;
107
+ errors = `${constants[1]}
108
+
109
+ ${errors}`;
110
+ }
111
+ // generate code for structs
112
+ const [customTypes, customReflection] = (0, AliasGen_1.generateAliases)(aliases, {
113
+ cppStringType,
114
+ });
115
+ const customTypesExist = customTypes !== '';
116
+ const replaceContent = function (template) {
117
+ return template
118
+ .replace(/::_MODULE_CUSTOM_TYPES_::/g, customTypes)
119
+ .replace(/::_MODULE_CUSTOM_TYPES_REFLECTION_::/g, customReflection)
120
+ .replace(/::_MODULE_MEMBERS_TUPLES_::/g, tuples.substring(1))
121
+ .replace(/::_MODULE_MEMBERS_CHECKS_::/g, checks.substring(1))
122
+ .replace(/::_MODULE_MEMBERS_ERRORS_::/g, errors)
123
+ .replace(/::_MODULE_NAME_::/g, preferredModuleName)
124
+ .replace(/::_TYPE_DEFINITION_INCLUDE_::/g, customTypesExist
125
+ ? `// #include "Native${preferredModuleName}DataTypes.g.h" before this file to use the generated type definition`
126
+ : '')
127
+ .replace(/::_NAMESPACE_::/g, namespace);
128
+ };
129
+ if (separateDataTypes) {
130
+ if (customTypesExist) {
131
+ files.set(`Native${preferredModuleName}DataTypes.g.h`, replaceContent(typeOnlyTemplate));
132
+ }
133
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(moduleOnlyTemplate));
134
+ }
135
+ else {
136
+ files.set(`Native${preferredModuleName}Spec.g.h`, replaceContent(allInOneTemplate));
137
+ }
138
+ }
139
+ }
140
+ return files;
141
+ };
142
+ }
143
+ exports.createNM2Generator = createNM2Generator;
144
+ //# sourceMappingURL=GenerateNM2.js.map