Skip to content

Mapper Component Overview

The <mapper-component> is a visual data transformation tool that allows users to map data from input sources to output structures using a node-based interface.

import { defineCustomElement } from 'vue';
import MapperCe from '@/mapper/view/Mapper.ce.vue';
customElements.define('mapper-component', defineCustomElement(MapperCe));

  • Visual Mapping: Drag connections between input fields and output fields
  • Transformation Nodes: Built-in tools for data manipulation
  • Preview: Test mappings with sample data
  • VueFlow Based: Same visual paradigm as the flow editor

PropTypeDefaultDescription
withActionsbooleanfalseShow Save/Preview buttons in the toolbar

Node TypePurpose
sourceInput data structure (InputTool)
targetOutput data structure (OutputTool)
collect_extractorExtract nested object fields (ObjectSourceTool)
list_iteratorIterate over array items (ListIteratorTool)
substringExtract substring from text (SubstringTool)
get_by_indexGet array item by index (GetByIndexTool)
accumulatorCollect multiple values (AccumulatorTool)

<script setup lang="ts">
import { onMounted } from 'vue';
onMounted(() => {
// Configure mapper via hooks if needed
// The mapper has its own workspace store
});
function handleSave(mapperData: unknown) {
console.log('Mapper saved:', mapperData);
// POST to backend
}
</script>
<template>
<mapper-component
with-actions
style="width: 100%; height: 600px;"
/>
</template>

When withActions is enabled, the toolbar shows:

  1. Plus Button (+): Opens menu to add mapper tools
    • Fix Input/Mapper: Auto-fix input/output structure
    • Accumulator: Add accumulator node
  2. Preview Button: Test the current mapping
  3. Save Mapper Button: Save the mapping configuration

interface MapperConfig {
nodes: Array<{
id: string;
type: 'source' | 'target' | 'collect_extractor' | 'list_iterator' | 'substring' | 'get_by_index' | 'accumulator';
position: { x: number; y: number };
data: Record<string, any>;
}>;
edges: Array<{
id: string;
source: string;
target: string;
sourceHandle?: string;
targetHandle?: string;
}>;
}

The Mapper is typically used within the Flow editor for configuring node data transformations:

// In Flow component, when a node has mapping needs
const { onMapperPreview, setMapperPreviewResult } = window.$useFlowCore;
// Register preview handler
onMapperPreview(async (flow, params) => {
// Execute mapper transformation
const result = await api.post('/mapper/preview', {
mapper: flow,
inputData: params,
});
// Show result in mapper
setMapperPreviewResult(result);
});

src/mapper/
├── mapper.ts # Custom element registration
├── components/
│ └── tools/
│ ├── InputTool.vue # Source data node
│ ├── OutputTool.vue # Target data node
│ ├── ObjectSourceTool.vue # Object extractor
│ ├── ListIteratorTool.vue # Array iterator
│ ├── SubstringTool.vue # String manipulation
│ ├── GetByIndexTool.vue # Array indexing
│ └── AccumulatorTool.vue # Value collection
├── hooks/
│ └── useMapper.ts
├── store/
│ └── workspace.ts # Mapper state management
├── types.d.ts
└── view/
└── Mapper.ce.vue # Main component

A typical mapper setup connects source fields to target fields:

┌─────────────┐ ┌─────────────┐ ┌─────────────┐
│ Source │ │ Transform │ │ Target │
│ │ │ (optional) │ │ │
│ • name │─────►│ │─────►│ • fullName │
│ • email │─────────────────────────►│ • emailAddr │
│ • items[] │─────►│ ListIterator│─────►│ • products │
└─────────────┘ └─────────────┘ └─────────────┘