@asyra/ui-context 0.2.4 → 0.5.0
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/LICENSE +21 -0
- package/README.md +13 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/property-registry.d.ts +78 -0
- package/dist/property-registry.d.ts.map +1 -0
- package/dist/property-registry.js +119 -0
- package/dist/property-registry.js.map +1 -0
- package/dist/ui-context.d.ts +9 -21
- package/dist/ui-context.d.ts.map +1 -1
- package/dist/ui-context.js +58 -81
- package/dist/ui-context.js.map +1 -1
- package/package.json +24 -9
- package/.turbo/turbo-test$colon$ci.log +0 -117
- package/.turbo/turbo-test$colon$local.log +0 -23
- package/.turbo/turbo-test.log +0 -0
- package/CHANGELOG.md +0 -49
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -538
- package/coverage/coverage-final.json +0 -7443
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -176
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/index.html +0 -146
- package/coverage/src/index.ts.html +0 -97
- package/coverage/src/stores/index.html +0 -146
- package/coverage/src/stores/render.ts.html +0 -106
- package/coverage/src/stores/scene-tree.ts.html +0 -790
- package/coverage/src/stores/selection.ts.html +0 -220
- package/coverage/src/stores/system-context/index.html +0 -146
- package/coverage/src/stores/system-context/index.ts.html +0 -88
- package/coverage/src/stores/system-context/primary-tool.ts.html +0 -109
- package/coverage/src/stores/system-context/system-context.ts.html +0 -85
- package/coverage/src/subscribes/index.html +0 -161
- package/coverage/src/subscribes/index.ts.html +0 -124
- package/coverage/src/subscribes/render.ts.html +0 -151
- package/coverage/src/subscribes/scene-tree.ts.html +0 -373
- package/coverage/src/subscribes/selection.ts.html +0 -253
- package/coverage/src/subscribes/system-context/index.html +0 -131
- package/coverage/src/subscribes/system-context/index.ts.html +0 -100
- package/coverage/src/subscribes/system-context/primary-tool.ts.html +0 -151
- package/coverage/src/types.ts.html +0 -124
- package/coverage/src/ui-context.ts.html +0 -568
- package/dist/__tests__/ui-context.test.d.ts +0 -2
- package/dist/__tests__/ui-context.test.d.ts.map +0 -1
- package/dist/__tests__/ui-context.test.js +0 -170
- package/dist/__tests__/ui-context.test.js.map +0 -1
- package/dist/stores/__tests__/render.test.d.ts +0 -2
- package/dist/stores/__tests__/render.test.d.ts.map +0 -1
- package/dist/stores/__tests__/render.test.js +0 -30
- package/dist/stores/__tests__/render.test.js.map +0 -1
- package/dist/stores/__tests__/selection.test.d.ts +0 -2
- package/dist/stores/__tests__/selection.test.d.ts.map +0 -1
- package/dist/stores/__tests__/selection.test.js +0 -128
- package/dist/stores/__tests__/selection.test.js.map +0 -1
- package/dist/stores/render.d.ts +0 -4
- package/dist/stores/render.d.ts.map +0 -1
- package/dist/stores/render.js +0 -7
- package/dist/stores/render.js.map +0 -1
- package/dist/stores/scene-tree.d.ts +0 -35
- package/dist/stores/scene-tree.d.ts.map +0 -1
- package/dist/stores/scene-tree.js +0 -158
- package/dist/stores/scene-tree.js.map +0 -1
- package/dist/stores/selection.d.ts +0 -8
- package/dist/stores/selection.d.ts.map +0 -1
- package/dist/stores/selection.js +0 -38
- package/dist/stores/selection.js.map +0 -1
- package/dist/stores/system-context/__tests__/primary-tool.test.d.ts +0 -2
- package/dist/stores/system-context/__tests__/primary-tool.test.d.ts.map +0 -1
- package/dist/stores/system-context/__tests__/primary-tool.test.js +0 -27
- package/dist/stores/system-context/__tests__/primary-tool.test.js.map +0 -1
- package/dist/stores/system-context/index.d.ts +0 -2
- package/dist/stores/system-context/index.d.ts.map +0 -1
- package/dist/stores/system-context/index.js +0 -2
- package/dist/stores/system-context/index.js.map +0 -1
- package/dist/stores/system-context/primary-tool.d.ts +0 -5
- package/dist/stores/system-context/primary-tool.d.ts.map +0 -1
- package/dist/stores/system-context/primary-tool.js +0 -7
- package/dist/stores/system-context/primary-tool.js.map +0 -1
- package/dist/stores/system-context/system-context.d.ts +0 -1
- package/dist/stores/system-context/system-context.d.ts.map +0 -1
- package/dist/stores/system-context/system-context.js +0 -2
- package/dist/stores/system-context/system-context.js.map +0 -1
- package/dist/subscribes/index.d.ts +0 -5
- package/dist/subscribes/index.d.ts.map +0 -1
- package/dist/subscribes/index.js +0 -12
- package/dist/subscribes/index.js.map +0 -1
- package/dist/subscribes/render.d.ts +0 -2
- package/dist/subscribes/render.d.ts.map +0 -1
- package/dist/subscribes/render.js +0 -15
- package/dist/subscribes/render.js.map +0 -1
- package/dist/subscribes/scene-tree.d.ts +0 -5
- package/dist/subscribes/scene-tree.d.ts.map +0 -1
- package/dist/subscribes/scene-tree.js +0 -71
- package/dist/subscribes/scene-tree.js.map +0 -1
- package/dist/subscribes/selection.d.ts +0 -5
- package/dist/subscribes/selection.d.ts.map +0 -1
- package/dist/subscribes/selection.js +0 -42
- package/dist/subscribes/selection.js.map +0 -1
- package/dist/subscribes/system-context/index.d.ts +0 -2
- package/dist/subscribes/system-context/index.d.ts.map +0 -1
- package/dist/subscribes/system-context/index.js +0 -5
- package/dist/subscribes/system-context/index.js.map +0 -1
- package/dist/subscribes/system-context/primary-tool.d.ts +0 -4
- package/dist/subscribes/system-context/primary-tool.d.ts.map +0 -1
- package/dist/subscribes/system-context/primary-tool.js +0 -15
- package/dist/subscribes/system-context/primary-tool.js.map +0 -1
- package/dist/types.d.ts +0 -11
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -2
- package/dist/types.js.map +0 -1
- package/src/__tests__/ui-context.test.ts +0 -220
- package/src/index.ts +0 -4
- package/src/stores/__tests__/render.test.ts +0 -38
- package/src/stores/__tests__/selection.test.ts +0 -190
- package/src/stores/render.ts +0 -7
- package/src/stores/scene-tree.ts +0 -235
- package/src/stores/selection.ts +0 -45
- package/src/stores/system-context/__tests__/primary-tool.test.ts +0 -37
- package/src/stores/system-context/index.ts +0 -1
- package/src/stores/system-context/primary-tool.ts +0 -8
- package/src/stores/system-context/system-context.ts +0 -0
- package/src/subscribes/index.ts +0 -13
- package/src/subscribes/render.ts +0 -22
- package/src/subscribes/scene-tree.ts +0 -96
- package/src/subscribes/selection.ts +0 -56
- package/src/subscribes/system-context/index.ts +0 -5
- package/src/subscribes/system-context/primary-tool.ts +0 -22
- package/src/types.ts +0 -13
- package/src/ui-context.ts +0 -161
- package/tsconfig.json +0 -17
package/src/index.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
-
import RenderStore from '../render'
|
|
3
|
-
import * as UIContextModule from '../../ui-context'
|
|
4
|
-
|
|
5
|
-
// Mock ui-context
|
|
6
|
-
vi.mock('../../ui-context', () => ({
|
|
7
|
-
default: {
|
|
8
|
-
updateZoom: vi.fn()
|
|
9
|
-
}
|
|
10
|
-
}))
|
|
11
|
-
|
|
12
|
-
describe('RenderStore', () => {
|
|
13
|
-
let renderStore: RenderStore
|
|
14
|
-
|
|
15
|
-
beforeEach(() => {
|
|
16
|
-
vi.clearAllMocks()
|
|
17
|
-
vi.resetAllMocks()
|
|
18
|
-
renderStore = new RenderStore()
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
it('should update zoom in ui context', () => {
|
|
22
|
-
renderStore.updateZoom(2.5)
|
|
23
|
-
|
|
24
|
-
expect(UIContextModule.default.updateZoom).toHaveBeenCalledWith(2.5)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
it('should update zoom to 1', () => {
|
|
28
|
-
renderStore.updateZoom(1)
|
|
29
|
-
|
|
30
|
-
expect(UIContextModule.default.updateZoom).toHaveBeenCalledWith(1)
|
|
31
|
-
})
|
|
32
|
-
|
|
33
|
-
it('should update zoom to 0.5', () => {
|
|
34
|
-
renderStore.updateZoom(0.5)
|
|
35
|
-
|
|
36
|
-
expect(UIContextModule.default.updateZoom).toHaveBeenCalledWith(0.5)
|
|
37
|
-
})
|
|
38
|
-
})
|
|
@@ -1,190 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, type Mock } from 'vitest'
|
|
2
|
-
import SelectionStore from '../selection'
|
|
3
|
-
import * as SelectionModule from '@asyra/selection'
|
|
4
|
-
import * as SceneTreeModule from '@asyra/scene-tree'
|
|
5
|
-
import * as UIContextModule from '../../ui-context'
|
|
6
|
-
import {
|
|
7
|
-
SELECTION_TYPES,
|
|
8
|
-
ComputedAttrs,
|
|
9
|
-
EntityTypes,
|
|
10
|
-
ElementInstanceTypes
|
|
11
|
-
} from '@asyra/utils'
|
|
12
|
-
|
|
13
|
-
// Mock external dependencies
|
|
14
|
-
vi.mock('@asyra/selection', () => ({
|
|
15
|
-
default: {
|
|
16
|
-
get: vi.fn()
|
|
17
|
-
},
|
|
18
|
-
SelectionManager: vi.fn()
|
|
19
|
-
}))
|
|
20
|
-
|
|
21
|
-
vi.mock('@asyra/scene-tree', () => ({
|
|
22
|
-
default: {
|
|
23
|
-
getElementById: vi.fn()
|
|
24
|
-
}
|
|
25
|
-
}))
|
|
26
|
-
|
|
27
|
-
vi.mock('../../ui-context', () => ({
|
|
28
|
-
default: {
|
|
29
|
-
updateElementSelection: vi.fn(),
|
|
30
|
-
updateVertexSelection: vi.fn(),
|
|
31
|
-
updateComputedProperties: vi.fn()
|
|
32
|
-
}
|
|
33
|
-
}))
|
|
34
|
-
|
|
35
|
-
describe('SelectionStore', () => {
|
|
36
|
-
let selectionStore: SelectionStore
|
|
37
|
-
let mockSelectionManager: { get: Mock }
|
|
38
|
-
let mockSelection: { getSelectedIds: Mock }
|
|
39
|
-
|
|
40
|
-
beforeEach(() => {
|
|
41
|
-
vi.clearAllMocks()
|
|
42
|
-
vi.resetAllMocks()
|
|
43
|
-
|
|
44
|
-
mockSelection = {
|
|
45
|
-
getSelectedIds: vi.fn(() => new Set(['elem-1', 'elem-2']))
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
mockSelectionManager = {
|
|
49
|
-
get: vi.fn(() => mockSelection)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
vi.mocked(SelectionModule.default.get).mockImplementation(
|
|
53
|
-
mockSelectionManager.get
|
|
54
|
-
)
|
|
55
|
-
|
|
56
|
-
selectionStore = new SelectionStore()
|
|
57
|
-
selectionStore.selectionManager =
|
|
58
|
-
mockSelectionManager as unknown as SelectionModule.SelectionManager
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
// Test updateSelection for ELEMENT type
|
|
62
|
-
it('should update element selection and computed properties when elements are selected', () => {
|
|
63
|
-
const mockElement1 = {
|
|
64
|
-
getAllComputedData: vi.fn(
|
|
65
|
-
() =>
|
|
66
|
-
({
|
|
67
|
-
id: 'elem-1',
|
|
68
|
-
type: EntityTypes.RECTANGLE,
|
|
69
|
-
name: 'Element 1',
|
|
70
|
-
x: 10,
|
|
71
|
-
y: 20,
|
|
72
|
-
width: 100,
|
|
73
|
-
height: 50,
|
|
74
|
-
rotation: 0
|
|
75
|
-
}) as ComputedAttrs
|
|
76
|
-
)
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
const mockElement2 = {
|
|
80
|
-
getAllComputedData: vi.fn(
|
|
81
|
-
() =>
|
|
82
|
-
({
|
|
83
|
-
id: 'elem-2',
|
|
84
|
-
type: EntityTypes.RECTANGLE,
|
|
85
|
-
name: 'Element 2',
|
|
86
|
-
x: 10,
|
|
87
|
-
y: 20,
|
|
88
|
-
width: 100,
|
|
89
|
-
height: 50,
|
|
90
|
-
rotation: 0
|
|
91
|
-
}) as ComputedAttrs
|
|
92
|
-
)
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
vi.mocked(SceneTreeModule.default.getElementById)
|
|
96
|
-
.mockReturnValueOnce(mockElement1 as unknown as ElementInstanceTypes)
|
|
97
|
-
.mockReturnValueOnce(mockElement2 as unknown as ElementInstanceTypes)
|
|
98
|
-
|
|
99
|
-
selectionStore.updateSelection(SELECTION_TYPES.ELEMENT)
|
|
100
|
-
|
|
101
|
-
expect(mockSelectionManager.get).toHaveBeenCalledWith(
|
|
102
|
-
SELECTION_TYPES.ELEMENT
|
|
103
|
-
)
|
|
104
|
-
expect(UIContextModule.default.updateElementSelection).toHaveBeenCalledWith(
|
|
105
|
-
new Set(['elem-1', 'elem-2'])
|
|
106
|
-
)
|
|
107
|
-
expect(
|
|
108
|
-
UIContextModule.default.updateComputedProperties
|
|
109
|
-
).toHaveBeenCalledWith([
|
|
110
|
-
{
|
|
111
|
-
id: 'elem-1',
|
|
112
|
-
type: EntityTypes.RECTANGLE,
|
|
113
|
-
name: 'Element 1',
|
|
114
|
-
x: 10,
|
|
115
|
-
y: 20,
|
|
116
|
-
width: 100,
|
|
117
|
-
height: 50,
|
|
118
|
-
rotation: 0
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
id: 'elem-2',
|
|
122
|
-
type: EntityTypes.RECTANGLE,
|
|
123
|
-
name: 'Element 2',
|
|
124
|
-
x: 10,
|
|
125
|
-
y: 20,
|
|
126
|
-
width: 100,
|
|
127
|
-
height: 50,
|
|
128
|
-
rotation: 0
|
|
129
|
-
}
|
|
130
|
-
])
|
|
131
|
-
})
|
|
132
|
-
|
|
133
|
-
it('should not update computed properties when no elements are selected', () => {
|
|
134
|
-
mockSelection.getSelectedIds = vi.fn(() => new Set())
|
|
135
|
-
|
|
136
|
-
selectionStore.updateSelection(SELECTION_TYPES.ELEMENT)
|
|
137
|
-
|
|
138
|
-
expect(UIContextModule.default.updateElementSelection).toHaveBeenCalledWith(
|
|
139
|
-
new Set()
|
|
140
|
-
)
|
|
141
|
-
expect(
|
|
142
|
-
UIContextModule.default.updateComputedProperties
|
|
143
|
-
).not.toHaveBeenCalled()
|
|
144
|
-
})
|
|
145
|
-
|
|
146
|
-
it('should handle missing elements gracefully', () => {
|
|
147
|
-
vi.mocked(SceneTreeModule.default.getElementById)
|
|
148
|
-
.mockReturnValueOnce(undefined as unknown as ElementInstanceTypes)
|
|
149
|
-
.mockReturnValueOnce(undefined as unknown as ElementInstanceTypes)
|
|
150
|
-
|
|
151
|
-
selectionStore.updateSelection(SELECTION_TYPES.ELEMENT)
|
|
152
|
-
|
|
153
|
-
expect(UIContextModule.default.updateElementSelection).toHaveBeenCalled()
|
|
154
|
-
expect(
|
|
155
|
-
UIContextModule.default.updateComputedProperties
|
|
156
|
-
).toHaveBeenCalledWith([])
|
|
157
|
-
})
|
|
158
|
-
|
|
159
|
-
// Test updateSelection for VERTEX type
|
|
160
|
-
it('should update vertex selection when vertices are selected', () => {
|
|
161
|
-
mockSelection.getSelectedIds = vi.fn(
|
|
162
|
-
() => new Set(['vertex-1', 'vertex-2'])
|
|
163
|
-
)
|
|
164
|
-
|
|
165
|
-
selectionStore.updateSelection(SELECTION_TYPES.VERTEX)
|
|
166
|
-
|
|
167
|
-
expect(mockSelectionManager.get).toHaveBeenCalledWith(
|
|
168
|
-
SELECTION_TYPES.VERTEX
|
|
169
|
-
)
|
|
170
|
-
expect(UIContextModule.default.updateVertexSelection).toHaveBeenCalledWith(
|
|
171
|
-
new Set(['vertex-1', 'vertex-2'])
|
|
172
|
-
)
|
|
173
|
-
expect(
|
|
174
|
-
UIContextModule.default.updateComputedProperties
|
|
175
|
-
).not.toHaveBeenCalled()
|
|
176
|
-
})
|
|
177
|
-
|
|
178
|
-
it('should return early when selection is null', () => {
|
|
179
|
-
mockSelectionManager.get = vi.fn(() => null)
|
|
180
|
-
|
|
181
|
-
selectionStore.updateSelection(SELECTION_TYPES.ELEMENT)
|
|
182
|
-
|
|
183
|
-
expect(
|
|
184
|
-
UIContextModule.default.updateElementSelection
|
|
185
|
-
).not.toHaveBeenCalled()
|
|
186
|
-
expect(
|
|
187
|
-
UIContextModule.default.updateComputedProperties
|
|
188
|
-
).not.toHaveBeenCalled()
|
|
189
|
-
})
|
|
190
|
-
})
|
package/src/stores/render.ts
DELETED
package/src/stores/scene-tree.ts
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import { BehaviorSubject } from 'rxjs'
|
|
2
|
-
import { EntityTypes } from '@asyra/utils'
|
|
3
|
-
import type {
|
|
4
|
-
ComputedAttrs,
|
|
5
|
-
DataTypes,
|
|
6
|
-
ElementRawData,
|
|
7
|
-
GroupRawData,
|
|
8
|
-
WorkspaceRawData
|
|
9
|
-
} from '@asyra/utils'
|
|
10
|
-
import type { SceneTree, Workspace } from '@asyra/scene-tree'
|
|
11
|
-
import uiContext from '../ui-context'
|
|
12
|
-
|
|
13
|
-
type UIWorkspaceData = Partial<
|
|
14
|
-
Pick<WorkspaceRawData, 'id' | 'name' | 'type' | 'children'> & ComputedAttrs
|
|
15
|
-
>
|
|
16
|
-
|
|
17
|
-
type UIAllElementData = (ElementRawData | GroupRawData) & ComputedAttrs
|
|
18
|
-
|
|
19
|
-
type UIElementData = Partial<UIAllElementData>
|
|
20
|
-
|
|
21
|
-
export default class SceneTreeStore {
|
|
22
|
-
private sceneTree: SceneTree
|
|
23
|
-
private dirty: boolean
|
|
24
|
-
private workspaceId: string
|
|
25
|
-
private workspace: BehaviorSubject<UIWorkspaceData>
|
|
26
|
-
private _elements: Map<
|
|
27
|
-
string,
|
|
28
|
-
BehaviorSubject<UIElementData> | BehaviorSubject<UIWorkspaceData>
|
|
29
|
-
>
|
|
30
|
-
private _deletedMap: Map<
|
|
31
|
-
string,
|
|
32
|
-
BehaviorSubject<UIElementData> | BehaviorSubject<UIWorkspaceData>
|
|
33
|
-
>
|
|
34
|
-
|
|
35
|
-
constructor(sceneTree: SceneTree) {
|
|
36
|
-
this.sceneTree = sceneTree
|
|
37
|
-
this.dirty = false
|
|
38
|
-
this.workspaceId = ''
|
|
39
|
-
this.workspace = new BehaviorSubject<UIWorkspaceData>({
|
|
40
|
-
id: this.workspaceId,
|
|
41
|
-
name: '',
|
|
42
|
-
children: [],
|
|
43
|
-
type: EntityTypes.WORKSPACE
|
|
44
|
-
})
|
|
45
|
-
this._elements = new Map()
|
|
46
|
-
this._deletedMap = new Map()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
reload() {
|
|
50
|
-
this.workspaceId = this.sceneTree.workspace
|
|
51
|
-
const currentWs = this.sceneTree.currentWorkspace
|
|
52
|
-
|
|
53
|
-
if (
|
|
54
|
-
this.workspaceId &&
|
|
55
|
-
currentWs &&
|
|
56
|
-
currentWs.get('id') === this.workspaceId
|
|
57
|
-
) {
|
|
58
|
-
const ws = currentWs
|
|
59
|
-
this.workspace = new BehaviorSubject<UIWorkspaceData>({
|
|
60
|
-
id: ws.get('id'),
|
|
61
|
-
name: ws.get('name'),
|
|
62
|
-
type: ws.get('type'),
|
|
63
|
-
children: [...((ws as Workspace).get('children') || [])]
|
|
64
|
-
})
|
|
65
|
-
this.addToMap(ws.get('id'), this.workspace)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
this.sceneTree.getAllElements().forEach((element, id) => {
|
|
69
|
-
if (element.get('type') !== EntityTypes.WORKSPACE) {
|
|
70
|
-
this.addToMap(id, new BehaviorSubject(element.save() as UIElementData))
|
|
71
|
-
}
|
|
72
|
-
})
|
|
73
|
-
|
|
74
|
-
this.updateFlattenedElementIds()
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
markDirty() {
|
|
78
|
-
this.dirty = true
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
clearDirty() {
|
|
82
|
-
this.dirty = false
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
fireChange() {
|
|
86
|
-
if (this.dirty) {
|
|
87
|
-
this.clearDirty()
|
|
88
|
-
this.updateFlattenedElementIds()
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
getElement(
|
|
93
|
-
elementId: string
|
|
94
|
-
):
|
|
95
|
-
| BehaviorSubject<UIElementData>
|
|
96
|
-
| BehaviorSubject<UIWorkspaceData>
|
|
97
|
-
| undefined {
|
|
98
|
-
return this._elements.get(elementId)
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
addToMap(
|
|
102
|
-
elementId: string,
|
|
103
|
-
elementSubject:
|
|
104
|
-
| BehaviorSubject<UIElementData>
|
|
105
|
-
| BehaviorSubject<UIWorkspaceData>
|
|
106
|
-
) {
|
|
107
|
-
this.removeFromDeleteMap(elementId)
|
|
108
|
-
this._elements.set(elementId, elementSubject)
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
removeFromMap(elementId: string) {
|
|
112
|
-
const elementSubject = this.getElement(elementId)
|
|
113
|
-
if (elementSubject) {
|
|
114
|
-
this.addToDeleteMap(elementId, elementSubject)
|
|
115
|
-
}
|
|
116
|
-
this._elements.delete(elementId)
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
addToDeleteMap(
|
|
120
|
-
elementId: string,
|
|
121
|
-
elementSubject:
|
|
122
|
-
| BehaviorSubject<UIElementData>
|
|
123
|
-
| BehaviorSubject<UIWorkspaceData>
|
|
124
|
-
) {
|
|
125
|
-
this._deletedMap.set(elementId, elementSubject)
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
getRestoreElementById(
|
|
129
|
-
elementId: string
|
|
130
|
-
):
|
|
131
|
-
| BehaviorSubject<UIElementData>
|
|
132
|
-
| BehaviorSubject<UIWorkspaceData>
|
|
133
|
-
| undefined {
|
|
134
|
-
return this._deletedMap.get(elementId)
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
removeFromDeleteMap(elementId: string) {
|
|
138
|
-
this._deletedMap.delete(elementId)
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
isGroup(element: UIElementData) {
|
|
142
|
-
return 'children' in element
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
getFlattenedElementIds() {
|
|
146
|
-
const ids: string[] = []
|
|
147
|
-
const workspace = this.workspace.getValue()
|
|
148
|
-
if (workspace?.children) {
|
|
149
|
-
workspace.children.forEach((childId: string) => {
|
|
150
|
-
this.collectChildrenIds(childId, ids)
|
|
151
|
-
})
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
return ids
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
collectChildrenIds(elementId: string, ids: string[]): void {
|
|
158
|
-
const elementS = this.getElement(elementId)
|
|
159
|
-
if (!elementS) return
|
|
160
|
-
|
|
161
|
-
const element = elementS.getValue()
|
|
162
|
-
if (element.id) {
|
|
163
|
-
ids.push(element.id)
|
|
164
|
-
}
|
|
165
|
-
if (this.isGroup(element)) {
|
|
166
|
-
;(element as GroupRawData).children.forEach((childId: string) => {
|
|
167
|
-
const child = this.getElement(childId)?.getValue()
|
|
168
|
-
if (!child) return
|
|
169
|
-
|
|
170
|
-
this.collectChildrenIds(childId, ids)
|
|
171
|
-
})
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
updateFlattenedElementIds() {
|
|
176
|
-
uiContext.flattenedElementIds.next(this.getFlattenedElementIds())
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
addElement(data: Partial<ElementRawData | GroupRawData>) {
|
|
180
|
-
this.markDirty()
|
|
181
|
-
const elementSubject =
|
|
182
|
-
this.getRestoreElementById(data.id as string) || new BehaviorSubject(data)
|
|
183
|
-
this.addToMap(data.id as string, elementSubject)
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
removeElement(
|
|
187
|
-
data: Partial<ElementRawData | GroupRawData>,
|
|
188
|
-
parentId: string
|
|
189
|
-
): void {
|
|
190
|
-
this.markDirty()
|
|
191
|
-
const parent = this.getElement(parentId)
|
|
192
|
-
const avaliableParent =
|
|
193
|
-
parent ?? (this.workspace as BehaviorSubject<UIWorkspaceData>)
|
|
194
|
-
if (avaliableParent && data.id) {
|
|
195
|
-
const parentData = avaliableParent.getValue() as GroupRawData
|
|
196
|
-
const idx = parentData.children.indexOf(data.id)
|
|
197
|
-
const newChildren = [...parentData.children]
|
|
198
|
-
|
|
199
|
-
newChildren.splice(idx, 1)
|
|
200
|
-
|
|
201
|
-
avaliableParent.next({
|
|
202
|
-
...parentData,
|
|
203
|
-
children: newChildren
|
|
204
|
-
})
|
|
205
|
-
|
|
206
|
-
this.removeFromMap(data.id)
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
updateElement(elementId: string, key: string, after: DataTypes) {
|
|
211
|
-
const element = this.getElement(elementId)
|
|
212
|
-
if (!element) return
|
|
213
|
-
|
|
214
|
-
this.markDirty()
|
|
215
|
-
const current = element.getValue()
|
|
216
|
-
if ('children' in current) {
|
|
217
|
-
;(element as BehaviorSubject<UIWorkspaceData | GroupRawData>).next({
|
|
218
|
-
...current,
|
|
219
|
-
[key]: after
|
|
220
|
-
})
|
|
221
|
-
} else {
|
|
222
|
-
;(element as BehaviorSubject<UIElementData>).next({
|
|
223
|
-
...current,
|
|
224
|
-
[key]: after
|
|
225
|
-
})
|
|
226
|
-
}
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
getElementGeneralData(elementId: string) {
|
|
230
|
-
const element = this.getElement(elementId)
|
|
231
|
-
if (!element) return
|
|
232
|
-
|
|
233
|
-
return element.getValue()
|
|
234
|
-
}
|
|
235
|
-
}
|
package/src/stores/selection.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import selectionManager, { SelectionManager } from '@asyra/selection'
|
|
2
|
-
import { ComputedAttrs, SELECTION_TYPES } from '@asyra/utils'
|
|
3
|
-
import sceneTree from '@asyra/scene-tree'
|
|
4
|
-
import uiContext from '../ui-context'
|
|
5
|
-
|
|
6
|
-
export default class SelectionStore {
|
|
7
|
-
selectionManager: SelectionManager
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
this.selectionManager = selectionManager
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
updateSelection(type: SELECTION_TYPES) {
|
|
14
|
-
const selection = this.selectionManager.get(type)
|
|
15
|
-
if (!selection) {
|
|
16
|
-
return
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
const selectedIds = selection.getSelectedIds()
|
|
20
|
-
|
|
21
|
-
switch (type) {
|
|
22
|
-
case SELECTION_TYPES.ELEMENT: {
|
|
23
|
-
uiContext.updateElementSelection(selectedIds)
|
|
24
|
-
const allElementData = [...selectedIds].reduce((acc, elementId) => {
|
|
25
|
-
const element = sceneTree.getElementById(elementId)
|
|
26
|
-
if (!element) {
|
|
27
|
-
return acc
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const elementData = element.getAllComputedData() as ComputedAttrs
|
|
31
|
-
acc.push(elementData)
|
|
32
|
-
return acc
|
|
33
|
-
}, [] as ComputedAttrs[])
|
|
34
|
-
|
|
35
|
-
if (selectedIds.size) {
|
|
36
|
-
uiContext.updateComputedProperties(allElementData)
|
|
37
|
-
}
|
|
38
|
-
break
|
|
39
|
-
}
|
|
40
|
-
case SELECTION_TYPES.VERTEX:
|
|
41
|
-
uiContext.updateVertexSelection(selectedIds)
|
|
42
|
-
break
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
}
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
-
import { PrimaryToolStore } from '../primary-tool'
|
|
3
|
-
import * as UIContextModule from '../../../ui-context'
|
|
4
|
-
import { PrimaryToolType } from '@asyra/utils'
|
|
5
|
-
|
|
6
|
-
// Mock ui-context
|
|
7
|
-
vi.mock('../../../ui-context', () => ({
|
|
8
|
-
default: {
|
|
9
|
-
updatePrimaryTool: vi.fn()
|
|
10
|
-
}
|
|
11
|
-
}))
|
|
12
|
-
|
|
13
|
-
describe('PrimaryToolStore', () => {
|
|
14
|
-
let primaryToolStore: PrimaryToolStore
|
|
15
|
-
|
|
16
|
-
beforeEach(() => {
|
|
17
|
-
vi.clearAllMocks()
|
|
18
|
-
vi.resetAllMocks()
|
|
19
|
-
primaryToolStore = new PrimaryToolStore()
|
|
20
|
-
})
|
|
21
|
-
|
|
22
|
-
it('should update primary tool in ui context', () => {
|
|
23
|
-
primaryToolStore.updatePrimaryTool(PrimaryToolType.RECTANGLE)
|
|
24
|
-
|
|
25
|
-
expect(UIContextModule.default.updatePrimaryTool).toHaveBeenCalledWith(
|
|
26
|
-
PrimaryToolType.RECTANGLE
|
|
27
|
-
)
|
|
28
|
-
})
|
|
29
|
-
|
|
30
|
-
it('should update primary tool to SELECT', () => {
|
|
31
|
-
primaryToolStore.updatePrimaryTool(PrimaryToolType.SELECT)
|
|
32
|
-
|
|
33
|
-
expect(UIContextModule.default.updatePrimaryTool).toHaveBeenCalledWith(
|
|
34
|
-
PrimaryToolType.SELECT
|
|
35
|
-
)
|
|
36
|
-
})
|
|
37
|
-
})
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { PrimaryToolStore } from './primary-tool'
|
|
File without changes
|
package/src/subscribes/index.ts
DELETED
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { sceneTreeStore, initSceneTreeDataSubscribe } from './scene-tree'
|
|
2
|
-
import { selectionStore, initSelectionDataSubscribe } from './selection'
|
|
3
|
-
import { initRenderDataSubscribe } from './render'
|
|
4
|
-
import { initSystemContextSubscribe } from './system-context'
|
|
5
|
-
|
|
6
|
-
export const initDataContexts = () => {
|
|
7
|
-
initRenderDataSubscribe()
|
|
8
|
-
initSceneTreeDataSubscribe()
|
|
9
|
-
initSelectionDataSubscribe()
|
|
10
|
-
initSystemContextSubscribe()
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
export { sceneTreeStore, selectionStore }
|
package/src/subscribes/render.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
requestRenderZoom,
|
|
3
|
-
subscribeToEmitZoomFit
|
|
4
|
-
} from '@asyra/reactive-events'
|
|
5
|
-
import RenderStore from '../stores/render'
|
|
6
|
-
|
|
7
|
-
const renderStore = new RenderStore()
|
|
8
|
-
|
|
9
|
-
let hasInit = false
|
|
10
|
-
|
|
11
|
-
export const initRenderDataSubscribe = () => {
|
|
12
|
-
if (hasInit) {
|
|
13
|
-
return
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
subscribeToEmitZoomFit(async () => {
|
|
17
|
-
const zoom = await requestRenderZoom()
|
|
18
|
-
renderStore.updateZoom(zoom)
|
|
19
|
-
})
|
|
20
|
-
|
|
21
|
-
hasInit = true
|
|
22
|
-
}
|