# @embedpdf/plugin-form — ./internal Box [InterfaceDeclaration] (from packages/plugin/form/src/core/model.ts): export interface Box{ x: number; y: number; width: number; height: number; } CreateFieldInput [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface CreateFieldInput{ family: AuthorableFormFamily; page: PageRef; bounds: Box; name?: string; appearance?: WidgetAppearance; options?: readonly{ label: string; value: string} []; } CreatedField [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface CreatedField{ field: FormFieldDTO; widget: FormFieldDTO['widgets'][number] | null; } FieldKey [TypeAliasDeclaration] (from packages/plugin/form/src/core/model.ts): export type FieldKey = string; FillItem [TypeAliasDeclaration] (from packages/plugin/form/src/core/fill-items.ts): export type FillItem = FillItemBase & ( |{ control: 'text'; value: string; multiline: boolean; password: boolean; maxLength: number | null; comb: boolean; } |{ control: 'toggle'; kind: 'checkbox' | 'radio'; checked: boolean; onState: string} |{ control: 'choice'; kind: 'combo' | 'list'; edit: boolean; multi: boolean; options: FormFieldOption[]; selected: string[]; } |{ control: 'button'} |{ control: 'signature'; signed: boolean} ); FormAction [TypeAliasDeclaration] (from packages/plugin/form/src/model.ts): export type FormAction = |{ type: 'SET_MODEL'; model: Model} |{ type: 'SET_STATUS'; status: ResourceStatus} ; FormCapability [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormCapability{ getSnapshot(): FormSnapshot | null; getStatus(): ResourceStatus; listFields(filter?: FormFilter): readonly FormFieldDTO[]; getField(ref: FormFieldRef): FormFieldDTO | null; getFieldForWidget(widget: WidgetAddress): FormFieldDTO | null; getValue(ref: FormFieldRef): FormFieldValue | null; listWidgets(page: PageRef): readonly FormWidgetItem[]; getWidgetAt(page: PageRef, point:{ x: number; y: number} ): WidgetHit | null; setValue( ref: FormFieldRef, value: FormFieldValue, options?: OperationOptions, ): Promise; setValueRaw( ref: FormFieldRef, value: FormFieldValue, options?: OperationOptions, ): Promise; setValues( entries: readonly{ ref: FormFieldRef; value: FormFieldValue} [], options?: OperationOptions, ): Promise>; setText(ref: FormFieldRef, text: string, options?: OperationOptions): Promise; setChecked( ref: FormFieldRef, onState: string | null, options?: OperationOptions, ): Promise; setChoice( ref: FormFieldRef, values: readonly string[], options?: OperationOptions, ): Promise; reset(ref: FormFieldRef, options?: OperationOptions): Promise; resetAll( options?:{ fields?: readonly FormFieldRef[]; exclude?: boolean} & OperationOptions, ): Promise>; activateWidget( widget: AnnotationRef, options?: OperationOptions, ): Promise; exportData(format?: FormDataFormat, options?: OperationOptions): Promise; importData( data: Uint8Array | ArrayBuffer, format?: FormDataFormat, options?: OperationOptions, ): Promise; exportValues(): Readonly>; importValues( values: Readonly>, options?: OperationOptions, ): Promise>; repair(options?: FormRepairOptions & OperationOptions): Promise; refresh(options?: OperationOptions): Promise; createField(input: CreateFieldInput, options?: OperationOptions): Promise; updateField(ref: FormFieldRef, patch: FormFieldPatch, options?: OperationOptions): Promise; deleteField(ref: FormFieldRef, options?: OperationOptions): Promise; attachWidget(ref: FormFieldRef, widget: AnnotationRef, options?: OperationOptions): Promise; detachWidget(ref: FormFieldRef, widget: AnnotationRef, options?: OperationOptions): Promise; canRead(): boolean; canFill(): boolean; canDesign(): boolean; readonly onValueChanged: EventHook; readonly onFieldCreated: EventHook; readonly onFieldUpdated: EventHook; readonly onFieldDeleted: EventHook; readonly onValidationRejected: EventHook; readonly onResynced: EventHook; } FormCommitResult [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormCommitResult{ status: FormCommitStatus; scripted: boolean; effectsResult: FormEffectsResult | null; uiEffects: FormUiEffect[]; diagnostics: ScriptDiagnostic[]; error?: ScriptExecutionError; } FormCommitStatus [TypeAliasDeclaration] (from packages/plugin/form/src/contract.ts): export type FormCommitStatus = 'applied' | 'unchanged' | 'rejected' | 'failed'; FormConfig [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormConfig{ validation?: 'scripts' | 'none'; } FormDataExport [InterfaceDeclaration] (from packages/engine/core/src/mutation/FormMutationResults.ts): export interface FormDataExport{ format: 'fdf' | 'xfdf'; bytes: Uint8Array; } FormDataFormat [TypeAliasDeclaration] (from packages/engine/core/src/forms/value.ts): export type FormDataFormat = 'fdf' | 'xfdf'; FormFieldChangedEvent [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormFieldChangedEvent{ readonly ref: FormFieldRef; readonly field: FormFieldDTO | null; readonly origin: ChangeOrigin; } FormFieldDTO [TypeAliasDeclaration] (from packages/engine/core/src/forms/field.ts): export type FormFieldDTO = | TextFieldDTO | CheckboxFieldDTO | RadioFieldDTO | ComboBoxFieldDTO | ListBoxFieldDTO | PushButtonFieldDTO | SignatureFieldDTO | UnknownFieldDTO; FormFieldFamily [TypeAliasDeclaration] (from packages/engine/core/src/forms/field.ts): export type FormFieldFamily = | 'text' | 'checkbox' | 'radio' | 'combobox' | 'listbox' | 'pushbutton' | 'signature' | 'unknown'; FormFieldPatch [TypeAliasDeclaration] (from packages/engine/core/src/forms/patch.ts): export type FormFieldPatch = | TextFieldPatch | CheckboxFieldPatch | RadioFieldPatch | ComboBoxFieldPatch | ListBoxFieldPatch; FormFieldRef [TypeAliasDeclaration] (from packages/engine/core/src/identity/FormFieldRef.ts): export type FormFieldRef = |{ kind: 'objectNumber'; fieldObjectNumber: number} |{ kind: 'fqn'; name: string} ; FormFieldValue [TypeAliasDeclaration] (from packages/engine/core/src/forms/value.ts): export type FormFieldValue = |{ type: 'text'; value: string} |{ type: 'toggle'; state: string | null} |{ type: 'choice'; values: string[]} ; FormFilter [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormFilter{ readonly family?: FormFieldFamily; readonly page?: PageRef; readonly name?: string; } FormHostCapability [InterfaceDeclaration] (from packages/plugin/form/src/host-contract.ts): export interface FormHostCapability extends FormCapability{ listFillItems(page: PageRef): FillItem[]; getFillItem(annotObjectNumber: number): FillItem | null; ensureLoaded(page: PageRef): void; getPageBox(page: PageRef): Box | null; notifyWidgetEvent( field: FormFieldRef, widget: AnnotationRef, event: PdfAnnotationEventKind, ): void; resetFormAction( fields: PdfActionTargetRef[] | null, exclude: boolean, origin?: ActionOrigin, ): Promise; resolveSubmitDataset( intent: SubmitIntent, ctx: ActionContext, diagnose: (diagnostic: ActionDiagnostic) => void, ): Promise; commitScriptFormEffects(effects: FormEffect[]): Promise; } FormImportResult [InterfaceDeclaration] (from packages/engine/core/src/mutation/FormMutationResults.ts): export interface FormImportResult{ fieldsTotal: number; fieldsApplied: number; fieldsSkipped: number; widgetsChanged: number; snapshot: FormSnapshot; meta: MutationMeta; } FormRepairOptions [InterfaceDeclaration] (from packages/engine/core/src/engine/DocumentFormsService.ts): export interface FormRepairOptions{ bakeAppearances?: boolean; } FormRepairResult [InterfaceDeclaration] (from packages/engine/core/src/mutation/FormMutationResults.ts): export interface FormRepairResult{ acroformCreated: boolean; fieldsLinked: number; widgetsLinked: number; fieldsUnrepairable: number; appearancesBaked: number; needAppearancesCleared: boolean; meta: MutationMeta; } FormResyncedEvent [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormResyncedEvent{ readonly snapshot: FormSnapshot; } FormSetValueResult [InterfaceDeclaration] (from packages/engine/core/src/mutation/FormMutationResults.ts): export interface FormSetValueResult{ field: FormFieldDTO; changedWidgets: FormWidget[]; meta: MutationMeta; } FormSnapshot [InterfaceDeclaration] (from packages/engine/core/src/forms/snapshot.ts): export interface FormSnapshot{ formKind: FormKind; needsAppearances: boolean; fields: FormFieldDTO[]; calculationOrder: Array; } FormState [InterfaceDeclaration] (from packages/plugin/form/src/model.ts): export interface FormState{ model: Model; status: ResourceStatus; } FormToken [VariableDeclaration] (from packages/plugin/form/src/host-contract.ts): FormToken = PublicFormToken as unknown as CapabilityToken FormUiEffect [TypeAliasDeclaration] (from packages/plugin/form/src/contract.ts): export type FormUiEffect = ScriptUiEffect &{ phase: 'boot' | 'user'; origin?: ActionOrigin; } ; FormValidationRejectedEvent [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormValidationRejectedEvent{ readonly ref: FormFieldRef; readonly issues: readonly ScriptDiagnostic[]; } FormValueChangedEvent [InterfaceDeclaration] (from packages/plugin/form/src/contract.ts): export interface FormValueChangedEvent{ readonly ref: FormFieldRef; readonly field: FormFieldDTO; readonly origin: ChangeOrigin; } FormWidgetItem [TypeAliasDeclaration] (from packages/plugin/form/src/contract.ts): export type FormWidgetItem = FillItem; SetValueResult [TypeAliasDeclaration] (from packages/plugin/form/src/contract.ts): export type SetValueResult = FormCommitResult; WidgetActivationResult [TypeAliasDeclaration] (from packages/plugin/form/src/contract.ts): export type WidgetActivationResult = |{ kind: 'form'; result: FormCommitResult} |{ kind: 'dispatched'; result: ActionTriggerResult} ; WidgetAddress [TypeAliasDeclaration] (from packages/plugin/form/src/contract.ts): export type WidgetAddress = AnnotationRef |{ annotObjectNumber: number} ; WidgetAppearance [TypeAliasDeclaration] (from packages/engine/core/src/annotation/kinds/widget.shared.ts): export type WidgetAppearance = WidgetStyleDraftFields; WidgetHit [InterfaceDeclaration] (from packages/plugin/form/src/core/model.ts): export interface WidgetHit{ annotObjectNumber: number; field: FormFieldDTO; box: Box; } createFormCapability [FunctionDeclaration] (from packages/plugin/form/src/controller.ts): export function createFormCapability( ctx: FormContext, config: FormConfig ={ } , ): FormHostCapability{ const{ api, connect} = createFormController(ctx, config); connect(); return api; } createFormController [FunctionDeclaration] (from packages/plugin/form/src/controller.ts): export function createFormController( ctx: FormContext, config: FormConfig ={ } , ):{ api: FormHostCapability; connect(): void} { const services = createServices(ctx, config); const{ events, authority} = services; const fields = createFieldReads(services); const widgets = createWidgetReads(ctx, services); const hydration = createHydration(ctx, services); const values = createValueWrites(ctx, services, hydration); const resets = createResetWrites(ctx, services, hydration); const design = createFieldWrites(ctx, services, hydration, widgets); const interchange = createInterchange(ctx, services, hydration); const activation = createActivation(ctx, services, hydration, fields); const scripts = createScriptEffects(ctx, services, hydration); const api = composeApi('form', [ fields.api, widgets.api, hydration.api, values.api, resets.api, design.api, interchange.api, activation.api, scripts.api, { canRead: () => authority.can('doc.forms.read'), canFill: () => authority.can('doc.forms.fill'), canDesign: () => authority.can('doc.forms.modify'), onValueChanged: events.valueChanged.on, onFieldCreated: events.fieldCreated.on, onFieldUpdated: events.fieldUpdated.on, onFieldDeleted: events.fieldDeleted.on, onValidationRejected: events.validationRejected.on, onResynced: events.resynced.on, } , ]) satisfies FormHostCapability; return{ api, connect(){ subscribeDocumentEvents(ctx, services, hydration); void hydration.refresh(); } , } ; } createPlaceHandler [FunctionDeclaration] (from packages/plugin/form/src/tools/handlers.ts): export function createPlaceHandler( form: FormHostCapability, interaction: InteractionCapability, annotation: AnnotationHostCapability | null, ): InteractionHandler{ let origin:{ page: PageRef; start: Vec; last: Vec} | null = null; return{ id: 'form-place', priority: 95, enabledFor: (t) => t.enables.has('form-place'), onDown: (s) =>{ if (!s.page || !FORM_TOOL_BY_ID.has(interaction.getActiveToolId())) return false; if (!form.canDesign()) return false; origin ={ page: s.page.ref, start: s.page.point, last: s.page.point} ; return true; } , onMove: (s) =>{ if (!origin) return; const point = samplePointOn(s, origin.page); if (!point) return; origin.last = point; const box = rectFromCorners(origin.start, point); if (annotation){ if (Math.max(box.width, box.height) >= MIN_DRAG){ annotation.setPlacementPreview(interaction.getActiveToolId(), origin.page, box); } else{ annotation.clearPlacementPreview(); } } } , onUp: (s) =>{ if (!origin) return; const o = origin; origin = null; annotation?.clearPlacementPreview(); const toolId = interaction.getActiveToolId(); const tool = FORM_TOOL_BY_ID.get(toolId); if (!tool) return; const end = samplePointOn(s, o.page) ?? o.last; const dragged = rectFromCorners(o.start, end); const isClick = dragged.width < MIN_DRAG && dragged.height < MIN_DRAG; const pageBox = form.getPageBox(o.page); const box = isClick ? boxOfClick(o.start, tool.clickCreate, pageBox) : dragged; form .createField({ family: tool.family, page: o.page, bounds: box, appearance: widgetAppearanceFromProps( annotation ? annotation.getToolDefaults(toolId) : tool.defaults, ), } ) .then((placed) =>{ if (!annotation || interaction.getActiveToolId() !== toolId) return; const ref = placed.widget?.ref; if (!ref) return; annotation.select(ref); } ) .catch((err) =>{ globalThis.console?.error('[form] createField failed:', err); } ); } , } ; } fieldKeyOf [VariableDeclaration] (from packages/plugin/form/src/core/model.ts): fieldKeyOf = (field:{ fieldObjectNumber: number; name: string} ): FieldKey => field.fieldObjectNumber > 0 ? `obj:${ field.fieldObjectNumber} ` : `fqn:${ field.name} ` fieldRef [VariableDeclaration] (from packages/plugin/form/src/contract.ts): fieldRef ={ byName: (name: string): FormFieldRef => ({ kind: 'fqn', name} ), byObjectNumber: (fieldObjectNumber: number): FormFieldRef => ({ kind: 'objectNumber', fieldObjectNumber, } ), } formReducer [VariableDeclaration] (from packages/plugin/form/src/model.ts): formReducer = (state: FormState, action: FormAction): FormState =>{ switch (action.type){ case 'SET_MODEL': return{ ...state, model: action.model} ; case 'SET_STATUS': return state.status === action.status ? state :{ ...state, status: action.status} ; default: return state; } } initialFormState [VariableDeclaration] (from packages/plugin/form/src/model.ts): initialFormState = (): FormState => ({ model: initialModel(), status: 'idle'} )