@asyra/scene-tree 0.2.5 → 0.5.1
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/component-registry.d.ts +24 -0
- package/dist/component-registry.d.ts.map +1 -0
- package/dist/component-registry.js +26 -0
- package/dist/component-registry.js.map +1 -0
- package/dist/components/computed.d.ts +9 -6
- package/dist/components/computed.d.ts.map +1 -1
- package/dist/components/computed.js +37 -28
- package/dist/components/computed.js.map +1 -1
- package/dist/components/element-change-handler.d.ts +4 -3
- package/dist/components/element-change-handler.d.ts.map +1 -1
- package/dist/components/element-change-handler.js +21 -9
- package/dist/components/element-change-handler.js.map +1 -1
- package/dist/components/element.d.ts +19 -11
- package/dist/components/element.d.ts.map +1 -1
- package/dist/components/element.js +61 -31
- package/dist/components/element.js.map +1 -1
- package/dist/components/group.d.ts +9 -4
- package/dist/components/group.d.ts.map +1 -1
- package/dist/components/group.js +16 -12
- package/dist/components/group.js.map +1 -1
- package/dist/components/index.d.ts +3 -5
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +3 -5
- package/dist/components/index.js.map +1 -1
- package/dist/components/props.d.ts +12 -7
- package/dist/components/props.d.ts.map +1 -1
- package/dist/components/props.js +64 -20
- package/dist/components/props.js.map +1 -1
- package/dist/components/workspace.d.ts +9 -5
- package/dist/components/workspace.d.ts.map +1 -1
- package/dist/components/workspace.js +62 -36
- package/dist/components/workspace.js.map +1 -1
- package/dist/create-dynamic-component.d.ts +5 -0
- package/dist/create-dynamic-component.d.ts.map +1 -0
- package/dist/create-dynamic-component.js +53 -0
- package/dist/create-dynamic-component.js.map +1 -0
- package/dist/create-dynamic-props.d.ts +4 -0
- package/dist/create-dynamic-props.d.ts.map +1 -0
- package/dist/create-dynamic-props.js +104 -0
- package/dist/create-dynamic-props.js.map +1 -0
- package/dist/element-mutation.d.ts +92 -0
- package/dist/element-mutation.d.ts.map +1 -0
- package/dist/element-mutation.js +2 -0
- package/dist/element-mutation.js.map +1 -0
- package/dist/entity-data.d.ts +16 -0
- package/dist/entity-data.d.ts.map +1 -0
- package/dist/{utils.js → entity-data.js} +34 -22
- package/dist/entity-data.js.map +1 -0
- package/dist/index.d.ts +9 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/props-manager-context.d.ts +6 -0
- package/dist/props-manager-context.d.ts.map +1 -0
- package/dist/props-manager-context.js +26 -0
- package/dist/props-manager-context.js.map +1 -0
- package/dist/sceneTree.d.ts +105 -10
- package/dist/sceneTree.d.ts.map +1 -1
- package/dist/sceneTree.js +3308 -96
- package/dist/sceneTree.js.map +1 -1
- package/dist/subscribes.d.ts.map +1 -1
- package/dist/subscribes.js +188 -24
- package/dist/subscribes.js.map +1 -1
- package/dist/types.d.ts +26 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +24 -5
- package/.turbo/turbo-test$colon$ci.log +0 -134
- package/.turbo/turbo-test$colon$local.log +0 -31
- package/.turbo/turbo-test.log +0 -53
- package/CHANGELOG.md +0 -51
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -778
- package/coverage/coverage-final.json +0 -10478
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -131
- 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/components/computed.ts.html +0 -313
- package/coverage/src/components/element-change-handler.ts.html +0 -145
- package/coverage/src/components/element.ts.html +0 -586
- package/coverage/src/components/frame.ts.html +0 -169
- package/coverage/src/components/group.ts.html +0 -295
- package/coverage/src/components/index.html +0 -236
- package/coverage/src/components/index.ts.html +0 -103
- package/coverage/src/components/props.ts.html +0 -355
- package/coverage/src/components/rectangle.ts.html +0 -169
- package/coverage/src/components/workspace.ts.html +0 -433
- package/coverage/src/index.html +0 -161
- package/coverage/src/index.ts.html +0 -103
- package/coverage/src/sceneTree.ts.html +0 -853
- package/coverage/src/subscribes.ts.html +0 -295
- package/coverage/src/utils.ts.html +0 -328
- package/dist/__tests__/sceneTree.test.d.ts +0 -2
- package/dist/__tests__/sceneTree.test.d.ts.map +0 -1
- package/dist/__tests__/sceneTree.test.js +0 -261
- package/dist/__tests__/sceneTree.test.js.map +0 -1
- package/dist/components/frame.d.ts +0 -11
- package/dist/components/frame.d.ts.map +0 -1
- package/dist/components/frame.js +0 -21
- package/dist/components/frame.js.map +0 -1
- package/dist/components/legacy-element.d.ts +0 -22
- package/dist/components/legacy-element.d.ts.map +0 -1
- package/dist/components/legacy-element.js +0 -120
- package/dist/components/legacy-element.js.map +0 -1
- package/dist/components/polygon.d.ts +0 -11
- package/dist/components/polygon.d.ts.map +0 -1
- package/dist/components/polygon.js +0 -21
- package/dist/components/polygon.js.map +0 -1
- package/dist/components/rectangle.d.ts +0 -11
- package/dist/components/rectangle.d.ts.map +0 -1
- package/dist/components/rectangle.js +0 -21
- package/dist/components/rectangle.js.map +0 -1
- package/dist/components/shape-entity.d.ts +0 -16
- package/dist/components/shape-entity.d.ts.map +0 -1
- package/dist/components/shape-entity.js +0 -42
- package/dist/components/shape-entity.js.map +0 -1
- package/dist/components/shape.d.ts +0 -40
- package/dist/components/shape.d.ts.map +0 -1
- package/dist/components/shape.js +0 -105
- package/dist/components/shape.js.map +0 -1
- package/dist/utils.d.ts +0 -19
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- package/src/__tests__/sceneTree.test.ts +0 -339
- package/src/components/computed.ts +0 -76
- package/src/components/element-change-handler.ts +0 -20
- package/src/components/element.ts +0 -167
- package/src/components/frame.ts +0 -28
- package/src/components/group.ts +0 -70
- package/src/components/index.ts +0 -6
- package/src/components/props.ts +0 -90
- package/src/components/rectangle.ts +0 -28
- package/src/components/workspace.ts +0 -116
- package/src/index.ts +0 -6
- package/src/sceneTree.ts +0 -256
- package/src/subscribes.ts +0 -70
- package/src/utils.ts +0 -81
- package/tsconfig.json +0 -17
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ElementRawData,
|
|
3
|
-
ElementAttrs,
|
|
4
|
-
IElement,
|
|
5
|
-
PropsRawData,
|
|
6
|
-
ComputedAttrs,
|
|
7
|
-
PropertyComponentInstanceDataTypes
|
|
8
|
-
} from '@asyra/utils'
|
|
9
|
-
import {
|
|
10
|
-
Setter,
|
|
11
|
-
IDTypes,
|
|
12
|
-
NameTypes,
|
|
13
|
-
EntityTypes,
|
|
14
|
-
id,
|
|
15
|
-
loadId,
|
|
16
|
-
name,
|
|
17
|
-
loadName
|
|
18
|
-
} from '@asyra/utils'
|
|
19
|
-
import Props from './props'
|
|
20
|
-
import Computed from './computed'
|
|
21
|
-
import ElementChangeHandler from './element-change-handler'
|
|
22
|
-
|
|
23
|
-
const elementChangeHandler = new ElementChangeHandler()
|
|
24
|
-
|
|
25
|
-
type ElementDataType = Partial<ElementRawData>
|
|
26
|
-
|
|
27
|
-
const ElementProps: (keyof ElementAttrs)[] = ['id', 'name', 'visible', 'lock']
|
|
28
|
-
|
|
29
|
-
class Element<T extends ElementAttrs = ElementAttrs>
|
|
30
|
-
extends Setter<T>
|
|
31
|
-
implements IElement<T>
|
|
32
|
-
{
|
|
33
|
-
_idType!: IDTypes
|
|
34
|
-
_nameType!: NameTypes
|
|
35
|
-
|
|
36
|
-
props!: Props
|
|
37
|
-
computed!: Computed<ComputedAttrs>
|
|
38
|
-
|
|
39
|
-
constructor(data?: Partial<ElementRawData>) {
|
|
40
|
-
super(elementChangeHandler.addChange)
|
|
41
|
-
this._init()
|
|
42
|
-
|
|
43
|
-
if (data && Object.keys(data).length) {
|
|
44
|
-
this.load(data)
|
|
45
|
-
} else {
|
|
46
|
-
this.create()
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.setupProps(data?.props)
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
_init(): void {
|
|
53
|
-
this._idType ??= IDTypes.ELEMENT
|
|
54
|
-
this._nameType ??= NameTypes.ELEMENT
|
|
55
|
-
this.data = {
|
|
56
|
-
id: '',
|
|
57
|
-
type: EntityTypes.UNDEFINED,
|
|
58
|
-
name: '',
|
|
59
|
-
visible: false,
|
|
60
|
-
lock: true
|
|
61
|
-
} as T
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
create(): void {
|
|
65
|
-
this.data = {
|
|
66
|
-
id: id(this._idType),
|
|
67
|
-
type: EntityTypes.ELEMENT,
|
|
68
|
-
name: name(this._nameType),
|
|
69
|
-
visible: true,
|
|
70
|
-
lock: false
|
|
71
|
-
} as T
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
load(data: ElementDataType): void {
|
|
75
|
-
if (!data) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
if (data.type !== EntityTypes.WORKSPACE) {
|
|
80
|
-
ElementProps.forEach((propName) => {
|
|
81
|
-
switch (propName) {
|
|
82
|
-
case 'id': {
|
|
83
|
-
const id = data.id
|
|
84
|
-
if (id) {
|
|
85
|
-
this.data.id = id
|
|
86
|
-
loadId(id, this._idType)
|
|
87
|
-
}
|
|
88
|
-
break
|
|
89
|
-
}
|
|
90
|
-
case 'name': {
|
|
91
|
-
const name = data.name
|
|
92
|
-
if (name) {
|
|
93
|
-
this.data.name = name
|
|
94
|
-
loadName(name, this._nameType)
|
|
95
|
-
}
|
|
96
|
-
break
|
|
97
|
-
}
|
|
98
|
-
default: {
|
|
99
|
-
const key = propName as keyof ElementAttrs
|
|
100
|
-
const newValue = data[key] as T[keyof T]
|
|
101
|
-
if (newValue !== undefined) {
|
|
102
|
-
this.data[propName as keyof T] = newValue
|
|
103
|
-
}
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
})
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
save(): ElementRawData {
|
|
111
|
-
const data = {} as ElementRawData
|
|
112
|
-
data.id = this.get('id')
|
|
113
|
-
data.type = this.get('type')
|
|
114
|
-
data.name = this.get('name')
|
|
115
|
-
data.visible = this.get('visible')
|
|
116
|
-
data.lock = this.get('lock')
|
|
117
|
-
|
|
118
|
-
if (this.data.type !== EntityTypes.WORKSPACE) {
|
|
119
|
-
data.props = this.props.save()
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
return data
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
setupProps(propsData?: Partial<PropsRawData>) {
|
|
126
|
-
const elementId = this.get('id') as string
|
|
127
|
-
if (this.data.type !== EntityTypes.WORKSPACE) {
|
|
128
|
-
if (propsData) {
|
|
129
|
-
this.props = new Props(elementId, propsData)
|
|
130
|
-
} else {
|
|
131
|
-
this.props = new Props(elementId)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
this.computed = new Computed(elementId, this.props)
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
updateComputedData<K extends keyof ComputedAttrs>(
|
|
139
|
-
key: K,
|
|
140
|
-
data: ComputedAttrs[K]
|
|
141
|
-
) {
|
|
142
|
-
if (!(key in this.data)) {
|
|
143
|
-
this.computed.set(key, data)
|
|
144
|
-
|
|
145
|
-
// Convert data type from ComputedAttrs to PropertyComponentInstanceDataTypes
|
|
146
|
-
type KEY = keyof PropertyComponentInstanceDataTypes
|
|
147
|
-
this.props.updateData(
|
|
148
|
-
key as KEY,
|
|
149
|
-
data as PropertyComponentInstanceDataTypes[KEY]
|
|
150
|
-
)
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
getAllComputedData() {
|
|
155
|
-
if (this.get('type') !== EntityTypes.WORKSPACE) {
|
|
156
|
-
return this.computed.save()
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
return {}
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
cleanup() {
|
|
163
|
-
this.props.cleanup()
|
|
164
|
-
}
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
export default Element
|
package/src/components/frame.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { FrameRawData } from '@asyra/utils'
|
|
2
|
-
import { EntityTypes, NameTypes } from '@asyra/utils'
|
|
3
|
-
import Group from './group'
|
|
4
|
-
|
|
5
|
-
type FrameDataType = Partial<FrameRawData>
|
|
6
|
-
|
|
7
|
-
class Frame extends Group {
|
|
8
|
-
constructor(data?: Partial<FrameRawData>) {
|
|
9
|
-
super(data)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
_init(): void {
|
|
13
|
-
this._nameType = NameTypes.FRAME
|
|
14
|
-
super._init()
|
|
15
|
-
this.data.type = EntityTypes.FRAME
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
create(): void {
|
|
19
|
-
super.create()
|
|
20
|
-
this.data.type = EntityTypes.FRAME
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
load(data: FrameDataType): void {
|
|
24
|
-
super.load(data)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default Frame
|
package/src/components/group.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
GroupRawData,
|
|
3
|
-
GroupAttrs,
|
|
4
|
-
ElementInstanceTypes,
|
|
5
|
-
IGroupElement,
|
|
6
|
-
ElementRawData
|
|
7
|
-
} from '@asyra/utils'
|
|
8
|
-
import { EntityTypes, NameTypes } from '@asyra/utils'
|
|
9
|
-
import Element from './element'
|
|
10
|
-
|
|
11
|
-
type GroupDataType = Partial<GroupRawData>
|
|
12
|
-
|
|
13
|
-
class Group<T extends GroupAttrs = GroupAttrs>
|
|
14
|
-
extends Element<T>
|
|
15
|
-
implements IGroupElement<T>
|
|
16
|
-
{
|
|
17
|
-
constructor(data?: Partial<ElementRawData>) {
|
|
18
|
-
super(data)
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
_init(): void {
|
|
22
|
-
this._nameType ??= NameTypes.GROUP
|
|
23
|
-
super._init()
|
|
24
|
-
this.data.type = EntityTypes.GROUP
|
|
25
|
-
this.data.children = []
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
load(data: GroupDataType): void {
|
|
29
|
-
super.load(data)
|
|
30
|
-
this.data.children = (data.children as string[]) || []
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
create(): void {
|
|
34
|
-
super.create()
|
|
35
|
-
this.data.type = EntityTypes.GROUP
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
save(): GroupRawData {
|
|
39
|
-
const data = super.save() as GroupRawData
|
|
40
|
-
data.children = this.data.children
|
|
41
|
-
return data
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
addElement(element: ElementInstanceTypes, index = -1) {
|
|
45
|
-
if (!element) {
|
|
46
|
-
return
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
const children = [...this.get('children')]
|
|
50
|
-
const idx = index ?? children.length
|
|
51
|
-
children.splice(idx, 0, element.get('id'))
|
|
52
|
-
this.set('children', children)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
removeElement(element: ElementInstanceTypes, index: number) {
|
|
56
|
-
if (!element) {
|
|
57
|
-
return
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
const children = [...this.get('children')]
|
|
61
|
-
if (children.indexOf(element.get('id')) !== index) {
|
|
62
|
-
return
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
children.splice(index, 1)
|
|
66
|
-
this.set('children', children)
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
export default Group
|
package/src/components/index.ts
DELETED
package/src/components/props.ts
DELETED
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { PropertyTypes } from '@asyra/utils'
|
|
2
|
-
import type {
|
|
3
|
-
PropertyComponentInstanceDataTypes,
|
|
4
|
-
PropsRawData
|
|
5
|
-
} from '@asyra/utils'
|
|
6
|
-
import { removeProperty } from '@asyra/reactive-events'
|
|
7
|
-
import propsManager from '@asyra/props-manager'
|
|
8
|
-
|
|
9
|
-
type PropsDataType = Partial<PropsRawData>
|
|
10
|
-
|
|
11
|
-
const PROP_NAMES: PropertyTypes[] = [
|
|
12
|
-
PropertyTypes.POSITION,
|
|
13
|
-
PropertyTypes.DIMENSION
|
|
14
|
-
]
|
|
15
|
-
|
|
16
|
-
type AliasKeys = 'x' | 'y' | 'width' | 'height'
|
|
17
|
-
|
|
18
|
-
const PROP_ALIAS: Record<AliasKeys, PropertyTypes> = {
|
|
19
|
-
x: PropertyTypes.POSITION,
|
|
20
|
-
y: PropertyTypes.POSITION,
|
|
21
|
-
width: PropertyTypes.DIMENSION,
|
|
22
|
-
height: PropertyTypes.DIMENSION
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
class Props {
|
|
26
|
-
elementId: string
|
|
27
|
-
position?: PropsRawData[PropertyTypes.POSITION]
|
|
28
|
-
dimension?: PropsRawData[PropertyTypes.DIMENSION]
|
|
29
|
-
|
|
30
|
-
constructor(elementId: string, data?: PropsDataType) {
|
|
31
|
-
this.elementId = elementId
|
|
32
|
-
|
|
33
|
-
if (data) {
|
|
34
|
-
this.load(data)
|
|
35
|
-
} else {
|
|
36
|
-
this.init()
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
init() {
|
|
41
|
-
const propertyComponents = PROP_NAMES.map((propName) =>
|
|
42
|
-
propsManager.createProperty({ type: propName })
|
|
43
|
-
)
|
|
44
|
-
const propIdsMap = propsManager.addProperty(propertyComponents)
|
|
45
|
-
propsManager.commitChanges()
|
|
46
|
-
if (!propIdsMap) {
|
|
47
|
-
return
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
PROP_NAMES.forEach((propName) => {
|
|
51
|
-
this[propName] = propIdsMap[propName]
|
|
52
|
-
})
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
load(data: PropsDataType = {}): void {
|
|
56
|
-
PROP_NAMES.forEach((propName) => {
|
|
57
|
-
this[propName] = data[propName]
|
|
58
|
-
})
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
save(): PropsRawData {
|
|
62
|
-
return PROP_NAMES.reduce((acc, propName) => {
|
|
63
|
-
const key = propName as keyof PropsRawData
|
|
64
|
-
acc[key] = this[key] as string
|
|
65
|
-
return acc
|
|
66
|
-
}, {} as PropsRawData)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
updateData<K extends keyof PropertyComponentInstanceDataTypes>(
|
|
70
|
-
key: K,
|
|
71
|
-
data: PropertyComponentInstanceDataTypes[K]
|
|
72
|
-
) {
|
|
73
|
-
const propName = (PROP_ALIAS[key] || key) as PropertyTypes
|
|
74
|
-
const propComponentId = this[propName]
|
|
75
|
-
if (!propComponentId) {
|
|
76
|
-
return
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
propsManager.updatePropsData(propComponentId, key, data)
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
cleanup() {
|
|
83
|
-
const removedPropertyIds = PROP_NAMES.map((propName) => ({
|
|
84
|
-
id: this[propName]
|
|
85
|
-
}))
|
|
86
|
-
removeProperty(removedPropertyIds)
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
export default Props
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import type { RectangleRawData } from '@asyra/utils'
|
|
2
|
-
import { EntityTypes, NameTypes } from '@asyra/utils'
|
|
3
|
-
import Element from './element'
|
|
4
|
-
|
|
5
|
-
type RectangleDataType = Partial<RectangleRawData>
|
|
6
|
-
|
|
7
|
-
class Rectangle extends Element {
|
|
8
|
-
constructor(data?: Partial<RectangleRawData>) {
|
|
9
|
-
super(data)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
_init(): void {
|
|
13
|
-
this._nameType = NameTypes.RECTANGLE
|
|
14
|
-
super._init()
|
|
15
|
-
this.data.type = EntityTypes.RECTANGLE
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
create(): void {
|
|
19
|
-
super.create()
|
|
20
|
-
this.data.type = EntityTypes.RECTANGLE
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
load(data: RectangleDataType): void {
|
|
24
|
-
super.load(data)
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export default Rectangle
|
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
WorkspaceRawData,
|
|
3
|
-
ElementInstanceTypes,
|
|
4
|
-
GroupInstanceTypes,
|
|
5
|
-
IElement
|
|
6
|
-
} from '@asyra/utils'
|
|
7
|
-
import { isGroupEntity, IDTypes, NameTypes, EntityTypes } from '@asyra/utils'
|
|
8
|
-
import Group from './group'
|
|
9
|
-
import sceneTree from '../sceneTree'
|
|
10
|
-
|
|
11
|
-
type WorkspaceDataType = Partial<WorkspaceRawData>
|
|
12
|
-
|
|
13
|
-
class Workspace extends Group {
|
|
14
|
-
constructor() {
|
|
15
|
-
super()
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
_init(): void {
|
|
19
|
-
this._idType = IDTypes.WORKSPACE
|
|
20
|
-
this._nameType = NameTypes.WORKSPACE
|
|
21
|
-
super._init()
|
|
22
|
-
this.data.type = EntityTypes.WORKSPACE
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
create(): void {
|
|
26
|
-
super.create()
|
|
27
|
-
this.data.type = EntityTypes.WORKSPACE
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
load(data: WorkspaceDataType): void {
|
|
31
|
-
super.load(data)
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get firstFrame(): ElementInstanceTypes | null {
|
|
35
|
-
let result = null
|
|
36
|
-
|
|
37
|
-
const children = this.get('children')
|
|
38
|
-
for (const childId of children) {
|
|
39
|
-
const child = sceneTree.getElementById(childId)
|
|
40
|
-
if (
|
|
41
|
-
child &&
|
|
42
|
-
isGroupEntity(child.get('type')) &&
|
|
43
|
-
(child as GroupInstanceTypes).get('children')
|
|
44
|
-
) {
|
|
45
|
-
result = child
|
|
46
|
-
break
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return result
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
addNewElement(
|
|
54
|
-
element: ElementInstanceTypes,
|
|
55
|
-
parent?: GroupInstanceTypes,
|
|
56
|
-
index = -1
|
|
57
|
-
) {
|
|
58
|
-
if (!element) {
|
|
59
|
-
return
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
let avaliableParent = parent
|
|
63
|
-
if (!avaliableParent) {
|
|
64
|
-
const firstFrame = this.firstFrame
|
|
65
|
-
if (firstFrame) {
|
|
66
|
-
avaliableParent = this.firstFrame as GroupInstanceTypes
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
if (avaliableParent && avaliableParent.get('children')) {
|
|
71
|
-
// Add new element to Group type instance
|
|
72
|
-
avaliableParent.addElement(element, index)
|
|
73
|
-
} else {
|
|
74
|
-
// Add new element to Workspace
|
|
75
|
-
const originalChildrenList = [...this.get('children')]
|
|
76
|
-
const idx = index > -1 ? index : this.get('children').length
|
|
77
|
-
originalChildrenList.splice(idx, 0, element.get('id'))
|
|
78
|
-
this.set('children', originalChildrenList)
|
|
79
|
-
}
|
|
80
|
-
sceneTree.addToMap(element)
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
removeElement(element: IElement, index: number, parent?: GroupInstanceTypes) {
|
|
84
|
-
if (!element) {
|
|
85
|
-
return
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
let avaliableParent = parent
|
|
89
|
-
if (!avaliableParent) {
|
|
90
|
-
const firstFrame = this.firstFrame
|
|
91
|
-
if (firstFrame) {
|
|
92
|
-
avaliableParent = this.firstFrame as GroupInstanceTypes
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
const elementId = element.get('id')
|
|
97
|
-
if (avaliableParent && avaliableParent.get('children')) {
|
|
98
|
-
// Remove element from Group type instance
|
|
99
|
-
const idx = index ?? avaliableParent?.get('children').indexOf(elementId)
|
|
100
|
-
avaliableParent.removeElement(element, idx)
|
|
101
|
-
} else {
|
|
102
|
-
// Add new element to Workspace
|
|
103
|
-
const originalChildrenList = [...this.get('children')]
|
|
104
|
-
const idx = index ?? this.get('children').indexOf(elementId)
|
|
105
|
-
originalChildrenList.splice(idx, 1)
|
|
106
|
-
this.set('children', originalChildrenList)
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
element.cleanup()
|
|
110
|
-
|
|
111
|
-
// Remove element from Workspace
|
|
112
|
-
sceneTree.removeFromMap(element)
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
export default Workspace
|