Files
yaak/src-web/lib/prompt-form.tsx
Gregory Schier 09e78d9210 Add dynamic() support to prompt.form() plugin API
- prompt.form() inputs can now have dynamic() callbacks that update
  reactively when form values change (same pattern as auth/template plugins)
- Changed PromptFormRequest routing from one-shot to bidirectional events
- Added PromptFormResponse.done field to distinguish intermediate updates
- Added optional size (enum) to PromptFormRequest for dialog sizing
- Added optional rows to FormInputEditor for fixed height editors
- New httpsnippet plugin: generates code snippets with dynamic language
  and library selectors that update the code preview in real-time
2026-02-05 15:17:39 -08:00

53 lines
1.4 KiB
TypeScript

import type { FormInput, JsonPrimitive } from '@yaakapp-internal/plugins';
import type { DialogProps } from '../components/core/Dialog';
import type { PromptProps } from '../components/core/Prompt';
import { Prompt } from '../components/core/Prompt';
import { showDialog } from './dialog';
type FormArgs = Pick<DialogProps, 'title' | 'description' | 'size'> &
Omit<PromptProps, 'onClose' | 'onCancel' | 'onResult'> & {
id: string;
onValuesChange?: (values: Record<string, JsonPrimitive>) => void;
onInputsUpdated?: (cb: (inputs: FormInput[]) => void) => void;
};
export async function showPromptForm({
id,
title,
description,
size,
onValuesChange,
onInputsUpdated,
...props
}: FormArgs) {
return new Promise((resolve: PromptProps['onResult']) => {
showDialog({
id,
title,
description,
hideX: true,
size: size ?? 'sm',
disableBackdropClose: true, // Prevent accidental dismisses
onClose: () => {
// Click backdrop, close, or escape
resolve(null);
},
render: ({ hide }) =>
Prompt({
onCancel: () => {
// Click cancel button within dialog
resolve(null);
hide();
},
onResult: (v) => {
resolve(v);
hide();
},
onValuesChange,
onInputsUpdated,
...props,
}),
});
});
}