// Copyright (c) Cratis. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. import { lazy } from 'react'; import { FormPropertyNames, InteractionAction, WidthSizeClass } from '@cratis/scene.model'; import { formSuccessContinuation } from './formSuccessContinuation'; import { RegisteredComponentProps, useInteractionScope } from '@cratis/scene.react'; import { ArcRuntimeBoundary, BindingKind, MissingBinding, resolveElementBinding } from '../bindings'; import type { BoundConstructor } from '../bindings'; import { numberProperty, stringArrayProperty, stringProperty, unionProperty } from '../properties'; import { commandFormLayout } from './commandFormLayout'; import { commandInputs } from './commandInputs'; const CommandFormRuntime = lazy(() => import('./CommandFormRuntime')); // Arc's useCommand constructs the proxy only on mount. Key by the actual registered class, // not its Scene name (which may be re-registered with a different route or roles). const commandKeys = new WeakMap(); let nextCommandKey = 0; function commandKey(command: BoundConstructor): number { let key = commandKeys.get(command); if (key === undefined) { key = ++nextCommandKey; commandKeys.set(command, key); } return key; } /** * Auto mode follows supported native proxy descriptors; opt-in inputs bind exactly named fields * inside a single native Arc form. Neither mode consumes the content slot. */ export function SceneCommandForm({ element }: RegisteredComponentProps) { const scope = useInteractionScope(); const { name, target } = resolveElementBinding(element, BindingKind.Command); const continuation = formSuccessContinuation(element.properties[FormPropertyNames.onSubmit] as InteractionAction[] | undefined, name ?? '', scope); if (!target) return ; const mode = unionProperty(element.properties, 'mode', ['auto', 'manual'] as const) ?? (Object.hasOwn(element.properties, 'inputs') ? 'manual' : 'auto'); const inputs = mode === 'manual' ? commandInputs(element.properties) : undefined; if (mode === 'manual' && !inputs) return
Invalid command form inputs declaration
; return ( ); }