/** * The **Import Engine** — Photon Grid's public, framework-agnostic entry point * for ingesting Excel / CSV / TSV / Clipboard data. It mirrors the * {@link import('../export/export-engine').ExportEngine} (its inverse): one * engine per grid, constructed with the {@link EventBus}, exposed through thin * {@link import('../../core/grid-api').GridApi} methods. * * Flow for every source: * 1. obtain raw bytes/text and normalize into a {@link Workbook} (the only * source-specific step); * 2. run the shared {@link ImportPipeline} (validate → map → detect → discover); * 3. apply the {@link ImportResult} to the grid through the injected * {@link GridImportSink} (the public `setColumns`/`setData`/`appendData` * seams) according to the {@link ImportMode}; * 4. emit `IMPORT_START` / `IMPORT_PROGRESS` / `IMPORT_COMPLETE` / `IMPORT_ERROR`. * * The engine never evaluates formulas: `=`-prefixed cells are carried into row * data verbatim, and the grid's existing `setData → FormulaInitializer` path * registers them with the one Formula Engine. It also never imports * `GridCore` — it writes only through the {@link GridImportSink} port — so the * architecture rule that business logic stays free of composition-root details * is preserved. * * @packageDocumentation */ import type { EventBus } from '../../event-bus/event-bus'; import { ImportSourceType, type GridImportSink, type ImportOptions, type ImportResult } from '../../types/import.types'; import type { Workbook } from './model/workbook'; import { type ClipboardTextReader } from './importers/clipboard-importer'; import type { WorkbookParser } from './parser/workbook-parser'; /** Orchestrates the unified import pipeline and feeds the grid. */ export declare class ImportEngine { private readonly eventBus; private readonly clipboardReader?; /** Registered Excel parser (SheetJS adapter or custom); `null` until set. */ private parser; private static globalParser; /** * Per-session mapping memory: imported header → target grid `field`. Lets a * mapping resolved (or confirmed) once be reused for later imports in the * same session. This is also where a future mapping dialog would persist. */ private readonly rememberedMapping; /** * @param eventBus - Grid event bus for lifecycle/progress events. * @param clipboardReader - Optional clipboard engine used to read pasted text. */ constructor(eventBus: EventBus, clipboardReader?: ClipboardTextReader | undefined); /** * Registers the parser used for binary Excel files (e.g. the optional SheetJS * adapter). Until one is registered, `.xlsx`/`.xls` imports fail with a * friendly validation error rather than throwing an opaque parser exception. * * @param parser - The workbook parser to use for Excel input. */ registerWorkbookParser(parser: WorkbookParser): void; /** Whether Excel import is currently available (a parser is registered). */ get isExcelAvailable(): boolean; /** Returns the module-global workbook parser, if any. */ static getGlobalWorkbookParser(): WorkbookParser | null; /** Registers a module-global workbook parser applied to every new grid. */ static registerGlobalWorkbookParser(parser: WorkbookParser | null): void; /** * Imports a {@link File} (from an `` or drop). The source is * inferred from the extension: `.xlsx`/`.xls` → Excel, `.tsv` → TSV, anything * else → CSV. * * @param file - The file to import. * @param sink - The grid write port. * @param options - Import options. * @returns The import result (also emitted via `IMPORT_COMPLETE`). */ importFile(file: File, sink: GridImportSink, options?: ImportOptions): Promise; /** * Imports a {@link File} as an explicit source, bypassing extension * inference. Used by the `importExcel`/`importCsv`/`importTsv` API wrappers. * * @param file - The file to import. * @param source - The source type to treat the file as. * @param sink - The grid write port. * @param options - Import options. * @returns The import result. */ importFileAs(file: File, source: ImportSourceType, sink: GridImportSink, options?: ImportOptions): Promise; /** * Imports a raw text payload as a given delimited/clipboard source. * * @param text - The CSV/TSV/clipboard text. * @param source - Which text source this is. * @param sink - The grid write port. * @param options - Import options. * @returns The import result. */ importText(text: string, source: ImportSourceType, sink: GridImportSink, options?: ImportOptions): Promise; /** * Imports the current clipboard contents (TSV, as emitted by Excel / Sheets). * * @param sink - The grid write port. * @param options - Import options. * @returns The import result. */ importFromClipboard(sink: GridImportSink, options?: ImportOptions): Promise; /** * Imports an already-parsed {@link Workbook} (e.g. produced by a custom * importer). Routes through the same pipeline as every other source. * * @param workbook - The workbook to import. * @param sink - The grid write port. * @param options - Import options. * @returns The import result. */ importWorkbook(workbook: Workbook, sink: GridImportSink, options?: ImportOptions): Promise; /** * Shared execution wrapper: emits START, obtains the workbook via * `produce`, runs the pipeline, applies the result (or reports validation * failure), and emits COMPLETE/ERROR. */ private execute; /** Normalizes CSV/TSV/clipboard text into a workbook. */ private textToWorkbook; /** * Applies a validated result to the grid via the sink, honoring the import * mode. Replace-with-defineColumns redefines the schema; every other mode maps * the imported rows onto the existing columns first. */ private applyToGrid; /** * Re-keys imported rows (keyed by inferred field) onto the grid's existing * column fields using an explicit or auto-resolved mapping, and remembers the * resolved mapping for the session. */ private remapOntoExisting; /** Emits an `IMPORT_PROGRESS` event for a stage. */ private emitProgress; /** Infers the {@link ImportSourceType} from a file name's extension. */ static sourceFromFileName(fileName: string): ImportSourceType; /** Monotonic-ish timestamp for duration measurement (falls back to `Date.now`). */ private static now; } //# sourceMappingURL=import-engine.d.ts.map