@cratis/components 0.1.18 → 0.1.19
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/README.md +83 -0
- package/dist/cjs/Common/ErrorBoundary.js +26 -0
- package/dist/cjs/Common/ErrorBoundary.js.map +1 -0
- package/dist/cjs/Common/FormElement.js +10 -0
- package/dist/cjs/Common/FormElement.js.map +1 -0
- package/dist/cjs/Common/index.js +12 -0
- package/dist/cjs/Common/index.js.map +1 -0
- package/dist/cjs/EventModeling/EventModeling.css +146 -0
- package/dist/cjs/EventModeling/EventModeling.js +209 -0
- package/dist/cjs/EventModeling/EventModeling.js.map +1 -0
- package/dist/cjs/EventModeling/components/Canvas.js +403 -0
- package/dist/cjs/EventModeling/components/Canvas.js.map +1 -0
- package/dist/cjs/EventModeling/components/CanvasControls.js +10 -0
- package/dist/cjs/EventModeling/components/CanvasControls.js.map +1 -0
- package/dist/cjs/EventModeling/components/Toolbox.js +18 -0
- package/dist/cjs/EventModeling/components/Toolbox.js.map +1 -0
- package/dist/cjs/EventModeling/engine/connectorGraphics.js +173 -0
- package/dist/cjs/EventModeling/engine/connectorGraphics.js.map +1 -0
- package/dist/cjs/EventModeling/engine/elementSprites.js +301 -0
- package/dist/cjs/EventModeling/engine/elementSprites.js.map +1 -0
- package/dist/cjs/EventModeling/index.js +12 -0
- package/dist/cjs/EventModeling/index.js.map +1 -0
- package/dist/cjs/EventModeling/types.js +60 -0
- package/dist/cjs/EventModeling/types.js.map +1 -0
- package/dist/cjs/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/cjs/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/groups.js +15 -15
- package/dist/cjs/PivotViewer/components/pivot/groups.js.map +1 -1
- package/dist/cjs/PivotViewer/components/pivot/sprites.js +2 -2
- package/dist/cjs/PivotViewer/components/pivot/sprites.js.map +1 -1
- package/dist/cjs/PivotViewer/types.js.map +1 -1
- package/dist/cjs/TimeMachine/TimeMachine.js +0 -3
- package/dist/cjs/TimeMachine/TimeMachine.js.map +1 -1
- package/dist/cjs/index.js +16 -12
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/package.json +3 -0
- package/dist/esm/Common/ErrorBoundary.js +7 -4
- package/dist/esm/Common/ErrorBoundary.js.map +1 -1
- package/dist/esm/Common/FormElement.js +7 -4
- package/dist/esm/Common/FormElement.js.map +1 -1
- package/dist/esm/Common/index.js +4 -4
- package/dist/esm/Common/index.js.map +1 -1
- package/dist/esm/EventModeling/EventModeling.css +146 -0
- package/dist/esm/EventModeling/EventModeling.d.ts +11 -0
- package/dist/esm/EventModeling/EventModeling.d.ts.map +1 -0
- package/dist/esm/EventModeling/EventModeling.js +207 -0
- package/dist/esm/EventModeling/EventModeling.js.map +1 -0
- package/dist/esm/EventModeling/EventModeling.stories.d.ts +10 -0
- package/dist/esm/EventModeling/EventModeling.stories.d.ts.map +1 -0
- package/dist/esm/EventModeling/EventModeling.stories.js +252 -0
- package/dist/esm/EventModeling/EventModeling.stories.js.map +1 -0
- package/dist/esm/EventModeling/components/Canvas.d.ts +23 -0
- package/dist/esm/EventModeling/components/Canvas.d.ts.map +1 -0
- package/dist/esm/EventModeling/components/Canvas.js +382 -0
- package/dist/esm/EventModeling/components/Canvas.js.map +1 -0
- package/dist/esm/EventModeling/components/CanvasControls.d.ts +10 -0
- package/dist/esm/EventModeling/components/CanvasControls.d.ts.map +1 -0
- package/dist/esm/EventModeling/components/CanvasControls.js +8 -0
- package/dist/esm/EventModeling/components/CanvasControls.js.map +1 -0
- package/dist/esm/EventModeling/components/Toolbox.d.ts +9 -0
- package/dist/esm/EventModeling/components/Toolbox.d.ts.map +1 -0
- package/dist/esm/EventModeling/components/Toolbox.js +16 -0
- package/dist/esm/EventModeling/components/Toolbox.js.map +1 -0
- package/dist/esm/EventModeling/engine/connectorGraphics.d.ts +12 -0
- package/dist/esm/EventModeling/engine/connectorGraphics.d.ts.map +1 -0
- package/dist/esm/EventModeling/engine/connectorGraphics.js +151 -0
- package/dist/esm/EventModeling/engine/connectorGraphics.js.map +1 -0
- package/dist/esm/EventModeling/engine/elementSprites.d.ts +23 -0
- package/dist/esm/EventModeling/engine/elementSprites.d.ts.map +1 -0
- package/dist/esm/EventModeling/engine/elementSprites.js +276 -0
- package/dist/esm/EventModeling/engine/elementSprites.js.map +1 -0
- package/dist/esm/EventModeling/index.d.ts +3 -0
- package/dist/esm/EventModeling/index.d.ts.map +1 -0
- package/dist/esm/EventModeling/index.js +3 -0
- package/dist/esm/EventModeling/index.js.map +1 -0
- package/dist/esm/EventModeling/types.d.ts +79 -0
- package/dist/esm/EventModeling/types.d.ts.map +1 -0
- package/dist/esm/EventModeling/types.js +56 -0
- package/dist/esm/EventModeling/types.js.map +1 -0
- package/dist/esm/PivotViewer/components/PivotCanvas.d.ts +2 -2
- package/dist/esm/PivotViewer/components/PivotCanvas.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/PivotCanvas.js.map +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.d.ts +2 -2
- package/dist/esm/PivotViewer/components/PivotViewerMain.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/PivotViewerMain.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/groups.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/groups.js +2 -2
- package/dist/esm/PivotViewer/components/pivot/groups.js.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/sprites.d.ts +4 -4
- package/dist/esm/PivotViewer/components/pivot/sprites.d.ts.map +1 -1
- package/dist/esm/PivotViewer/components/pivot/sprites.js +2 -2
- package/dist/esm/PivotViewer/components/pivot/sprites.js.map +1 -1
- package/dist/esm/PivotViewer/types.d.ts +2 -2
- package/dist/esm/PivotViewer/types.d.ts.map +1 -1
- package/dist/esm/PivotViewer/types.js.map +1 -1
- package/dist/esm/TimeMachine/TimeMachine.js +1 -1
- package/dist/esm/index.d.ts +5 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +16 -12
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/package.json +3 -0
- package/dist/esm/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -78
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
import { EventModeling } from './EventModeling';
|
|
2
|
+
const meta = {
|
|
3
|
+
title: 'EventModeling',
|
|
4
|
+
component: EventModeling,
|
|
5
|
+
parameters: {
|
|
6
|
+
layout: 'fullscreen',
|
|
7
|
+
},
|
|
8
|
+
tags: ['autodocs'],
|
|
9
|
+
};
|
|
10
|
+
export default meta;
|
|
11
|
+
export const Empty = {
|
|
12
|
+
args: {
|
|
13
|
+
width: '100%',
|
|
14
|
+
height: '800px',
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
export const SimpleFlow = {
|
|
18
|
+
args: {
|
|
19
|
+
width: '100%',
|
|
20
|
+
height: '800px',
|
|
21
|
+
initialState: {
|
|
22
|
+
elements: [
|
|
23
|
+
{
|
|
24
|
+
id: 'cmd-1',
|
|
25
|
+
type: 'command',
|
|
26
|
+
position: { x: 100, y: 200 },
|
|
27
|
+
size: { width: 200, height: 100 },
|
|
28
|
+
label: 'Register User',
|
|
29
|
+
description: 'userId, email, name',
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id: 'evt-1',
|
|
33
|
+
type: 'event',
|
|
34
|
+
position: { x: 400, y: 200 },
|
|
35
|
+
size: { width: 200, height: 100 },
|
|
36
|
+
label: 'User Registered',
|
|
37
|
+
description: 'userId, email, name, timestamp',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'view-1',
|
|
41
|
+
type: 'readmodel',
|
|
42
|
+
position: { x: 700, y: 200 },
|
|
43
|
+
size: { width: 200, height: 100 },
|
|
44
|
+
label: 'User Profile',
|
|
45
|
+
description: 'userId, email, name, status',
|
|
46
|
+
},
|
|
47
|
+
],
|
|
48
|
+
connectors: [
|
|
49
|
+
{
|
|
50
|
+
id: 'conn-1',
|
|
51
|
+
from: { elementId: 'cmd-1', side: 'right' },
|
|
52
|
+
to: { elementId: 'evt-1', side: 'left' },
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'conn-2',
|
|
56
|
+
from: { elementId: 'evt-1', side: 'right' },
|
|
57
|
+
to: { elementId: 'view-1', side: 'left' },
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
export const ComplexEventModel = {
|
|
64
|
+
args: {
|
|
65
|
+
width: '100%',
|
|
66
|
+
height: '800px',
|
|
67
|
+
initialState: {
|
|
68
|
+
elements: [
|
|
69
|
+
{
|
|
70
|
+
id: 'cmd-1',
|
|
71
|
+
type: 'command',
|
|
72
|
+
position: { x: 100, y: 100 },
|
|
73
|
+
size: { width: 200, height: 100 },
|
|
74
|
+
label: 'Register User',
|
|
75
|
+
description: 'email, name, password',
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
id: 'evt-1',
|
|
79
|
+
type: 'event',
|
|
80
|
+
position: { x: 400, y: 100 },
|
|
81
|
+
size: { width: 200, height: 100 },
|
|
82
|
+
label: 'User Registered',
|
|
83
|
+
description: 'userId, email, name',
|
|
84
|
+
},
|
|
85
|
+
{
|
|
86
|
+
id: 'view-1',
|
|
87
|
+
type: 'readmodel',
|
|
88
|
+
position: { x: 700, y: 100 },
|
|
89
|
+
size: { width: 200, height: 100 },
|
|
90
|
+
label: 'User List',
|
|
91
|
+
description: 'All active users',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'proc-1',
|
|
95
|
+
type: 'process',
|
|
96
|
+
position: { x: 420, y: 260 },
|
|
97
|
+
size: { width: 80, height: 80 },
|
|
98
|
+
label: 'Send Email',
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'cmd-2',
|
|
102
|
+
type: 'command',
|
|
103
|
+
position: { x: 560, y: 250 },
|
|
104
|
+
size: { width: 200, height: 100 },
|
|
105
|
+
label: 'Send Verification',
|
|
106
|
+
description: 'userId, email, token',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'evt-2',
|
|
110
|
+
type: 'event',
|
|
111
|
+
position: { x: 860, y: 250 },
|
|
112
|
+
size: { width: 200, height: 100 },
|
|
113
|
+
label: 'Verification Sent',
|
|
114
|
+
description: 'userId, sentAt',
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
id: 'cmd-3',
|
|
118
|
+
type: 'command',
|
|
119
|
+
position: { x: 100, y: 400 },
|
|
120
|
+
size: { width: 200, height: 100 },
|
|
121
|
+
label: 'Verify Email',
|
|
122
|
+
description: 'token',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
id: 'evt-3',
|
|
126
|
+
type: 'event',
|
|
127
|
+
position: { x: 400, y: 400 },
|
|
128
|
+
size: { width: 200, height: 100 },
|
|
129
|
+
label: 'Email Verified',
|
|
130
|
+
description: 'userId, verifiedAt',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 'view-2',
|
|
134
|
+
type: 'readmodel',
|
|
135
|
+
position: { x: 700, y: 400 },
|
|
136
|
+
size: { width: 200, height: 100 },
|
|
137
|
+
label: 'User Profile',
|
|
138
|
+
description: 'userId, verified: true',
|
|
139
|
+
},
|
|
140
|
+
],
|
|
141
|
+
connectors: [
|
|
142
|
+
{
|
|
143
|
+
id: 'conn-1',
|
|
144
|
+
from: { elementId: 'cmd-1', side: 'right' },
|
|
145
|
+
to: { elementId: 'evt-1', side: 'left' },
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
id: 'conn-2',
|
|
149
|
+
from: { elementId: 'evt-1', side: 'right' },
|
|
150
|
+
to: { elementId: 'view-1', side: 'left' },
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
id: 'conn-3',
|
|
154
|
+
from: { elementId: 'evt-1', side: 'bottom' },
|
|
155
|
+
to: { elementId: 'proc-1', side: 'top' },
|
|
156
|
+
},
|
|
157
|
+
{
|
|
158
|
+
id: 'conn-4',
|
|
159
|
+
from: { elementId: 'proc-1', side: 'right' },
|
|
160
|
+
to: { elementId: 'cmd-2', side: 'left' },
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
id: 'conn-5',
|
|
164
|
+
from: { elementId: 'cmd-2', side: 'right' },
|
|
165
|
+
to: { elementId: 'evt-2', side: 'left' },
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: 'conn-6',
|
|
169
|
+
from: { elementId: 'cmd-3', side: 'right' },
|
|
170
|
+
to: { elementId: 'evt-3', side: 'left' },
|
|
171
|
+
},
|
|
172
|
+
{
|
|
173
|
+
id: 'conn-7',
|
|
174
|
+
from: { elementId: 'evt-3', side: 'right' },
|
|
175
|
+
to: { elementId: 'view-2', side: 'left' },
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
},
|
|
180
|
+
};
|
|
181
|
+
export const WithProcessAutomation = {
|
|
182
|
+
args: {
|
|
183
|
+
width: '100%',
|
|
184
|
+
height: '800px',
|
|
185
|
+
initialState: {
|
|
186
|
+
elements: [
|
|
187
|
+
{
|
|
188
|
+
id: 'evt-1',
|
|
189
|
+
type: 'event',
|
|
190
|
+
position: { x: 100, y: 150 },
|
|
191
|
+
size: { width: 200, height: 100 },
|
|
192
|
+
label: 'Order Placed',
|
|
193
|
+
description: 'orderId, amount, items',
|
|
194
|
+
},
|
|
195
|
+
{
|
|
196
|
+
id: 'view-1',
|
|
197
|
+
type: 'readmodel',
|
|
198
|
+
position: { x: 400, y: 150 },
|
|
199
|
+
size: { width: 200, height: 100 },
|
|
200
|
+
label: 'Pending Orders',
|
|
201
|
+
description: 'Orders awaiting processing',
|
|
202
|
+
},
|
|
203
|
+
{
|
|
204
|
+
id: 'proc-1',
|
|
205
|
+
type: 'process',
|
|
206
|
+
position: { x: 660, y: 160 },
|
|
207
|
+
size: { width: 80, height: 80 },
|
|
208
|
+
label: 'Process',
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
id: 'cmd-1',
|
|
212
|
+
type: 'command',
|
|
213
|
+
position: { x: 800, y: 150 },
|
|
214
|
+
size: { width: 200, height: 100 },
|
|
215
|
+
label: 'Process Payment',
|
|
216
|
+
description: 'orderId, amount',
|
|
217
|
+
},
|
|
218
|
+
{
|
|
219
|
+
id: 'evt-2',
|
|
220
|
+
type: 'event',
|
|
221
|
+
position: { x: 1100, y: 150 },
|
|
222
|
+
size: { width: 200, height: 100 },
|
|
223
|
+
label: 'Payment Processed',
|
|
224
|
+
description: 'orderId, transactionId',
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
connectors: [
|
|
228
|
+
{
|
|
229
|
+
id: 'conn-1',
|
|
230
|
+
from: { elementId: 'evt-1', side: 'right' },
|
|
231
|
+
to: { elementId: 'view-1', side: 'left' },
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
id: 'conn-2',
|
|
235
|
+
from: { elementId: 'view-1', side: 'right' },
|
|
236
|
+
to: { elementId: 'proc-1', side: 'left' },
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
id: 'conn-3',
|
|
240
|
+
from: { elementId: 'proc-1', side: 'right' },
|
|
241
|
+
to: { elementId: 'cmd-1', side: 'left' },
|
|
242
|
+
},
|
|
243
|
+
{
|
|
244
|
+
id: 'conn-4',
|
|
245
|
+
from: { elementId: 'cmd-1', side: 'right' },
|
|
246
|
+
to: { elementId: 'evt-2', side: 'left' },
|
|
247
|
+
},
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
},
|
|
251
|
+
};
|
|
252
|
+
//# sourceMappingURL=EventModeling.stories.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"EventModeling.stories.js","sourceRoot":"","sources":["../../../EventModeling/EventModeling.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,MAAM,IAAI,GA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oBACZ,IAAI,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,OAAO,EAAE;oBAC5C,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;iBAC3C;gBACD;oBACI,EAAE,EAAE,QAAQ;oBACZ,IAAI,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE;oBAC3C,EAAE,EAAE,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE;iBAC3C;aACJ;SACkB;KAC1B;CACJ,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { EventModelingState, ElementType, ElementData, Connector } from '../types';
|
|
3
|
+
export interface CanvasProps {
|
|
4
|
+
state: EventModelingState;
|
|
5
|
+
selectedTool: ElementType | 'select';
|
|
6
|
+
zoom: number;
|
|
7
|
+
pan: {
|
|
8
|
+
x: number;
|
|
9
|
+
y: number;
|
|
10
|
+
};
|
|
11
|
+
onZoomChange: (zoom: number) => void;
|
|
12
|
+
onPanChange: (pan: {
|
|
13
|
+
x: number;
|
|
14
|
+
y: number;
|
|
15
|
+
}) => void;
|
|
16
|
+
onAddElement: (type: ElementType, x: number, y: number) => void;
|
|
17
|
+
onUpdateElement: (id: string, updates: Partial<ElementData>) => void;
|
|
18
|
+
onAddConnector: (connector: Connector) => void;
|
|
19
|
+
onSelectElement: (id: string | undefined) => void;
|
|
20
|
+
onSelectConnector: (id: string | undefined) => void;
|
|
21
|
+
}
|
|
22
|
+
export declare const Canvas: React.FC<CanvasProps>;
|
|
23
|
+
//# sourceMappingURL=Canvas.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Canvas.d.ts","sourceRoot":"","sources":["../../../../EventModeling/components/Canvas.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAmD,MAAM,OAAO,CAAC;AAExE,OAAO,EAAE,kBAAkB,EAAE,WAAW,EAAE,WAAW,EAAE,SAAS,EAAY,MAAM,UAAU,CAAC;AAI7F,MAAM,WAAW,WAAW;IACxB,KAAK,EAAE,kBAAkB,CAAC;IAC1B,YAAY,EAAE,WAAW,GAAG,QAAQ,CAAC;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IAC9B,YAAY,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,GAAG,EAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI,CAAC;IACrD,YAAY,EAAE,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,KAAK,IAAI,CAAC;IAChE,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,KAAK,IAAI,CAAC;IACrE,cAAc,EAAE,CAAC,SAAS,EAAE,SAAS,KAAK,IAAI,CAAC;IAC/C,eAAe,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;IAClD,iBAAiB,EAAE,CAAC,EAAE,EAAE,MAAM,GAAG,SAAS,KAAK,IAAI,CAAC;CACvD;AAWD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAufxC,CAAC"}
|
|
@@ -0,0 +1,382 @@
|
|
|
1
|
+
import { jsx } from 'react/jsx-runtime';
|
|
2
|
+
import { useRef, useState, useEffect, useCallback } from 'react';
|
|
3
|
+
import * as PIXI from 'pixi.js';
|
|
4
|
+
import { updateElementSprite, createElementSprite, showEdgePoints, hideEdgePoints, setElementSelected } from '../engine/elementSprites.js';
|
|
5
|
+
import { updateConnectorGraphics, createConnectorGraphics } from '../engine/connectorGraphics.js';
|
|
6
|
+
|
|
7
|
+
function getComputedBackgroundColor() {
|
|
8
|
+
const style = getComputedStyle(document.documentElement);
|
|
9
|
+
const bgColorStr = style.getPropertyValue('--surface-ground').trim() || '#18181b';
|
|
10
|
+
return parseInt(bgColorStr.replace('#', ''), 16);
|
|
11
|
+
}
|
|
12
|
+
const Canvas = ({ state, selectedTool, zoom, pan, onZoomChange, onPanChange, onAddElement, onUpdateElement, onAddConnector, onSelectElement, onSelectConnector, }) => {
|
|
13
|
+
const containerRef = useRef(null);
|
|
14
|
+
const canvasRef = useRef(null);
|
|
15
|
+
const appRef = useRef(null);
|
|
16
|
+
const worldRef = useRef(null);
|
|
17
|
+
const elementsLayerRef = useRef(null);
|
|
18
|
+
const connectorsLayerRef = useRef(null);
|
|
19
|
+
const spritesRef = useRef(new Map());
|
|
20
|
+
const connectorsRef = useRef(new Map());
|
|
21
|
+
const [pixiReady, setPixiReady] = useState(false);
|
|
22
|
+
const draggingElementRef = useRef(null);
|
|
23
|
+
const connectingFromRef = useRef(null);
|
|
24
|
+
const tempConnectorLineRef = useRef(null);
|
|
25
|
+
const zoomRef = useRef(zoom);
|
|
26
|
+
const panRef = useRef(pan);
|
|
27
|
+
const selectedToolRef = useRef(selectedTool);
|
|
28
|
+
const stateRef = useRef(state);
|
|
29
|
+
const onZoomChangeRef = useRef(onZoomChange);
|
|
30
|
+
const onPanChangeRef = useRef(onPanChange);
|
|
31
|
+
const onAddElementRef = useRef(onAddElement);
|
|
32
|
+
const onUpdateElementRef = useRef(onUpdateElement);
|
|
33
|
+
const onAddConnectorRef = useRef(onAddConnector);
|
|
34
|
+
const onSelectElementRef = useRef(onSelectElement);
|
|
35
|
+
useEffect(() => { zoomRef.current = zoom; }, [zoom]);
|
|
36
|
+
useEffect(() => { panRef.current = pan; }, [pan]);
|
|
37
|
+
useEffect(() => { selectedToolRef.current = selectedTool; }, [selectedTool]);
|
|
38
|
+
useEffect(() => { stateRef.current = state; }, [state]);
|
|
39
|
+
useEffect(() => { onZoomChangeRef.current = onZoomChange; }, [onZoomChange]);
|
|
40
|
+
useEffect(() => { onPanChangeRef.current = onPanChange; }, [onPanChange]);
|
|
41
|
+
useEffect(() => { onAddElementRef.current = onAddElement; }, [onAddElement]);
|
|
42
|
+
useEffect(() => { onUpdateElementRef.current = onUpdateElement; }, [onUpdateElement]);
|
|
43
|
+
useEffect(() => { onAddConnectorRef.current = onAddConnector; }, [onAddConnector]);
|
|
44
|
+
useEffect(() => { onSelectElementRef.current = onSelectElement; }, [onSelectElement]);
|
|
45
|
+
const screenToWorld = useCallback((screenX, screenY) => {
|
|
46
|
+
const rect = containerRef.current?.getBoundingClientRect();
|
|
47
|
+
if (!rect)
|
|
48
|
+
return { x: 0, y: 0 };
|
|
49
|
+
const x = (screenX - rect.left - panRef.current.x) / zoomRef.current;
|
|
50
|
+
const y = (screenY - rect.top - panRef.current.y) / zoomRef.current;
|
|
51
|
+
return { x, y };
|
|
52
|
+
}, []);
|
|
53
|
+
const getEdgePosition = useCallback((element, side) => {
|
|
54
|
+
const { position, size } = element;
|
|
55
|
+
switch (side) {
|
|
56
|
+
case 'top': return { x: position.x + size.width / 2, y: position.y };
|
|
57
|
+
case 'right': return { x: position.x + size.width, y: position.y + size.height / 2 };
|
|
58
|
+
case 'bottom': return { x: position.x + size.width / 2, y: position.y + size.height };
|
|
59
|
+
case 'left': return { x: position.x, y: position.y + size.height / 2 };
|
|
60
|
+
}
|
|
61
|
+
}, []);
|
|
62
|
+
const handleWheel = useCallback((e) => {
|
|
63
|
+
e.preventDefault();
|
|
64
|
+
if (!containerRef.current)
|
|
65
|
+
return;
|
|
66
|
+
const rect = containerRef.current.getBoundingClientRect();
|
|
67
|
+
const mouseX = e.clientX - rect.left;
|
|
68
|
+
const mouseY = e.clientY - rect.top;
|
|
69
|
+
const currentZoom = zoomRef.current;
|
|
70
|
+
const currentPan = panRef.current;
|
|
71
|
+
if (e.ctrlKey) {
|
|
72
|
+
const zoomIntensity = 0.008;
|
|
73
|
+
const delta = Math.exp(-e.deltaY * zoomIntensity);
|
|
74
|
+
const newZoom = Math.max(0.1, Math.min(5, currentZoom * delta));
|
|
75
|
+
const worldX = (mouseX - currentPan.x) / currentZoom;
|
|
76
|
+
const worldY = (mouseY - currentPan.y) / currentZoom;
|
|
77
|
+
const newPanX = mouseX - worldX * newZoom;
|
|
78
|
+
const newPanY = mouseY - worldY * newZoom;
|
|
79
|
+
onZoomChangeRef.current(newZoom);
|
|
80
|
+
onPanChangeRef.current({ x: newPanX, y: newPanY });
|
|
81
|
+
}
|
|
82
|
+
else {
|
|
83
|
+
const newPan = {
|
|
84
|
+
x: currentPan.x - e.deltaX,
|
|
85
|
+
y: currentPan.y - e.deltaY,
|
|
86
|
+
};
|
|
87
|
+
onPanChangeRef.current(newPan);
|
|
88
|
+
}
|
|
89
|
+
}, []);
|
|
90
|
+
const handleCanvasPointerDown = useCallback((e) => {
|
|
91
|
+
if (!containerRef.current)
|
|
92
|
+
return;
|
|
93
|
+
const tool = selectedToolRef.current;
|
|
94
|
+
if (tool !== 'select') {
|
|
95
|
+
const worldPos = screenToWorld(e.clientX, e.clientY);
|
|
96
|
+
onAddElementRef.current(tool, worldPos.x, worldPos.y);
|
|
97
|
+
}
|
|
98
|
+
}, [screenToWorld]);
|
|
99
|
+
const handlePointerMove = useCallback((e) => {
|
|
100
|
+
if (draggingElementRef.current) {
|
|
101
|
+
const { id, startX, startY, elementStartX, elementStartY } = draggingElementRef.current;
|
|
102
|
+
const dx = (e.clientX - startX) / zoomRef.current;
|
|
103
|
+
const dy = (e.clientY - startY) / zoomRef.current;
|
|
104
|
+
onUpdateElementRef.current(id, {
|
|
105
|
+
position: { x: elementStartX + dx, y: elementStartY + dy }
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
if (connectingFromRef.current && tempConnectorLineRef.current) {
|
|
109
|
+
const worldPos = screenToWorld(e.clientX, e.clientY);
|
|
110
|
+
const line = tempConnectorLineRef.current;
|
|
111
|
+
line.clear();
|
|
112
|
+
line.moveTo(connectingFromRef.current.startX, connectingFromRef.current.startY);
|
|
113
|
+
line.lineTo(worldPos.x, worldPos.y);
|
|
114
|
+
line.stroke({ color: 0x6b7280, width: 2 });
|
|
115
|
+
}
|
|
116
|
+
}, [screenToWorld]);
|
|
117
|
+
const handlePointerUp = useCallback(() => {
|
|
118
|
+
draggingElementRef.current = null;
|
|
119
|
+
if (tempConnectorLineRef.current) {
|
|
120
|
+
tempConnectorLineRef.current.destroy();
|
|
121
|
+
tempConnectorLineRef.current = null;
|
|
122
|
+
}
|
|
123
|
+
connectingFromRef.current = null;
|
|
124
|
+
}, []);
|
|
125
|
+
const handleDragOver = useCallback((e) => {
|
|
126
|
+
if (e.dataTransfer?.types.includes('application/x-event-modeling-tool')) {
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
e.dataTransfer.dropEffect = 'copy';
|
|
129
|
+
}
|
|
130
|
+
}, []);
|
|
131
|
+
const handleDrop = useCallback((e) => {
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
const tool = e.dataTransfer?.getData('application/x-event-modeling-tool');
|
|
134
|
+
if (tool && containerRef.current) {
|
|
135
|
+
const worldPos = screenToWorld(e.clientX, e.clientY);
|
|
136
|
+
onAddElementRef.current(tool, worldPos.x, worldPos.y);
|
|
137
|
+
}
|
|
138
|
+
}, [screenToWorld]);
|
|
139
|
+
const handleElementPointerDown = useCallback((id, e) => {
|
|
140
|
+
e.stopPropagation();
|
|
141
|
+
const element = stateRef.current.elements.find(el => el.id === id);
|
|
142
|
+
if (!element)
|
|
143
|
+
return;
|
|
144
|
+
draggingElementRef.current = {
|
|
145
|
+
id,
|
|
146
|
+
startX: e.globalX,
|
|
147
|
+
startY: e.globalY,
|
|
148
|
+
elementStartX: element.position.x,
|
|
149
|
+
elementStartY: element.position.y,
|
|
150
|
+
};
|
|
151
|
+
onSelectElementRef.current(id);
|
|
152
|
+
}, []);
|
|
153
|
+
const handleEdgePointerDown = useCallback((elementId, side, e) => {
|
|
154
|
+
e.stopPropagation();
|
|
155
|
+
const element = stateRef.current.elements.find(el => el.id === elementId);
|
|
156
|
+
if (!element)
|
|
157
|
+
return;
|
|
158
|
+
const edgePos = getEdgePosition(element, side);
|
|
159
|
+
connectingFromRef.current = {
|
|
160
|
+
elementId,
|
|
161
|
+
side,
|
|
162
|
+
startX: edgePos.x,
|
|
163
|
+
startY: edgePos.y,
|
|
164
|
+
};
|
|
165
|
+
if (worldRef.current) {
|
|
166
|
+
const line = new PIXI.Graphics();
|
|
167
|
+
worldRef.current.addChild(line);
|
|
168
|
+
tempConnectorLineRef.current = line;
|
|
169
|
+
}
|
|
170
|
+
}, [getEdgePosition]);
|
|
171
|
+
const handleEdgePointerUp = useCallback((elementId, side, e) => {
|
|
172
|
+
e.stopPropagation();
|
|
173
|
+
if (connectingFromRef.current && connectingFromRef.current.elementId !== elementId) {
|
|
174
|
+
const connector = {
|
|
175
|
+
id: `conn-${Date.now()}`,
|
|
176
|
+
from: { elementId: connectingFromRef.current.elementId, side: connectingFromRef.current.side },
|
|
177
|
+
to: { elementId, side },
|
|
178
|
+
};
|
|
179
|
+
onAddConnectorRef.current(connector);
|
|
180
|
+
}
|
|
181
|
+
if (tempConnectorLineRef.current) {
|
|
182
|
+
tempConnectorLineRef.current.destroy();
|
|
183
|
+
tempConnectorLineRef.current = null;
|
|
184
|
+
}
|
|
185
|
+
connectingFromRef.current = null;
|
|
186
|
+
}, []);
|
|
187
|
+
const handleConnectorClick = useCallback((id) => {
|
|
188
|
+
onSelectConnector(id);
|
|
189
|
+
onSelectElement(undefined);
|
|
190
|
+
}, [onSelectConnector, onSelectElement]);
|
|
191
|
+
useEffect(() => {
|
|
192
|
+
if (!containerRef.current || appRef.current)
|
|
193
|
+
return;
|
|
194
|
+
let isMounted = true;
|
|
195
|
+
const initPixi = async () => {
|
|
196
|
+
const container = containerRef.current;
|
|
197
|
+
if (!container)
|
|
198
|
+
return;
|
|
199
|
+
const rect = container.getBoundingClientRect();
|
|
200
|
+
const width = rect.width > 0 ? rect.width : container.clientWidth || 800;
|
|
201
|
+
const height = rect.height > 0 ? rect.height : container.clientHeight || 600;
|
|
202
|
+
const app = new PIXI.Application();
|
|
203
|
+
const bgColor = getComputedBackgroundColor();
|
|
204
|
+
try {
|
|
205
|
+
await app.init({
|
|
206
|
+
background: bgColor,
|
|
207
|
+
antialias: true,
|
|
208
|
+
autoDensity: true,
|
|
209
|
+
resolution: window.devicePixelRatio || 1,
|
|
210
|
+
width,
|
|
211
|
+
height,
|
|
212
|
+
autoStart: true,
|
|
213
|
+
});
|
|
214
|
+
app.ticker.add(() => {
|
|
215
|
+
app.renderer.render(app.stage);
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
catch (e) {
|
|
219
|
+
console.error('PIXI init failed:', e);
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
if (!isMounted || !containerRef.current) {
|
|
223
|
+
app.destroy(true, { children: true });
|
|
224
|
+
return;
|
|
225
|
+
}
|
|
226
|
+
appRef.current = app;
|
|
227
|
+
const world = new PIXI.Container();
|
|
228
|
+
worldRef.current = world;
|
|
229
|
+
app.stage.addChild(world);
|
|
230
|
+
const connectorsLayer = new PIXI.Container();
|
|
231
|
+
connectorsLayerRef.current = connectorsLayer;
|
|
232
|
+
world.addChild(connectorsLayer);
|
|
233
|
+
const elementsLayer = new PIXI.Container();
|
|
234
|
+
elementsLayerRef.current = elementsLayer;
|
|
235
|
+
world.addChild(elementsLayer);
|
|
236
|
+
const canvasEl = app.canvas;
|
|
237
|
+
if (canvasEl && containerRef.current) {
|
|
238
|
+
canvasEl.classList.add('event-modeling-canvas');
|
|
239
|
+
canvasEl.style.touchAction = 'none';
|
|
240
|
+
containerRef.current.appendChild(canvasEl);
|
|
241
|
+
canvasRef.current = canvasEl;
|
|
242
|
+
canvasEl.addEventListener('wheel', handleWheel, { passive: false });
|
|
243
|
+
canvasEl.addEventListener('pointerdown', handleCanvasPointerDown);
|
|
244
|
+
canvasEl.addEventListener('pointermove', handlePointerMove);
|
|
245
|
+
canvasEl.addEventListener('pointerup', handlePointerUp);
|
|
246
|
+
canvasEl.addEventListener('pointerleave', handlePointerUp);
|
|
247
|
+
containerRef.current.addEventListener('dragover', handleDragOver);
|
|
248
|
+
containerRef.current.addEventListener('drop', handleDrop);
|
|
249
|
+
}
|
|
250
|
+
setPixiReady(true);
|
|
251
|
+
};
|
|
252
|
+
initPixi();
|
|
253
|
+
return () => {
|
|
254
|
+
isMounted = false;
|
|
255
|
+
if (canvasRef.current) {
|
|
256
|
+
canvasRef.current.removeEventListener('wheel', handleWheel);
|
|
257
|
+
canvasRef.current.removeEventListener('pointerdown', handleCanvasPointerDown);
|
|
258
|
+
canvasRef.current.removeEventListener('pointermove', handlePointerMove);
|
|
259
|
+
canvasRef.current.removeEventListener('pointerup', handlePointerUp);
|
|
260
|
+
canvasRef.current.removeEventListener('pointerleave', handlePointerUp);
|
|
261
|
+
}
|
|
262
|
+
if (containerRef.current) {
|
|
263
|
+
containerRef.current.removeEventListener('dragover', handleDragOver);
|
|
264
|
+
containerRef.current.removeEventListener('drop', handleDrop);
|
|
265
|
+
}
|
|
266
|
+
if (appRef.current) {
|
|
267
|
+
appRef.current.destroy(true, { children: true });
|
|
268
|
+
appRef.current = null;
|
|
269
|
+
}
|
|
270
|
+
};
|
|
271
|
+
}, [handleWheel, handleCanvasPointerDown, handlePointerMove, handlePointerUp, handleDragOver, handleDrop]);
|
|
272
|
+
useEffect(() => {
|
|
273
|
+
if (!pixiReady || !worldRef.current)
|
|
274
|
+
return;
|
|
275
|
+
worldRef.current.position.set(pan.x, pan.y);
|
|
276
|
+
worldRef.current.scale.set(zoom);
|
|
277
|
+
}, [pixiReady, zoom, pan]);
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
console.log('Sync useEffect running', { pixiReady, hasElementsLayer: !!elementsLayerRef.current, elementCount: state.elements.length });
|
|
280
|
+
if (!pixiReady || !elementsLayerRef.current) {
|
|
281
|
+
console.log('Sync useEffect early return', { pixiReady, hasElementsLayer: !!elementsLayerRef.current });
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const elementsMap = new Map(state.elements.map(el => [el.id, el]));
|
|
285
|
+
spritesRef.current.forEach((sprite, id) => {
|
|
286
|
+
if (!elementsMap.has(id)) {
|
|
287
|
+
elementsLayerRef.current.removeChild(sprite.container);
|
|
288
|
+
sprite.container.destroy({ children: true });
|
|
289
|
+
spritesRef.current.delete(id);
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
state.elements.forEach(elementData => {
|
|
293
|
+
const existing = spritesRef.current.get(elementData.id);
|
|
294
|
+
if (existing) {
|
|
295
|
+
updateElementSprite(existing, elementData);
|
|
296
|
+
}
|
|
297
|
+
else {
|
|
298
|
+
console.log('Creating sprite for', elementData.id, 'at', elementData.position.x, elementData.position.y);
|
|
299
|
+
const sprite = createElementSprite(elementData, Function.prototype, Function.prototype, Function.prototype, Function.prototype, Function.prototype);
|
|
300
|
+
spritesRef.current.set(elementData.id, sprite);
|
|
301
|
+
elementsLayerRef.current.addChild(sprite.container);
|
|
302
|
+
console.log('Sprite added to layer', {
|
|
303
|
+
spritePos: { x: sprite.container.position.x, y: sprite.container.position.y },
|
|
304
|
+
layerChildren: elementsLayerRef.current.children.length,
|
|
305
|
+
visible: sprite.container.visible,
|
|
306
|
+
alpha: sprite.container.alpha
|
|
307
|
+
});
|
|
308
|
+
sprite.container.eventMode = 'static';
|
|
309
|
+
sprite.container.cursor = 'grab';
|
|
310
|
+
sprite.container.on('pointerdown', (e) => {
|
|
311
|
+
handleElementPointerDown(elementData.id, e);
|
|
312
|
+
});
|
|
313
|
+
sprite.edgePoints.forEach((edgePoint, side) => {
|
|
314
|
+
edgePoint.eventMode = 'static';
|
|
315
|
+
edgePoint.cursor = 'crosshair';
|
|
316
|
+
edgePoint.on('pointerdown', (e) => {
|
|
317
|
+
handleEdgePointerDown(elementData.id, side, e);
|
|
318
|
+
});
|
|
319
|
+
edgePoint.on('pointerup', (e) => {
|
|
320
|
+
handleEdgePointerUp(elementData.id, side, e);
|
|
321
|
+
});
|
|
322
|
+
edgePoint.on('pointerover', () => {
|
|
323
|
+
if (connectingFromRef.current && connectingFromRef.current.elementId !== elementData.id) {
|
|
324
|
+
edgePoint.alpha = 1;
|
|
325
|
+
edgePoint.scale.set(1.5);
|
|
326
|
+
}
|
|
327
|
+
});
|
|
328
|
+
edgePoint.on('pointerout', () => {
|
|
329
|
+
edgePoint.scale.set(1);
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
sprite.container.on('pointerover', () => showEdgePoints(sprite));
|
|
333
|
+
sprite.container.on('pointerout', () => {
|
|
334
|
+
if (!connectingFromRef.current || connectingFromRef.current.elementId !== elementData.id) {
|
|
335
|
+
hideEdgePoints(sprite);
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
});
|
|
340
|
+
}, [pixiReady, state.elements, handleElementPointerDown, handleEdgePointerDown, handleEdgePointerUp]);
|
|
341
|
+
const getElementsMapRef = useRef(() => new Map());
|
|
342
|
+
useEffect(() => {
|
|
343
|
+
getElementsMapRef.current = () => new Map(stateRef.current.elements.map(el => [el.id, el]));
|
|
344
|
+
}, []);
|
|
345
|
+
useEffect(() => {
|
|
346
|
+
if (!pixiReady || !connectorsLayerRef.current)
|
|
347
|
+
return;
|
|
348
|
+
const connectorsMap = new Map(state.connectors.map(conn => [conn.id, conn]));
|
|
349
|
+
const elementsMap = new Map(state.elements.map(el => [el.id, el]));
|
|
350
|
+
connectorsRef.current.forEach((connGraphics, id) => {
|
|
351
|
+
if (!connectorsMap.has(id)) {
|
|
352
|
+
connectorsLayerRef.current.removeChild(connGraphics.graphics);
|
|
353
|
+
connGraphics.graphics.destroy();
|
|
354
|
+
connectorsRef.current.delete(id);
|
|
355
|
+
}
|
|
356
|
+
});
|
|
357
|
+
state.connectors.forEach(connector => {
|
|
358
|
+
const existing = connectorsRef.current.get(connector.id);
|
|
359
|
+
if (existing) {
|
|
360
|
+
existing.connector = connector;
|
|
361
|
+
existing.getElements = getElementsMapRef.current;
|
|
362
|
+
updateConnectorGraphics(existing, elementsMap);
|
|
363
|
+
}
|
|
364
|
+
else {
|
|
365
|
+
const connGraphics = createConnectorGraphics(connector, getElementsMapRef.current, handleConnectorClick);
|
|
366
|
+
connectorsRef.current.set(connector.id, connGraphics);
|
|
367
|
+
connectorsLayerRef.current.addChild(connGraphics.graphics);
|
|
368
|
+
}
|
|
369
|
+
});
|
|
370
|
+
}, [pixiReady, state.connectors, state.elements, handleConnectorClick]);
|
|
371
|
+
useEffect(() => {
|
|
372
|
+
if (!pixiReady)
|
|
373
|
+
return;
|
|
374
|
+
spritesRef.current.forEach((sprite, id) => {
|
|
375
|
+
setElementSelected(sprite, id === state.selectedElementId);
|
|
376
|
+
});
|
|
377
|
+
}, [pixiReady, state.selectedElementId]);
|
|
378
|
+
return jsx("div", { ref: containerRef, className: "event-modeling-canvas-container" });
|
|
379
|
+
};
|
|
380
|
+
|
|
381
|
+
export { Canvas };
|
|
382
|
+
//# sourceMappingURL=Canvas.js.map
|