techtools
Головна / proto / flow-old / src / components / NodeInspector.vue

NodeInspector.vue

Vue · 99 рядків

1<script setup>
2import { computed, ref, watch } from 'vue'
3import { expandSchema, schemaPaths } from '../dataFlow.js'
4import { validateCondition } from '../../shared/condition.ts'
5import { validateApiRequest } from '../../shared/api-request.ts'
6import { deriveMappingSchema, validateMapping } from '../../shared/mapping.ts'
7import { handlerContextModelId, validateTaskConfig } from '../../shared/task.ts'
8import { boardStages } from '../../shared/stages.ts'
9import { validateFireEventConfig } from '../../shared/fire-event.ts'
10import { blockHelp } from '../blockHelp.js'
11import BlockHelpPanel from './BlockHelpPanel.vue'
12import WorkflowProperties from './WorkflowProperties.vue'
13import DecisionTable from './DecisionTable.vue'
14import ScreenProperties from './ScreenProperties.vue'
15import { decisionPorts } from '../../shared/decision.ts'
16import { validateScreen } from '../../shared/screen.ts'
17const props=defineProps({node:Object,board:{type:Object,default:null},models:{type:Array,default:()=>[]},workflows:{type:Array,default:()=>[]},dataSchema:{type:Object,default:()=>({})},inputSchema:{type:Object,default:()=>({})},modelSchema:{type:Object,default:()=>({})},eventSchema:{type:Object,default:()=>({})}})
18const emit=defineEmits(['update','delete'])
19const tab=ref('main'),sourceDraft=ref(''),sourceErrors=ref([]),conditionsText=ref(''),apiMappingDraft=ref('{}'),apiMappingError=ref(''),mappingDraft=ref('{}'),mappingError=ref(''),taskPayloadDraft=ref('{}'),taskPayloadError=ref(''),routesDraft=ref('{}'),routesError=ref(''),showConditionHelp=ref(false),showBlockHelp=ref(false)
20const isEvent=computed(()=>props.node.type==='EVENT')
21const paths=computed(()=>schemaPaths(props.dataSchema))
22const inputPaths=computed(()=>schemaPaths(props.inputSchema,'input'))
23const modelPaths=computed(()=>schemaPaths(props.modelSchema,'model'))
24const taskSchema=computed(()=>expandSchema(props.models.find(model=>model.id==='system-task')?.schema||{},props.models))
25const conditionSchema=computed(()=>({data:props.dataSchema,input:props.inputSchema,model:props.modelSchema,event:props.eventSchema,task:taskSchema.value}))
26const mappingScopes=computed(()=>({task:taskSchema.value,event:props.eventSchema}))
27// обробник задачі — етап цього борду (R-30.12) або окремий workflow
28const boardStageList=computed(()=>boardStages(props.board))
29const handlerContext=computed(()=>{if(props.node.type!=='TASK')return null;const model=props.models.find(item=>item.id===handlerContextModelId(props.board,props.workflows,props.node.config));return model?expandSchema(model.schema,props.models):null})
30const handlerDefaults=computed(()=>props.node.type==='TASK'?props.models.find(item=>item.id===handlerContextModelId(props.board,props.workflows,props.node.config))?.defaults||null:null)
31function setHandlerStage(id){props.node.config||={};if(id){props.node.config.handlerStageId=id;props.node.config.handlerWorkflowId=''}else delete props.node.config.handlerStageId;changed()}
32const mappingPreview=computed(()=>deriveMappingSchema(props.node.config?.mapping||{$copy:'data'},props.inputSchema,mappingScopes.value))
33const currentHelp=computed(()=>blockHelp(props.node.type))
34const propertyHelp=computed(()=>({EVENT:'START creates a new flow. TASK routes one active entity task into its pinned handler workflow without waiting. Conditions can use data.*, task.*, and event.*.',CONDITION:'Routes inherited data through the first matching JSON port. Empty string is fallback; $error handles evaluation errors.',DELAY:'Waits for the configured number of seconds, then passes the inherited data unchanged through its single output.',API_REQUEST:'URL templates and shared mappings accept data.*, task.*, and event.*. Project arrays with { $map: data.parts, value: item.id }. Success adds the response model; error adds a standard error object.',MAPPING:'$copy: data keeps every input field at the output root. Use $data for the whole input, or project arrays with { $map: data.parts, value: { id: item.id } }. Remove $copy to create a new structure.',TASK:'Creates a task and immediately continues. Payload mapping supports the same $map collection projection as Mapping and API Request. Single mode adds data.task and exposes the task output. Batch itemsPath adds data.tasks[] through next and does not fan out task executions.',TASK_UPDATE:'Updates the current routed task or a task selected by path. It can change status, state, progress, and completion.',CLIENT_RESPONSE:'Terminates the execution and maps data.*, task.*, or event.* into the synchronous HTTP response.'}[props.node.type]||'Edit this block configuration. Changes are validated and synchronized with Source.'))
35function modelId(){if(['CONDITION','DECISION','SCREEN','DELAY','MAPPING','FIRE_EVENT','TASK','TASK_UPDATE','WORKFLOW','WORKFLOW_OUTPUT','CLIENT_RESPONSE'].includes(props.node.type))return'';if(isEvent.value||props.node.type==='WORKFLOW_INPUT')return props.node.config?.modelId||'';if(props.node.type==='API_REQUEST')return props.node.config?.modelId||props.node.config?.responseModelId||'';return props.node.config?.outputModels?.[props.node.outputs?.[0]?.id]||''}
36function setModelId(id,synchronize=true){props.node.config||={};if(isEvent.value||['API_REQUEST','WORKFLOW_INPUT','WORKFLOW_OUTPUT'].includes(props.node.type)){props.node.config.modelId=id;if(props.node.type==='API_REQUEST')delete props.node.config.responseModelId}else{props.node.config.outputModels||={};props.node.config.outputModels[props.node.outputs?.[0]?.id||'next']=id}if(synchronize)changed()}
37const jsonClone=value=>JSON.parse(JSON.stringify(value))
38function sourceObject(){const cfg=jsonClone(props.node.config||{}),id=modelId();delete cfg.modelId;delete cfg.outputModelId;delete cfg.responseModelId;delete cfg.outputModels;if(props.node.type==='CONDITION'){const ports=cfg.routes||{};delete cfg.routes;return{type:'condition',nodeId:props.node.id,title:props.node.name,ports,...cfg}}if(props.node.type==='TASK'){const taskTitle=cfg.title;delete cfg.title;return{type:'task',nodeId:props.node.id,title:props.node.name,taskTitle,...cfg}}if(['DECISION','SCREEN','DELAY','MAPPING','FIRE_EVENT','TASK_UPDATE','WORKFLOW_OUTPUT','CLIENT_RESPONSE'].includes(props.node.type))return{type:props.node.type.toLowerCase(),nodeId:props.node.id,title:props.node.name,...cfg};return{type:props.node.type.toLowerCase(),nodeId:props.node.id,title:props.node.name,modelId:id||null,...cfg}}
39function sync(){showBlockHelp.value=false;conditionsText.value=(props.node.config?.conditions||[]).join('\n');apiMappingDraft.value=JSON.stringify(props.node.config?.requestMapping||{},null,2);apiMappingError.value='';mappingDraft.value=JSON.stringify(props.node.config?.mapping||{$copy:'data'},null,2);mappingError.value='';taskPayloadDraft.value=JSON.stringify(props.node.config?.payloadMapping||{$copy:'data'},null,2);taskPayloadError.value='';routesDraft.value=JSON.stringify(props.node.config?.routes||{},null,2);routesError.value='';sourceDraft.value=JSON.stringify(sourceObject(),null,2);sourceErrors.value=[]}
40watch(()=>props.node.id,sync,{immediate:true})
41function changed(){sourceDraft.value=JSON.stringify(sourceObject(),null,2);sourceErrors.value=[];emit('update')}
42function changeConditions(){props.node.config.conditions=conditionsText.value.split('\n').map(value=>value.trim()).filter(Boolean);changed()}
43const conditionErrors=computed(()=>{const result=[];for(const condition of props.node.config?.conditions||[])for(const error of validateCondition(condition,conditionSchema.value).errors)result.push(error);return result})
44function validateRoutes(routes){const errors=[];if(!routes||typeof routes!=='object'||Array.isArray(routes))return['ports must be a JSON object'];const entries=Object.entries(routes);if(!entries.length)errors.push('At least one output port is required');if(entries.some(([name,value])=>!name.trim()||typeof value!=='string'))errors.push('Every port needs a name and string condition');if(entries.filter(([,value])=>value==='').length>1)errors.push('Only one empty fallback condition is allowed');if(entries.filter(([,value])=>value==='$error').length>1)errors.push('Only one $error route is allowed');for(const[name,expression]of entries)if(expression&&expression!=='$error')for(const error of validateCondition(expression,props.inputSchema).errors)errors.push(`${name}: ${error}`);return errors}
45function changeRoutes(){let value;try{value=JSON.parse(routesDraft.value)}catch(error){routesError.value=error.message;return}if(!value||typeof value!=='object'||Array.isArray(value)){routesError.value='ports must be a JSON object';return}const errors=validateRoutes(value);props.node.config={...(props.node.config||{}),routes:value};props.node.outputs=Object.keys(value).map(id=>({id,name:id}));routesError.value=errors.join('\n');changed()}
46function formatRoutes(){try{routesDraft.value=JSON.stringify(JSON.parse(routesDraft.value),null,2);changeRoutes()}catch(error){routesError.value=error.message}}
47function addRoutePath(path){let routes;try{routes=JSON.parse(routesDraft.value)}catch{return}const key=Object.keys(routes).find(name=>routes[name]&&routes[name]!=='$error')||Object.keys(routes).find(name=>routes[name]!=='$error');if(!key)return;routes[key]=(routes[key]?routes[key]+' ':'')+`${path} == `;routesDraft.value=JSON.stringify(routes,null,2);changeRoutes()}
48const apiErrors=computed(()=>props.node.type==='API_REQUEST'?[...validateApiRequest(props.node.config,props.inputSchema,mappingScopes.value).errors,...(apiMappingError.value?[apiMappingError.value]:[])]:[])
49const fireEventErrors=computed(()=>props.node.type==='FIRE_EVENT'?[...validateFireEventConfig(props.node.config,props.inputSchema,mappingScopes.value).errors,...(taskPayloadError.value?[taskPayloadError.value]:[])]:[])
50function changeApiMapping(){try{const value=JSON.parse(apiMappingDraft.value),validation=validateMapping(value,props.inputSchema,mappingScopes.value);if(!validation.valid)throw new Error(validation.errors.join('\n'));props.node.config.requestMapping=value;apiMappingError.value='';sourceDraft.value=JSON.stringify(sourceObject(),null,2);sourceErrors.value=[];emit('update')}catch(error){apiMappingError.value=error.message}}
51function formatApiMapping(){try{apiMappingDraft.value=JSON.stringify(JSON.parse(apiMappingDraft.value),null,2);changeApiMapping()}catch(error){apiMappingError.value=error.message}}
52function changeMapping(){try{const value=JSON.parse(mappingDraft.value),validation=validateMapping(value,props.inputSchema,mappingScopes.value);if(!validation.valid)throw new Error(validation.errors.join('\n'));props.node.config.mapping=value;mappingError.value='';changed()}catch(error){mappingError.value=error.message}}
53function formatMapping(){try{mappingDraft.value=JSON.stringify(JSON.parse(mappingDraft.value),null,2);changeMapping()}catch(error){mappingError.value=error.message}}
54function changeTaskPayload(){try{const value=JSON.parse(taskPayloadDraft.value),validation=validateMapping(value,props.inputSchema,mappingScopes.value);if(!validation.valid)throw new Error(validation.errors.join('\n'));props.node.config.payloadMapping=value;taskPayloadError.value='';changed()}catch(error){taskPayloadError.value=error.message}}
55function validateSource(value){const errors=[];if(!value||typeof value!=='object'||Array.isArray(value))return['Source must be a JSON object'];if(value.type!==props.node.type.toLowerCase())errors.push(`type must remain "${props.node.type.toLowerCase()}"`);if(value.nodeId!==props.node.id)errors.push('nodeId is immutable');if(typeof value.title!=='string'||!value.title.trim())errors.push('title is required');if(props.node.type==='CONDITION')errors.push(...validateRoutes(value.ports));if(['MAPPING','CLIENT_RESPONSE'].includes(props.node.type))errors.push(...validateMapping(value.mapping,props.inputSchema,mappingScopes.value).errors);if(props.node.type==='SCREEN')errors.push(...validateScreen(value,conditionSchema.value));if(props.node.type==='CLIENT_RESPONSE'&&(!Number.isInteger(Number(value.status))||Number(value.status)<100||Number(value.status)>599))errors.push('status must be an integer from 100 to 599');if(props.node.type==='DELAY'){if(!Number.isFinite(Number(value.seconds))||Number(value.seconds)<0||Number(value.seconds)>86400)errors.push('seconds must be between 0 and 86400');if(['modelId','outputModelId','responseModelId','outputModels'].some(key=>key in value))errors.push('Delay does not support a data model')}if(isEvent.value&&!value.modelId)errors.push('modelId is required');if(value.modelId&&!props.models.some(model=>model.id===value.modelId))errors.push('modelId does not reference an existing model');if(value.errorModelId&&!props.models.some(model=>model.id===value.errorModelId))errors.push('errorModelId does not reference an existing model');if(isEvent.value&&(!value.event||typeof value.event!=='string'))errors.push('event is required');if(value.conditions!==undefined&&(!Array.isArray(value.conditions)||value.conditions.some(item=>typeof item!=='string')))errors.push('conditions must be an array of strings');for(const condition of Array.isArray(value.conditions)?value.conditions:[])for(const error of validateCondition(condition,conditionSchema.value).errors)errors.push(error);if(props.node.type==='API_REQUEST')errors.push(...validateApiRequest(value,props.inputSchema,mappingScopes.value).errors);if(props.node.type==='FIRE_EVENT')errors.push(...validateFireEventConfig(value,props.inputSchema,mappingScopes.value).errors);if(['TASK','TASK_UPDATE'].includes(props.node.type))errors.push(...validateTaskConfig(props.node.type==='TASK'?{...value,title:value.taskTitle}:value,props.inputSchema,props.node.type==='TASK_UPDATE',mappingScopes.value,handlerContext.value,handlerDefaults.value).errors);return errors}
56function editSource(){let value;try{value=JSON.parse(sourceDraft.value)}catch(error){sourceErrors.value=[error.message];return}const errors=validateSource(value);sourceErrors.value=errors;if(errors.length)return;const{type,nodeId,title,modelId,ports,...config}=value;props.node.name=title;if(props.node.type==='TASK'){config.title=config.taskTitle;delete config.taskTitle}props.node.config=props.node.type==='CONDITION'?{...config,routes:ports}:config;if(props.node.type==='CONDITION'){props.node.outputs=Object.keys(ports).map(id=>({id,name:id}));routesDraft.value=JSON.stringify(ports,null,2)}else if(props.node.type==='DECISION')props.node.outputs=decisionPorts(props.node.config).map(id=>({id,name:id}));else if(!['SCREEN','DELAY','MAPPING','FIRE_EVENT','TASK','TASK_UPDATE','WORKFLOW_OUTPUT'].includes(props.node.type))setModelId(modelId||'',false);conditionsText.value=(props.node.config.conditions||[]).join('\n');apiMappingDraft.value=JSON.stringify(props.node.config.requestMapping||{},null,2);mappingDraft.value=JSON.stringify(props.node.config.mapping||{$copy:'data'},null,2);taskPayloadDraft.value=JSON.stringify(props.node.config.payloadMapping||{$copy:'data'},null,2);emit('update')}
57function formatSource(){try{sourceDraft.value=JSON.stringify(JSON.parse(sourceDraft.value),null,2);editSource()}catch(error){sourceErrors.value=[error.message]}}
58function indent(e){if(e.key!=='Tab')return;e.preventDefault();const el=e.target,start=el.selectionStart,end=el.selectionEnd;sourceDraft.value=sourceDraft.value.slice(0,start)+'  '+sourceDraft.value.slice(end);requestAnimationFrame(()=>el.setSelectionRange(start+2,start+2))}
59function indentApi(e){if(e.key!=='Tab')return;e.preventDefault();const el=e.target,start=el.selectionStart,end=el.selectionEnd;apiMappingDraft.value=apiMappingDraft.value.slice(0,start)+'  '+apiMappingDraft.value.slice(end);requestAnimationFrame(()=>el.setSelectionRange(start+2,start+2))}
60function addPath(path){conditionsText.value+=(conditionsText.value?'\n':'')+`${path} == `;changeConditions()}
61</script>
62<template><section :class="['node-inspector','type-'+node.type,'tab-'+tab]"><nav class="node-tabs"><button v-for="name in ['main','properties','source']" :key="name" :class="{active:tab===name}" @click="tab=name">{{name}}</button></nav>
63  <div v-if="tab==='main'" class="node-tab-body"><div class="eyebrow">{{node.type}}</div><label>Node ID<input :value="node.id" disabled></label><label>Title<input v-model="node.name" :disabled="node.type==='WORKFLOW'" @input="changed"></label><label v-if="!['CONDITION','DECISION','SCREEN','DELAY','MAPPING','FIRE_EVENT','TASK','TASK_UPDATE','WORKFLOW','WORKFLOW_OUTPUT','CLIENT_RESPONSE'].includes(node.type)">Model<select :value="modelId()" @change="setModelId($event.target.value)"><option value="">No model</option><option v-for="model in models" :key="model.id" :value="model.id">{{model.name}}</option></select></label><p v-else class="model-note">{{node.type==='FIRE_EVENT'?'Accepts any input data, fires a mapped FLOW event, and passes the input unchanged.':node.type==='WORKFLOW_OUTPUT'?'Passes its input data unchanged; the parent output contract is derived automatically.':node.type==='WORKFLOW'?'Title, input, and output contracts are inherited from the selected child workflow.':node.type==='MAPPING'?'Mapping JSON alone defines the output structure.':['TASK','TASK_UPDATE'].includes(node.type)?'Uses the read-only system Task model.':node.type==='DECISION'?'Decision table writes the values of the first matching rule into data.<result path>; its structure is derived from the columns.':node.type==='SCREEN'?'Terminal TSD screen response; no output model or port.':node.type==='DELAY'?'Delay passes inherited data unchanged and does not define a model.':node.type==='CLIENT_RESPONSE'?'Terminal HTTP response mapping; no output model or port.':'Condition uses inherited input data and does not define a model.'}}</p></div>
64  <div v-else-if="tab==='properties'" class="node-tab-body">
65    <button v-if="currentHelp" class="block-help-launch" @click="showBlockHelp=true"><span>?</span><b>Help &amp; examples</b></button><details v-else class="inspector-help"><summary>How this block works</summary><p>{{propertyHelp}}</p></details>
66    <template v-if="isEvent"><label>Event name <b class="required">required</b><input v-model="node.config.event" @input="changed" placeholder="ITEM_SCANNED"></label><label>Activation<select v-model="node.config.activation" @change="changed"><option value="START">START · creates flow</option><option value="TASK">TASK · routes active task</option></select></label><label>Conditions <small>one per line · AND</small><textarea class="code condition-editor" v-model="conditionsText" @input="changeConditions" placeholder="input.itemId == model.itemId"></textarea></label><div class="condition-scopes"><div class="field-paths"><b>INPUT PORT DATA</b><button v-for="field in inputPaths" :key="field.path" @click="addPath(field.path)"><code>{{field.path}}</code><span>{{field.type}}</span></button><small v-if="!inputPaths.length">No input fields</small></div><div class="field-paths"><b>BLOCK MODEL DATA</b><button v-for="field in modelPaths" :key="field.path" @click="addPath(field.path)"><code>{{field.path}}</code><span>{{field.type}}</span></button><small v-if="!modelPaths.length">No model fields</small></div></div><div v-if="conditionErrors.length" class="inspector-errors"><p v-for="error in conditionErrors" :key="error">{{error}}</p></div></template>
67    <template v-else-if="node.type==='CONDITION'"><div class="source-head"><span>Output ports and conditions</span><div><button class="help-button" title="How conditions work" @click="showConditionHelp=!showConditionHelp">?</button><button @click="formatRoutes">Format</button></div></div><div v-if="showConditionHelp" class="condition-help">Rules run from top to bottom. The first true expression selects its port. One empty string is the fallback. <code>$error</code> catches evaluation errors. Port names are synchronized with this JSON. Expressions support arithmetic and functions (<code>len</code>, <code>coalesce</code>, <code>now()</code>…) — see Help &amp; examples.</div><textarea class="code condition-routes-editor" v-model="routesDraft" @input="changeRoutes" spellcheck="false" placeholder='{&#10;  "Success": "data.sku == 1",&#10;  "Fail": "",&#10;  "Error": "$error"&#10;}'></textarea><div v-if="routesError" class="inspector-errors"><p v-for="error in routesError.split('\n')" :key="error">{{error}}</p></div><div class="field-paths"><b>AVAILABLE INPUT DATA</b><button v-for="field in paths" :key="field.path" @click="addRoutePath(field.path)"><code>{{field.path}}</code><span>{{field.type}}</span></button><small v-if="!paths.length">No input fields</small></div></template>
68    <template v-else-if="node.type==='FIRE_EVENT'">
69      <label>Event <b class="required">required</b><input v-model="node.config.event" @input="changed" placeholder="ITEM_SCANNED or data.event"></label>
70      <label>Entity type <b class="required">required</b><input v-model="node.config.entityType" @input="changed" placeholder="warehouse_item or data.entityType"></label>
71      <label>Entity ID <b class="required">required</b><input v-model="node.config.entityId" @input="changed" placeholder="data.entityId"></label>
72      <label>User ID <b class="required">required</b><input v-model.number="node.config.userId" @input="changed" placeholder="data.userId or 42"></label>
73      <div class="source-head"><span>Payload mapping</span><button @click="taskPayloadDraft=JSON.stringify(JSON.parse(taskPayloadDraft),null,2)">Format</button></div>
74      <textarea class="code mapping-editor" v-model="taskPayloadDraft" @input="changeTaskPayload" spellcheck="false" placeholder='{ "$copy": "data" }'></textarea>
75      <div v-if="fireEventErrors.length" class="inspector-errors"><p v-for="error in fireEventErrors" :key="error">{{error}}</p></div>
76      <div class="field-paths"><b>AVAILABLE INPUT DATA</b><button v-for="field in paths" :key="field.path"><code>{{field.path}}</code><span>{{field.type}}</span></button></div>
77    </template>
78    <template v-else-if="node.type==='API_REQUEST'"><label>Request method<select v-model="node.config.method" @change="changed"><option>GET</option><option>POST</option></select></label><label>URL <b class="required">required</b><input v-model="node.config.url" @input="changed" placeholder="/v1/{{data.item.sku}}/{{data.param2}}"></label><template v-if="node.config.method==='POST'"><div class="source-head"><span>POST request mapping</span><button @click="formatApiMapping">Format</button></div><textarea class="code api-mapping-editor" v-model="apiMappingDraft" @input="changeApiMapping" @keydown="indentApi" spellcheck="false" placeholder='{ "partIds": { "$map": "data.parts", "value": "item.id" } }'></textarea></template><div class="field-paths"><b>Available input data</b><button v-for="field in paths" :key="field.path"><code>{{field.path}}</code><span>{{field.type}}</span></button></div><div v-if="apiErrors.length" class="inspector-errors"><p v-for="error in apiErrors" :key="error">{{error}}</p></div></template>
79    <template v-else-if="['MAPPING','CLIENT_RESPONSE'].includes(node.type)"><label v-if="node.type==='CLIENT_RESPONSE'">HTTP status<input v-model.number="node.config.status" type="number" min="100" max="599" @input="changed"></label><div class="source-head"><span>{{node.type==='CLIENT_RESPONSE'?'Response JSON mapping':'Output JSON mapping'}}</span><button @click="formatMapping">Format</button></div><textarea class="code mapping-editor" v-model="mappingDraft" @input="changeMapping" spellcheck="false" placeholder='{&#10;  "$copy": "data",&#10;  "taskStatus": "task.status"&#10;}'></textarea><div v-if="mappingError" class="inspector-errors"><p v-for="error in mappingError.split('\n')" :key="error">{{error}}</p></div><div class="field-paths"><b>AVAILABLE INPUT DATA</b><button v-for="field in paths" :key="field.path"><code>{{field.path}}</code><span>{{field.type}}</span></button></div><div class="mapping-preview"><b>RESULT STRUCTURE</b><pre>{{JSON.stringify(mappingPreview,null,2)}}</pre></div></template>
80    <DecisionTable v-else-if="node.type==='DECISION'" :node="node" :schema="conditionSchema" @update="changed"/><ScreenProperties v-else-if="node.type==='SCREEN'" :node="node" :schema="conditionSchema" @update="changed"/><template v-else><label>Properties JSON<textarea class="code" :value="JSON.stringify(node.config||{},null,2)" @change="node.config=JSON.parse($event.target.value);changed()"></textarea></label></template>
81  </div>
82  <div v-else class="node-tab-body source-pane"><details class="inspector-help"><summary>Source reference</summary><p>Source is the complete synchronized block configuration. <code>type</code> and <code>nodeId</code> are immutable. Valid edits immediately update Main, Properties, ports and canvas; invalid JSON is kept as a draft. {{propertyHelp}}</p></details><div class="source-head"><span>Executable block source</span><button @click="formatSource">Format</button></div><textarea class="code source-editor" v-model="sourceDraft" @input="editSource" @keydown="indent" spellcheck="false"></textarea><div :class="['source-status',{valid:!sourceErrors.length}]">{{sourceErrors.length?'Invalid source':'Valid source · synchronized'}}</div><div v-if="sourceErrors.length" class="inspector-errors"><p v-for="error in sourceErrors" :key="error">{{error}}</p></div></div>
83  <div v-if="tab==='properties'&&node.type==='API_REQUEST'" class="api-error-model-section"><label>Error data model<select v-model="node.config.errorModelId" @change="changed"><option v-for="model in models" :key="model.id" :value="model.id">{{model.name}}{{model.system?' · SYSTEM':''}}</option></select></label><small>Default: ApiError · applied to the error output port</small></div>
84  <div v-if="tab==='properties'&&node.type==='DELAY'" class="api-error-model-section"><label>Delay in seconds<input v-model.number="node.config.seconds" type="number" min="0" max="86400" step="0.1" @input="changed"></label><small>Passes input data unchanged after the delay · range 0–86400 seconds</small></div>
85  <div v-if="tab==='properties'&&node.type==='TASK'" class="api-error-model-section task-properties"><label v-if="boardStageList.length">Етап-обробник (цей борд)<select :value="node.config.handlerStageId||''" @change="setHandlerStage($event.target.value)"><option value="">— окремий workflow —</option><option v-for="stage in boardStageList" :key="stage.id" :value="stage.id">{{stage.name}}</option></select></label><label v-if="!node.config.handlerStageId">Handler workflow<input v-model="node.config.handlerWorkflowId" @input="changed" placeholder="Workflow ID or exact name"></label><div v-if="handlerContext" class="mapping-preview"><b>HANDLER TASK CONTEXT · payloadMapping must provide</b><pre>{{JSON.stringify(handlerContext,null,2)}}</pre></div><label>Entity type<input v-model="node.config.entityType" @input="changed" placeholder="item"></label><label>Entity ID path<input v-model="node.config.entityIdPath" @input="changed" placeholder="data.entityId"></label><label>Initial state<input v-model="node.config.state" @input="changed" placeholder="created"></label><label>Batch items path<input v-model="node.config.itemsPath" @input="changed" placeholder="data.parts · optional"></label><label>Assign to<select v-model="node.config.assigneeType" @change="changed"><option value="group">Group</option><option value="person">Person</option></select></label><label>Group/person ID or data path<input v-model="node.config.assignee" @input="changed" placeholder="warehouse_worker or data.user.id"></label><label>Task type<input v-model="node.config.taskType" @input="changed" placeholder="UNLOAD"></label><label>Priority<input v-model="node.config.priority" @input="changed"></label><label>Task title<input v-model="node.config.title" @input="changed" placeholder="Put away {{data.item.sku}}"></label><label>Description<textarea v-model="node.config.description" @input="changed"></textarea></label><label>Initial progress<input v-model="node.config.progress" @input="changed"></label><label>Task payload mapping<textarea class="code" v-model="taskPayloadDraft" @input="changeTaskPayload" spellcheck="false"></textarea></label><div v-if="taskPayloadError" class="inspector-errors"><p>{{taskPayloadError}}</p></div><div class="field-paths"><b>AVAILABLE INPUT DATA</b><button v-for="field in paths" :key="field.path"><code>{{field.path}}</code><span>{{field.type}}</span></button></div></div>
86  <div v-if="tab==='properties'&&node.type==='TASK_UPDATE'" class="api-error-model-section task-properties"><label>Task ID data path<input v-model="node.config.taskIdPath" @input="changed" placeholder="data.task.id"></label><label>Status<input v-model="node.config.status" @input="changed" placeholder="in_progress"></label><label>State<input v-model="node.config.state" @input="changed" placeholder="moving"></label><label>Progress<input v-model="node.config.progress" @input="changed" placeholder="collecting"></label><label class="check-label"><input v-model="node.config.complete" type="checkbox" @change="changed"> Complete task</label><div class="field-paths"><b>AVAILABLE INPUT DATA</b><button v-for="field in paths" :key="field.path"><code>{{field.path}}</code><span>{{field.type}}</span></button></div></div>
87  <WorkflowProperties v-if="tab==='properties'&&node.type==='WORKFLOW'" class="api-error-model-section" :node="node" :workflows="workflows" :models="models" :input-schema="inputSchema" @update="changed"/>
88  <BlockHelpPanel v-if="showBlockHelp&&currentHelp" :help="currentHelp" @close="showBlockHelp=false"/>
89  <button class="danger inspector-delete" @click="emit('delete')">Delete node</button>
90</section></template>
91
92<style scoped>
93.block-help-launch{width:100%;display:flex;align-items:center;gap:9px;margin-bottom:12px;padding:9px 11px;border:1px solid #40515f;border-radius:6px;background:#1c2831;color:#dce7ee;cursor:pointer;text-align:left}
94.block-help-launch:hover{border-color:#72d7c7;color:#fff}
95.block-help-launch span{display:grid;place-items:center;width:20px;height:20px;border-radius:50%;background:#72d7c7;color:#112029;font-weight:900}
96.block-help-launch b{font-size:12px}
97</style>
98
99