提交 | 用户 | 时间
|
820397
|
1 |
import PaletteProvider from 'bpmn-js/lib/features/palette/PaletteProvider' |
H |
2 |
import { assign } from 'min-dash' |
|
3 |
|
|
4 |
export default function CustomPalette( |
|
5 |
palette, |
|
6 |
create, |
|
7 |
elementFactory, |
|
8 |
spaceTool, |
|
9 |
lassoTool, |
|
10 |
handTool, |
|
11 |
globalConnect, |
|
12 |
translate |
|
13 |
) { |
|
14 |
PaletteProvider.call( |
|
15 |
this, |
|
16 |
palette, |
|
17 |
create, |
|
18 |
elementFactory, |
|
19 |
spaceTool, |
|
20 |
lassoTool, |
|
21 |
handTool, |
|
22 |
globalConnect, |
|
23 |
translate, |
|
24 |
2000 |
|
25 |
) |
|
26 |
} |
|
27 |
|
|
28 |
const F = function () {} // 核心,利用空对象作为中介; |
|
29 |
F.prototype = PaletteProvider.prototype // 核心,将父类的原型赋值给空对象F; |
|
30 |
|
|
31 |
// 利用中介函数重写原型链方法 |
|
32 |
F.prototype.getPaletteEntries = function () { |
|
33 |
const actions = {}, |
|
34 |
create = this._create, |
|
35 |
elementFactory = this._elementFactory, |
|
36 |
spaceTool = this._spaceTool, |
|
37 |
lassoTool = this._lassoTool, |
|
38 |
handTool = this._handTool, |
|
39 |
globalConnect = this._globalConnect, |
|
40 |
translate = this._translate |
|
41 |
|
|
42 |
function createAction(type, group, className, title, options) { |
|
43 |
function createListener(event) { |
|
44 |
const shape = elementFactory.createShape(assign({ type: type }, options)) |
|
45 |
|
|
46 |
if (options) { |
|
47 |
shape.businessObject.di.isExpanded = options.isExpanded |
|
48 |
} |
|
49 |
|
|
50 |
create.start(event, shape) |
|
51 |
} |
|
52 |
|
|
53 |
const shortType = type.replace(/^bpmn:/, '') |
|
54 |
|
|
55 |
return { |
|
56 |
group: group, |
|
57 |
className: className, |
|
58 |
title: title || translate('Create {type}', { type: shortType }), |
|
59 |
action: { |
|
60 |
dragstart: createListener, |
|
61 |
click: createListener |
|
62 |
} |
|
63 |
} |
|
64 |
} |
|
65 |
|
|
66 |
function createSubprocess(event) { |
|
67 |
const subProcess = elementFactory.createShape({ |
|
68 |
type: 'bpmn:SubProcess', |
|
69 |
x: 0, |
|
70 |
y: 0, |
|
71 |
isExpanded: true |
|
72 |
}) |
|
73 |
|
|
74 |
const startEvent = elementFactory.createShape({ |
|
75 |
type: 'bpmn:StartEvent', |
|
76 |
x: 40, |
|
77 |
y: 82, |
|
78 |
parent: subProcess |
|
79 |
}) |
|
80 |
|
|
81 |
create.start(event, [subProcess, startEvent], { |
|
82 |
hints: { |
|
83 |
autoSelect: [startEvent] |
|
84 |
} |
|
85 |
}) |
|
86 |
} |
|
87 |
|
|
88 |
function createParticipant(event) { |
|
89 |
create.start(event, elementFactory.createParticipantShape()) |
|
90 |
} |
|
91 |
|
|
92 |
assign(actions, { |
|
93 |
'hand-tool': { |
|
94 |
group: 'tools', |
|
95 |
className: 'bpmn-icon-hand-tool', |
|
96 |
title: '激活抓手工具', |
|
97 |
// title: translate("Activate the hand tool"), |
|
98 |
action: { |
|
99 |
click: function (event) { |
|
100 |
handTool.activateHand(event) |
|
101 |
} |
|
102 |
} |
|
103 |
}, |
|
104 |
'lasso-tool': { |
|
105 |
group: 'tools', |
|
106 |
className: 'bpmn-icon-lasso-tool', |
|
107 |
title: translate('Activate the lasso tool'), |
|
108 |
action: { |
|
109 |
click: function (event) { |
|
110 |
lassoTool.activateSelection(event) |
|
111 |
} |
|
112 |
} |
|
113 |
}, |
|
114 |
'space-tool': { |
|
115 |
group: 'tools', |
|
116 |
className: 'bpmn-icon-space-tool', |
|
117 |
title: translate('Activate the create/remove space tool'), |
|
118 |
action: { |
|
119 |
click: function (event) { |
|
120 |
spaceTool.activateSelection(event) |
|
121 |
} |
|
122 |
} |
|
123 |
}, |
|
124 |
'global-connect-tool': { |
|
125 |
group: 'tools', |
|
126 |
className: 'bpmn-icon-connection-multi', |
|
127 |
title: translate('Activate the global connect tool'), |
|
128 |
action: { |
|
129 |
click: function (event) { |
|
130 |
globalConnect.toggle(event) |
|
131 |
} |
|
132 |
} |
|
133 |
}, |
|
134 |
'tool-separator': { |
|
135 |
group: 'tools', |
|
136 |
separator: true |
|
137 |
}, |
|
138 |
'create.start-event': createAction( |
|
139 |
'bpmn:StartEvent', |
|
140 |
'event', |
|
141 |
'bpmn-icon-start-event-none', |
|
142 |
translate('Create StartEvent') |
|
143 |
), |
|
144 |
'create.intermediate-event': createAction( |
|
145 |
'bpmn:IntermediateThrowEvent', |
|
146 |
'event', |
|
147 |
'bpmn-icon-intermediate-event-none', |
|
148 |
translate('Create Intermediate/Boundary Event') |
|
149 |
), |
|
150 |
'create.end-event': createAction( |
|
151 |
'bpmn:EndEvent', |
|
152 |
'event', |
|
153 |
'bpmn-icon-end-event-none', |
|
154 |
translate('Create EndEvent') |
|
155 |
), |
|
156 |
'create.exclusive-gateway': createAction( |
|
157 |
'bpmn:ExclusiveGateway', |
|
158 |
'gateway', |
|
159 |
'bpmn-icon-gateway-none', |
|
160 |
translate('Create Gateway') |
|
161 |
), |
|
162 |
'create.user-task': createAction( |
|
163 |
'bpmn:UserTask', |
|
164 |
'activity', |
|
165 |
'bpmn-icon-user-task', |
|
166 |
translate('Create User Task') |
|
167 |
), |
9259c2
|
168 |
'create.call-activity': createAction( |
H |
169 |
'bpmn:CallActivity', |
|
170 |
'activity', |
|
171 |
'bpmn-icon-call-activity', |
|
172 |
translate('Create Call Activity') |
|
173 |
), |
|
174 |
'create.service-task': createAction( |
|
175 |
'bpmn:ServiceTask', |
|
176 |
'activity', |
|
177 |
'bpmn-icon-service', |
|
178 |
translate('Create Service Task') |
|
179 |
), |
820397
|
180 |
'create.data-object': createAction( |
H |
181 |
'bpmn:DataObjectReference', |
|
182 |
'data-object', |
|
183 |
'bpmn-icon-data-object', |
|
184 |
translate('Create DataObjectReference') |
|
185 |
), |
|
186 |
'create.data-store': createAction( |
|
187 |
'bpmn:DataStoreReference', |
|
188 |
'data-store', |
|
189 |
'bpmn-icon-data-store', |
|
190 |
translate('Create DataStoreReference') |
|
191 |
), |
|
192 |
'create.subprocess-expanded': { |
|
193 |
group: 'activity', |
|
194 |
className: 'bpmn-icon-subprocess-expanded', |
|
195 |
title: translate('Create expanded SubProcess'), |
|
196 |
action: { |
|
197 |
dragstart: createSubprocess, |
|
198 |
click: createSubprocess |
|
199 |
} |
|
200 |
}, |
|
201 |
'create.participant-expanded': { |
|
202 |
group: 'collaboration', |
|
203 |
className: 'bpmn-icon-participant', |
|
204 |
title: translate('Create Pool/Participant'), |
|
205 |
action: { |
|
206 |
dragstart: createParticipant, |
|
207 |
click: createParticipant |
|
208 |
} |
|
209 |
}, |
|
210 |
'create.group': createAction( |
|
211 |
'bpmn:Group', |
|
212 |
'artifact', |
|
213 |
'bpmn-icon-group', |
|
214 |
translate('Create Group') |
|
215 |
) |
|
216 |
}) |
|
217 |
|
|
218 |
return actions |
|
219 |
} |
|
220 |
|
|
221 |
CustomPalette.$inject = [ |
|
222 |
'palette', |
|
223 |
'create', |
|
224 |
'elementFactory', |
|
225 |
'spaceTool', |
|
226 |
'lassoTool', |
|
227 |
'handTool', |
|
228 |
'globalConnect', |
|
229 |
'translate' |
|
230 |
] |
|
231 |
|
|
232 |
CustomPalette.prototype = new F() // 核心,将 F的实例赋值给子类; |
|
233 |
CustomPalette.prototype.constructor = CustomPalette // 修复子类CustomPalette的构造器指向,防止原型链的混乱; |