(...args: any[])
| 201 | ): FieldTree<TModel>; |
| 202 | |
| 203 | export function form<TModel>(...args: any[]): FieldTree<TModel> { |
| 204 | const [model, schema, options] = normalizeFormArgs<TModel>(args); |
| 205 | const injector = options?.injector ?? inject(Injector); |
| 206 | const pathNode = runInInjectionContext(injector, () => SchemaImpl.rootCompile(schema)); |
| 207 | const fieldManager = new FormFieldManager( |
| 208 | injector, |
| 209 | options?.name, |
| 210 | options?.submission as FormSubmitOptions<unknown, unknown> | undefined, |
| 211 | ); |
| 212 | const adapter = options?.adapter ?? new BasicFieldAdapter(); |
| 213 | const fieldRoot = FieldNode.newRoot(fieldManager, model, pathNode, adapter); |
| 214 | fieldManager.createFieldManagementEffect(fieldRoot.structure); |
| 215 | |
| 216 | // Register a WebMCP tool for the form if configured. |
| 217 | const {experimentalWebMcpTool} = options ?? {}; |
| 218 | if (experimentalWebMcpTool) { |
| 219 | const registerWebMcpForm = runInInjectionContext(injector, () => |
| 220 | inject(REGISTER_WEBMCP_FORM, {optional: true}), |
| 221 | ); |
| 222 | if (registerWebMcpForm) { |
| 223 | runInInjectionContext(injector, () => |
| 224 | registerWebMcpForm(fieldRoot.fieldTree, { |
| 225 | name: experimentalWebMcpTool.name, |
| 226 | description: experimentalWebMcpTool.description, |
| 227 | }), |
| 228 | ); |
| 229 | } else { |
| 230 | if (typeof ngDevMode !== 'undefined' && ngDevMode) { |
| 231 | throw new Error( |
| 232 | `Cannot register form "${experimentalWebMcpTool.name}" as a WebMCP tool. ` + |
| 233 | `Make sure to use \`provideExperimentalWebMcpForms()\` in your application bootstrap configuration.`, |
| 234 | ); |
| 235 | } |
| 236 | } |
| 237 | } |
| 238 | |
| 239 | return fieldRoot.fieldTree as FieldTree<TModel>; |
| 240 | } |
| 241 | |
| 242 | /** |
| 243 | * Applies a schema to each item of an array. |
searching dependent graphs…