@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.
Files changed (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -1
  3. package/dist/component-registry.d.ts +24 -0
  4. package/dist/component-registry.d.ts.map +1 -0
  5. package/dist/component-registry.js +26 -0
  6. package/dist/component-registry.js.map +1 -0
  7. package/dist/components/computed.d.ts +9 -6
  8. package/dist/components/computed.d.ts.map +1 -1
  9. package/dist/components/computed.js +37 -28
  10. package/dist/components/computed.js.map +1 -1
  11. package/dist/components/element-change-handler.d.ts +4 -3
  12. package/dist/components/element-change-handler.d.ts.map +1 -1
  13. package/dist/components/element-change-handler.js +21 -9
  14. package/dist/components/element-change-handler.js.map +1 -1
  15. package/dist/components/element.d.ts +19 -11
  16. package/dist/components/element.d.ts.map +1 -1
  17. package/dist/components/element.js +61 -31
  18. package/dist/components/element.js.map +1 -1
  19. package/dist/components/group.d.ts +9 -4
  20. package/dist/components/group.d.ts.map +1 -1
  21. package/dist/components/group.js +16 -12
  22. package/dist/components/group.js.map +1 -1
  23. package/dist/components/index.d.ts +3 -5
  24. package/dist/components/index.d.ts.map +1 -1
  25. package/dist/components/index.js +3 -5
  26. package/dist/components/index.js.map +1 -1
  27. package/dist/components/props.d.ts +12 -7
  28. package/dist/components/props.d.ts.map +1 -1
  29. package/dist/components/props.js +64 -20
  30. package/dist/components/props.js.map +1 -1
  31. package/dist/components/workspace.d.ts +9 -5
  32. package/dist/components/workspace.d.ts.map +1 -1
  33. package/dist/components/workspace.js +62 -36
  34. package/dist/components/workspace.js.map +1 -1
  35. package/dist/create-dynamic-component.d.ts +5 -0
  36. package/dist/create-dynamic-component.d.ts.map +1 -0
  37. package/dist/create-dynamic-component.js +53 -0
  38. package/dist/create-dynamic-component.js.map +1 -0
  39. package/dist/create-dynamic-props.d.ts +4 -0
  40. package/dist/create-dynamic-props.d.ts.map +1 -0
  41. package/dist/create-dynamic-props.js +104 -0
  42. package/dist/create-dynamic-props.js.map +1 -0
  43. package/dist/element-mutation.d.ts +92 -0
  44. package/dist/element-mutation.d.ts.map +1 -0
  45. package/dist/element-mutation.js +2 -0
  46. package/dist/element-mutation.js.map +1 -0
  47. package/dist/entity-data.d.ts +16 -0
  48. package/dist/entity-data.d.ts.map +1 -0
  49. package/dist/{utils.js → entity-data.js} +34 -22
  50. package/dist/entity-data.js.map +1 -0
  51. package/dist/index.d.ts +9 -2
  52. package/dist/index.d.ts.map +1 -1
  53. package/dist/index.js +8 -3
  54. package/dist/index.js.map +1 -1
  55. package/dist/props-manager-context.d.ts +6 -0
  56. package/dist/props-manager-context.d.ts.map +1 -0
  57. package/dist/props-manager-context.js +26 -0
  58. package/dist/props-manager-context.js.map +1 -0
  59. package/dist/sceneTree.d.ts +105 -10
  60. package/dist/sceneTree.d.ts.map +1 -1
  61. package/dist/sceneTree.js +3308 -96
  62. package/dist/sceneTree.js.map +1 -1
  63. package/dist/subscribes.d.ts.map +1 -1
  64. package/dist/subscribes.js +188 -24
  65. package/dist/subscribes.js.map +1 -1
  66. package/dist/types.d.ts +26 -0
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/types.js +2 -0
  69. package/dist/types.js.map +1 -0
  70. package/package.json +24 -5
  71. package/.turbo/turbo-test$colon$ci.log +0 -134
  72. package/.turbo/turbo-test$colon$local.log +0 -31
  73. package/.turbo/turbo-test.log +0 -53
  74. package/CHANGELOG.md +0 -51
  75. package/coverage/base.css +0 -224
  76. package/coverage/block-navigation.js +0 -87
  77. package/coverage/clover.xml +0 -778
  78. package/coverage/coverage-final.json +0 -10478
  79. package/coverage/favicon.png +0 -0
  80. package/coverage/index.html +0 -131
  81. package/coverage/prettify.css +0 -1
  82. package/coverage/prettify.js +0 -2
  83. package/coverage/sort-arrow-sprite.png +0 -0
  84. package/coverage/sorter.js +0 -196
  85. package/coverage/src/components/computed.ts.html +0 -313
  86. package/coverage/src/components/element-change-handler.ts.html +0 -145
  87. package/coverage/src/components/element.ts.html +0 -586
  88. package/coverage/src/components/frame.ts.html +0 -169
  89. package/coverage/src/components/group.ts.html +0 -295
  90. package/coverage/src/components/index.html +0 -236
  91. package/coverage/src/components/index.ts.html +0 -103
  92. package/coverage/src/components/props.ts.html +0 -355
  93. package/coverage/src/components/rectangle.ts.html +0 -169
  94. package/coverage/src/components/workspace.ts.html +0 -433
  95. package/coverage/src/index.html +0 -161
  96. package/coverage/src/index.ts.html +0 -103
  97. package/coverage/src/sceneTree.ts.html +0 -853
  98. package/coverage/src/subscribes.ts.html +0 -295
  99. package/coverage/src/utils.ts.html +0 -328
  100. package/dist/__tests__/sceneTree.test.d.ts +0 -2
  101. package/dist/__tests__/sceneTree.test.d.ts.map +0 -1
  102. package/dist/__tests__/sceneTree.test.js +0 -261
  103. package/dist/__tests__/sceneTree.test.js.map +0 -1
  104. package/dist/components/frame.d.ts +0 -11
  105. package/dist/components/frame.d.ts.map +0 -1
  106. package/dist/components/frame.js +0 -21
  107. package/dist/components/frame.js.map +0 -1
  108. package/dist/components/legacy-element.d.ts +0 -22
  109. package/dist/components/legacy-element.d.ts.map +0 -1
  110. package/dist/components/legacy-element.js +0 -120
  111. package/dist/components/legacy-element.js.map +0 -1
  112. package/dist/components/polygon.d.ts +0 -11
  113. package/dist/components/polygon.d.ts.map +0 -1
  114. package/dist/components/polygon.js +0 -21
  115. package/dist/components/polygon.js.map +0 -1
  116. package/dist/components/rectangle.d.ts +0 -11
  117. package/dist/components/rectangle.d.ts.map +0 -1
  118. package/dist/components/rectangle.js +0 -21
  119. package/dist/components/rectangle.js.map +0 -1
  120. package/dist/components/shape-entity.d.ts +0 -16
  121. package/dist/components/shape-entity.d.ts.map +0 -1
  122. package/dist/components/shape-entity.js +0 -42
  123. package/dist/components/shape-entity.js.map +0 -1
  124. package/dist/components/shape.d.ts +0 -40
  125. package/dist/components/shape.d.ts.map +0 -1
  126. package/dist/components/shape.js +0 -105
  127. package/dist/components/shape.js.map +0 -1
  128. package/dist/utils.d.ts +0 -19
  129. package/dist/utils.d.ts.map +0 -1
  130. package/dist/utils.js.map +0 -1
  131. package/src/__tests__/sceneTree.test.ts +0 -339
  132. package/src/components/computed.ts +0 -76
  133. package/src/components/element-change-handler.ts +0 -20
  134. package/src/components/element.ts +0 -167
  135. package/src/components/frame.ts +0 -28
  136. package/src/components/group.ts +0 -70
  137. package/src/components/index.ts +0 -6
  138. package/src/components/props.ts +0 -90
  139. package/src/components/rectangle.ts +0 -28
  140. package/src/components/workspace.ts +0 -116
  141. package/src/index.ts +0 -6
  142. package/src/sceneTree.ts +0 -256
  143. package/src/subscribes.ts +0 -70
  144. package/src/utils.ts +0 -81
  145. 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
@@ -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
@@ -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
@@ -1,6 +0,0 @@
1
- import Rectangle from './rectangle'
2
- import Group from './group'
3
- import Frame from './frame'
4
- import Workspace from './workspace'
5
-
6
- export { Rectangle, Group, Frame, Workspace }
@@ -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
package/src/index.ts DELETED
@@ -1,6 +0,0 @@
1
- import { initSceneTreeSubscribes } from './subscribes'
2
-
3
- initSceneTreeSubscribes()
4
-
5
- export * from './components'
6
- export { default, SceneTree } from './sceneTree'