orcasvn-react-diagrams 0.2.6 → 0.2.7

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.
@@ -3,75 +3,128 @@ import { createId } from '../../utils/ids';
3
3
  import type { DemoConfig } from '../types';
4
4
  import { baseElementShapes, basePortShapes } from './shared';
5
5
 
6
- const createNestedState = (): DiagramState => ({
7
- elements: [
8
- {
9
- id: 'parent-1',
10
- position: { x: 140, y: 140 },
11
- size: { width: 320, height: 240 },
12
- shapeId: 'panel',
13
- },
14
- {
15
- id: 'child-1',
16
- position: { x: 40, y: 60 },
17
- size: { width: 160, height: 100 },
18
- shapeId: 'default',
19
- parentId: 'parent-1',
20
- },
21
- ],
22
- ports: [
23
- {
24
- id: 'child-port',
25
- elementId: 'child-1',
26
- position: { x: 20, y: 20 },
27
- shapeId: 'port-circle',
28
- anchorCenter: true,
29
- },
30
- ],
31
- links: [],
32
- texts: [
33
- {
34
- id: 'child-label',
35
- content: 'Child',
36
- position: { x: 6, y: -16 },
37
- ownerId: 'child-1',
38
- },
39
- ],
40
- });
41
-
42
- export const nestedDemoConfig: DemoConfig = ({
43
- id: 'nested',
44
- title: 'Nested Elements',
45
- description: 'Parent/child elements with world positioning.',
46
- createState: createNestedState,
47
- elementShapes: baseElementShapes,
48
- portShapes: basePortShapes,
49
- defaultElementShapeId: 'default',
50
- defaultPortShapeId: 'port-circle',
51
- actions: [
52
- {
53
- id: 'move-parent',
54
- label: 'Move parent',
55
- run: (editor, state) => {
56
- const parent = state.elements.find((element) => element.id === 'parent-1');
57
- if (!parent) return;
58
- editor.moveElementTo(parent.id, parent.position.x + 40, parent.position.y + 20);
59
- },
60
- },
61
- {
62
- id: 'add-child',
63
- label: 'Add child',
64
- run: (editor, state, demo, helpers) => {
65
- const parent = state.elements.find((element) => element.id === 'parent-1');
66
- if (!parent) return;
67
- const offset = helpers.nextOffset();
68
- editor.addElement({
69
- id: `child-${createId()}`,
70
- position: { x: 30 + offset, y: 50 + offset },
71
- size: { width: 140, height: 90 },
72
- shapeId: demo.defaultElementShapeId ?? 'default',
73
- parentId: parent.id,
74
- });
6
+ const createNestedState = (): DiagramState => ({
7
+ elements: [
8
+ {
9
+ id: 'parent-locked',
10
+ position: { x: 110, y: 140 },
11
+ size: { width: 300, height: 240 },
12
+ shapeId: 'panel',
13
+ childElementInteraction: { movable: false },
14
+ },
15
+ {
16
+ id: 'child-locked',
17
+ position: { x: 40, y: 60 },
18
+ size: { width: 160, height: 100 },
19
+ shapeId: 'default',
20
+ parentId: 'parent-locked',
21
+ },
22
+ {
23
+ id: 'parent-free',
24
+ position: { x: 470, y: 140 },
25
+ size: { width: 300, height: 240 },
26
+ shapeId: 'panel',
27
+ },
28
+ {
29
+ id: 'child-free',
30
+ position: { x: 40, y: 60 },
31
+ size: { width: 160, height: 100 },
32
+ shapeId: 'default',
33
+ parentId: 'parent-free',
34
+ },
35
+ ],
36
+ ports: [
37
+ {
38
+ id: 'child-port-locked',
39
+ elementId: 'child-locked',
40
+ position: { x: 20, y: 20 },
41
+ shapeId: 'port-circle',
42
+ anchorCenter: true,
43
+ },
44
+ {
45
+ id: 'child-port-free',
46
+ elementId: 'child-free',
47
+ position: { x: 20, y: 20 },
48
+ shapeId: 'port-circle',
49
+ anchorCenter: true,
50
+ },
51
+ ],
52
+ links: [],
53
+ texts: [
54
+ {
55
+ id: 'parent-locked-label',
56
+ content: 'Locked child drag',
57
+ position: { x: 12, y: 12 },
58
+ ownerId: 'parent-locked',
59
+ interaction: { movable: false, editable: false },
60
+ },
61
+ {
62
+ id: 'child-locked-label',
63
+ content: 'Drag disabled',
64
+ position: { x: 10, y: 10 },
65
+ ownerId: 'child-locked',
66
+ interaction: { movable: false, editable: false },
67
+ },
68
+ {
69
+ id: 'parent-free-label',
70
+ content: 'Movable child drag',
71
+ position: { x: 12, y: 12 },
72
+ ownerId: 'parent-free',
73
+ interaction: { movable: false, editable: false },
74
+ },
75
+ {
76
+ id: 'child-free-label',
77
+ content: 'Drag enabled',
78
+ position: { x: 10, y: 10 },
79
+ ownerId: 'child-free',
80
+ interaction: { movable: false, editable: false },
81
+ },
82
+ ],
83
+ });
84
+
85
+ export const nestedDemoConfig: DemoConfig = ({
86
+ id: 'nested',
87
+ title: 'Nested Elements',
88
+ description: 'Compare locked and movable child drag; locked children still move through API actions.',
89
+ createState: createNestedState,
90
+ elementShapes: baseElementShapes,
91
+ portShapes: basePortShapes,
92
+ defaultElementShapeId: 'default',
93
+ defaultPortShapeId: 'port-circle',
94
+ actions: [
95
+ {
96
+ id: 'move-locked-child-api',
97
+ label: 'Move locked child (API)',
98
+ run: (editor, state) => {
99
+ const child = state.elements.find((element) => element.id === 'child-locked');
100
+ const parent = state.elements.find((element) => element.id === 'parent-locked');
101
+ if (!child || !parent) return;
102
+ editor.moveElementTo(child.id, parent.position.x + child.position.x + 30, parent.position.y + child.position.y + 10);
103
+ },
104
+ },
105
+ {
106
+ id: 'move-parent',
107
+ label: 'Move locked parent',
108
+ run: (editor, state) => {
109
+ const parent = state.elements.find((element) => element.id === 'parent-locked');
110
+ if (!parent) return;
111
+ editor.moveElementTo(parent.id, parent.position.x + 40, parent.position.y + 20);
112
+ },
113
+ },
114
+ {
115
+ id: 'add-child',
116
+ label: 'Add movable child',
117
+ run: (editor, state, demo, helpers) => {
118
+ const parent = state.elements.find((element) => element.id === 'parent-free');
119
+ if (!parent) return;
120
+ const offset = helpers.nextOffset();
121
+ editor.addElement({
122
+ id: `child-free-${createId()}`,
123
+ position: { x: 30 + offset, y: 50 + offset },
124
+ size: { width: 140, height: 90 },
125
+ shapeId: demo.defaultElementShapeId ?? 'default',
126
+ parentId: parent.id,
127
+ });
75
128
  },
76
129
  },
77
130
  ],