@vyr/service-graph 0.0.33 → 0.0.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vyr/service-graph",
3
- "version": "0.0.33",
3
+ "version": "0.0.34",
4
4
  "description": "",
5
5
  "main": "./src/index.ts",
6
6
  "author": "",
@@ -1,9 +1,10 @@
1
- import { Generate, Listener } from '@vyr/engine'
2
1
  import { Cell, CellView, Edge, Graph, Shape } from '@antv/x6'
3
2
  import { Selection } from '@antv/x6-plugin-selection'
4
3
  import { Stencil } from '@antv/x6-plugin-stencil'
5
4
  import { History } from '@antv/x6-plugin-history'
6
5
  import { Options } from '@antv/x6/lib/graph/options'
6
+ import { Listener } from '@vyr/engine'
7
+ import { runtime } from '@vyr/runtime'
7
8
  import { Unit } from './common/Unit'
8
9
  import { language } from './locale'
9
10
 
@@ -191,7 +192,7 @@ class GraphDrawer extends Listener<GraphObserver> {
191
192
  this.selectEdge = ''
192
193
  }
193
194
 
194
- private _delaySelect = Generate.delayExecute(() => {
195
+ private _delaySelect = runtime.delayExecute(() => {
195
196
  const cells = this.selection.getSelectedCells()
196
197
  this.trigger('select', cells)
197
198
  })
@@ -199,10 +200,10 @@ class GraphDrawer extends Listener<GraphObserver> {
199
200
  if (this.needTriggerChange === false) return
200
201
  this._delayChange()
201
202
  }
202
- private _delayChange = Generate.delayExecute(() => {
203
+ private _delayChange = runtime.delayExecute(() => {
203
204
  this.trigger('change', {})
204
205
  })
205
- private _resize = Generate.delayExecute(() => {
206
+ private _resize = runtime.delayExecute(() => {
206
207
  if (!this.container) return
207
208
  const rect = this.container.getBoundingClientRect()
208
209
  this.graph.resize(rect.width, rect.height)
@@ -1,23 +1,23 @@
1
1
  import { reactive, AsyncComponentLoader, defineAsyncComponent } from 'vue'
2
2
  import { Service } from "@vyr/service"
3
- import { DeserializationObject, InteractionInputCollection, ObjectUtils, InteractionDescriptor, InteractionNode, InteractionMapper } from '@vyr/engine'
3
+ import { DeserializationObject, InteractionNodeInputCollection, ObjectUtils, Interaction, InteractionNode, InteractionMapper, InteractionExecuteNodeSchame, InteractionConditionNodeSchame } from '@vyr/engine'
4
4
  import { Unit } from './common/Unit'
5
- import { BranchUnit, ConditionUnit, ExecuteUnit, InteractionUnit } from './common/InteractionUnit'
5
+ import { ConditionUnit, ExecuteUnit, InteractionUnit } from './common/InteractionUnit'
6
6
  import { GraphDrawer } from './GraphDrawer'
7
7
 
8
- class GraphState {
8
+ class GraphStore {
9
9
  width = '60%'
10
10
  height = '60%'
11
11
  visible = false
12
12
  descriptor = ''
13
13
  event = ''
14
- inputs: InteractionInputCollection = {}
15
- interaction: DeserializationObject<InteractionDescriptor> | null = null
14
+ nodes: InteractionNodeInputCollection = {}
15
+ interaction: DeserializationObject<Interaction> | null = null
16
16
 
17
17
  reset() {
18
18
  this.descriptor = ''
19
19
  this.event = ''
20
- this.inputs = {}
20
+ this.nodes = {}
21
21
  this.interaction = null
22
22
  }
23
23
  }
@@ -30,24 +30,21 @@ class GraphService extends Service {
30
30
  this._drawer = new GraphDrawer()
31
31
  this._drawer.stencil.load([
32
32
  new ExecuteUnit({ drawer: this._drawer, label: 'Execute' },),
33
- new BranchUnit({ drawer: this._drawer, label: 'Branch' }),
34
33
  new ConditionUnit({ drawer: this._drawer, label: 'Condition' }),
35
34
  ], 'inspector')
36
35
  }
37
36
  return this._drawer
38
37
  }
39
- readonly state = reactive(new GraphState())
40
- interaction: DeserializationObject<InteractionDescriptor> | null = null
38
+ readonly store = reactive(new GraphStore())
39
+ interaction: DeserializationObject<Interaction> | null = null
41
40
 
42
41
  private _doNodes(nodes: InteractionNode[]) {
43
42
  for (const node of nodes) {
44
- if (node.interaction === 'Execute') {
43
+ if (node.type === 'Execute') {
45
44
  const cell = new ExecuteUnit({ ...node, drawer: this.drawer })
46
45
  this.drawer.graph.addCell(cell)
47
- } else if (node.interaction === 'Condition') {
46
+ } else if (node.type === 'Condition') {
48
47
  this.drawer.graph.addCell(new ConditionUnit({ ...node, drawer: this.drawer }))
49
- } else if (node.interaction === 'Branch') {
50
- this.drawer.graph.addCell(new BranchUnit({ ...node, drawer: this.drawer }))
51
48
  }
52
49
  }
53
50
 
@@ -88,7 +85,7 @@ class GraphService extends Service {
88
85
  }
89
86
  }
90
87
 
91
- render(interaction: DeserializationObject<InteractionDescriptor>) {
88
+ render(interaction: DeserializationObject<Interaction>) {
92
89
  this.interaction = interaction
93
90
 
94
91
  this.drawer.needTriggerChange = false
@@ -97,7 +94,7 @@ class GraphService extends Service {
97
94
  this.drawer.needTriggerChange = true
98
95
  }
99
96
 
100
- update(curInteraction: DeserializationObject<InteractionDescriptor>) {
97
+ update(curInteraction: DeserializationObject<Interaction>) {
101
98
  if (this.interaction === null) return
102
99
 
103
100
  this.drawer.needTriggerChange = false
@@ -134,19 +131,20 @@ class GraphService extends Service {
134
131
  }
135
132
 
136
133
  build() {
137
- const interaction = new InteractionDescriptor()
134
+ const interaction = new Interaction()
138
135
  const cells = this.drawer.graph.getCells()
139
136
 
140
137
  for (const cell of cells) {
141
138
  if (cell instanceof InteractionUnit) {
142
- const node = {
139
+ const NodeSchame = cell.vMeta.type === 'Execute' ? InteractionExecuteNodeSchame : InteractionConditionNodeSchame
140
+ const node = NodeSchame.parse({
143
141
  id: cell.id,
144
142
  label: cell.vMeta.label ?? '',
145
- url: cell.vMeta.url,
146
- interaction: cell.vMeta.interaction,
143
+ script: cell.vMeta.script,
144
+ type: cell.vMeta.type,
147
145
  input: cell.vMeta.input,
148
146
  position: cell.getPosition(),
149
- }
147
+ })
150
148
  interaction.nodes.push(node)
151
149
  } else if (cell.isEdge()) {
152
150
  const mapper = this.drawer.getMapper(cell)
@@ -1,10 +1,10 @@
1
1
  import { Cell } from "@antv/x6";
2
- import { Descriptor } from "@vyr/engine";
2
+ import { ConditionScriptable, Descriptor } from "@vyr/engine";
3
3
  import { Unit, UnitMeta, UnitPartial, } from "./Unit";
4
4
 
5
5
  interface InteractionUnitMeta extends UnitMeta {
6
- url: string
7
- interaction: string
6
+ type: string
7
+ script: string
8
8
  input: { [param: string]: any }
9
9
  }
10
10
 
@@ -19,23 +19,9 @@ class InteractionUnit extends Unit {
19
19
 
20
20
  class ExecuteUnit extends InteractionUnit {
21
21
  constructor(vMeta: UnitPartial<InteractionUnitMeta>) {
22
- super({ ...vMeta, maxInCount: Infinity, icon: 'graphfont graph-execute' })
23
- this.vMeta.interaction = 'Execute'
24
- this.vMeta.url = vMeta.url ?? ''
25
- }
26
-
27
- isConnection(e: Element, source: Cell) {
28
- if (Unit.instanceOf(source, [ExecuteUnit, ConditionUnit]) === false) return false
29
- return super.isConnection(e, source)
30
- }
31
- }
32
-
33
- class BranchUnit extends InteractionUnit {
34
-
35
- constructor(vMeta: UnitPartial<InteractionUnitMeta>) {
36
- super({ ...vMeta, maxOutCount: Infinity, icon: 'graphfont graph-branch' })
37
- this.vMeta.interaction = 'Branch'
38
- this.vMeta.url = vMeta.url ?? ''
22
+ super({ ...vMeta, maxInCount: Infinity, maxOutCount: Infinity, icon: 'graphfont graph-execute' })
23
+ this.vMeta.type = 'Execute'
24
+ this.vMeta.script = vMeta.script ?? ''
39
25
  }
40
26
 
41
27
  isConnection(e: Element, source: Cell) {
@@ -46,13 +32,14 @@ class BranchUnit extends InteractionUnit {
46
32
 
47
33
  class ConditionUnit extends InteractionUnit {
48
34
  constructor(vMeta: UnitPartial<InteractionUnitMeta>) {
49
- super({ input: { value: { type: 'string', value: '' } }, ...vMeta, icon: 'graphfont graph-condition' })
50
- this.vMeta.interaction = 'Condition'
51
- this.vMeta.url = vMeta.url ?? ''
35
+ super({ ...vMeta, maxInCount: Infinity, icon: 'graphfont graph-condition' })
36
+ this.vMeta.type = 'Condition'
37
+ this.vMeta.script = vMeta.script ?? 'condition'
38
+ this.vMeta.input = vMeta.input ?? ConditionScriptable.inputSchame.parse({})
52
39
  }
53
40
 
54
41
  isConnection(e: Element, source: Cell) {
55
- if (Unit.instanceOf(source, [BranchUnit]) === false) return false
42
+ if (Unit.instanceOf(source, [ExecuteUnit, ConditionUnit]) === false) return false
56
43
  return super.isConnection(e, source)
57
44
  }
58
45
  }
@@ -60,6 +47,5 @@ class ConditionUnit extends InteractionUnit {
60
47
  export {
61
48
  InteractionUnit,
62
49
  ExecuteUnit,
63
- BranchUnit,
64
50
  ConditionUnit,
65
51
  }