| name | ordo-editor-component |
| description | Ordo visual editor component development guide. Includes Vue/React component usage, flow diagram integration, WASM calls, rule import/export. Use for frontend integration of rule editor, custom editor UI, extending editor functionality. |
Ordo Editor Component Development
Installation
npm install @ordo-engine/editor-vue
npm install @ordo-engine/editor-react
npm install @ordo-engine/editor-core
npm install @ordo-engine/wasm
Vue 3 Integration
Basic Usage
<script setup lang="ts">
import { ref } from 'vue'
import { OrdoEditor, type RuleSet } from '@ordo-engine/editor-vue'
import '@ordo-engine/editor-vue/style.css'
const ruleset = ref<RuleSet>({
config: {
name: 'my-rule',
version: '1.0.0',
entry_step: 'start'
},
steps: {}
})
const handleChange = (newRuleset: RuleSet) => {
ruleset.value = newRuleset
}
</script>
<template>
<OrdoEditor
v-model="ruleset"
@change="handleChange"
:readonly="false"
/>
</template>
Flow Editor
<script setup lang="ts">
import { FlowEditor } from '@ordo-engine/editor-vue'
const onNodeClick = (nodeId: string) => {
console.log('Clicked:', nodeId)
}
</script>
<template>
<FlowEditor
v-model="ruleset"
@node-click="onNodeClick"
:show-minimap="true"
:show-controls="true"
/>
</template>
Form Editor
<script setup lang="ts">
import { FormEditor, StepEditor } from '@ordo-engine/editor-vue'
</script>
<template>
<FormEditor v-model="ruleset" />
<!-- Or standalone step editor -->
<StepEditor
v-model="currentStep"
:step-id="selectedStepId"
@update="handleStepUpdate"
/>
</template>
Execution Panel
<script setup lang="ts">
import { ExecutionPanel } from '@ordo-engine/editor-vue'
const input = ref({ user: { vip: true } })
</script>
<template>
<ExecutionPanel
:ruleset="ruleset"
v-model:input="input"
:show-trace="true"
/>
</template>
React Integration
Basic Usage
import { useState } from 'react'
import { OrdoEditor, RuleSet } from '@ordo-engine/editor-react'
import '@ordo-engine/editor-react/style.css'
function App() {
const [ruleset, setRuleset] = useState<RuleSet>({
config: {
name: 'my-rule',
version: '1.0.0',
entry_step: 'start'
},
steps: {}
})
return (
<OrdoEditor
value={ruleset}
onChange={setRuleset}
readonly={false}
/>
)
}
Core Library API
Rule Operations
import {
createRuleSet,
addStep,
removeStep,
validateRuleSet,
serializeRuleSet,
deserializeRuleSet
} from '@ordo-engine/editor-core'
const ruleset = createRuleSet('my-rule', 'start')
addStep(ruleset, {
id: 'start',
name: 'Check User',
type: 'decision',
branches: [
{ condition: 'user.vip == true', next_step: 'vip' }
],
default_next: 'normal'
})
const errors = validateRuleSet(ruleset)
const json = serializeRuleSet(ruleset, 'json')
const yaml = serializeRuleSet(ruleset, 'yaml')
WASM Execution
import { OrdoEngine } from '@ordo-engine/wasm'
const engine = await OrdoEngine.init()
engine.loadRuleSet(ruleset)
const result = engine.execute('my-rule', {
user: { vip: true, balance: 1000 }
})
console.log(result.code)
console.log(result.outputs)
console.log(result.trace)
Expression Evaluation
import { OrdoEngine } from '@ordo-engine/wasm'
const engine = await OrdoEngine.init()
const result = engine.eval('age >= 18 && status == "active"', {
age: 25,
status: 'active'
})
File Import/Export
Export .ordo File
import { exportOrdo, exportJSON, exportYAML } from '@ordo-engine/editor-core'
const ordoBlob = await exportOrdo(ruleset)
downloadFile(ordoBlob, `${ruleset.config.name}.ordo`)
const jsonStr = exportJSON(ruleset)
const yamlStr = exportYAML(ruleset)
Import File
import { importOrdo, importJSON, importYAML } from '@ordo-engine/editor-core'
const file = await selectFile()
if (file.name.endsWith('.ordo')) {
const ruleset = await importOrdo(file)
} else if (file.name.endsWith('.json')) {
const ruleset = await importJSON(await file.text())
} else if (file.name.endsWith('.yaml') || file.name.endsWith('.yml')) {
const ruleset = await importYAML(await file.text())
}
Component Structure
packages/
├── core/ # @ordo-engine/editor-core
│ ├── src/
│ │ ├── engine/ # Rule engine adapter
│ │ ├── serialization/ # Serialization utilities
│ │ └── validation/ # Validators
│ └── package.json
│
├── vue/ # @ordo-engine/editor-vue
│ ├── src/components/
│ │ ├── flow/ # Flow diagram components
│ │ ├── form/ # Form components
│ │ ├── step/ # Step editors
│ │ ├── execution/ # Execution panel
│ │ └── debug/ # Debug tools
│ └── package.json
│
├── react/ # @ordo-engine/editor-react
│ └── src/
│
└── wasm/ # @ordo-engine/wasm
├── index.js # WASM wrapper
└── index.d.ts # Type definitions
Custom Theming
:root {
--ordo-primary-color: #1890ff;
--ordo-success-color: #52c41a;
--ordo-warning-color: #faad14;
--ordo-error-color: #ff4d4f;
--ordo-border-radius: 4px;
--ordo-font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto;
}
Internationalization
import { setLocale } from '@ordo-engine/editor-vue'
setLocale('zh-CN')
setLocale('en-US')
Local Development
cd ordo-editor
pnpm install
pnpm dev
pnpm build
pnpm test
Key Files
ordo-editor/packages/core/ - Core library
ordo-editor/packages/vue/src/components/ - Vue components
ordo-editor/packages/react/src/ - React components
ordo-editor/packages/wasm/ - WASM bindings
ordo-editor/apps/playground/ - Demo application
crates/ordo-wasm/ - WASM source code