/** * WordPress dependencies */ import { dispatch } from '@safe-wordpress/data'; import { render } from '@safe-wordpress/element'; /** * Internal dependencies */ import './field-management'; import { store as NC_SETTINGS } from './store'; import { fields } from './fields'; import type { FieldId, Attributes } from './store/types'; type Settings = { readonly attributes: Attributes; readonly component: string; readonly name: FieldId; readonly value: string; }; export function initField( id: string, settings: Settings ): void { const { component } = settings; const Component = fields[ component ]; if ( ! Component ) { return; } const node = document.getElementById( id ); if ( ! node ) { return; } const { name, value, attributes } = settings; const { initField: initTheField } = dispatch( NC_SETTINGS ); void initTheField( name, value, attributes ); render( , node ); }