@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
package/src/sceneTree.ts
DELETED
|
@@ -1,256 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
ComputedAttrs,
|
|
3
|
-
SceneTreeRawData,
|
|
4
|
-
WorkspaceRawData,
|
|
5
|
-
ElementRawData,
|
|
6
|
-
ElementInstanceTypes,
|
|
7
|
-
GroupInstanceTypes,
|
|
8
|
-
SceneTreeChange,
|
|
9
|
-
EVENT_OPTIONS,
|
|
10
|
-
CreateElementData
|
|
11
|
-
} from '@asyra/utils'
|
|
12
|
-
import { EntityTypes, OWNER, SCENE_TREE_ACTIONS } from '@asyra/utils'
|
|
13
|
-
import { EventTypes, updateTransaction } from '@asyra/reactive-events'
|
|
14
|
-
import propsManager from '@asyra/props-manager'
|
|
15
|
-
import { createElement, createWorkspace, stripNonRawFields } from './utils'
|
|
16
|
-
import type Workspace from './components/workspace'
|
|
17
|
-
|
|
18
|
-
type SceneTreeDataType = SceneTreeRawData
|
|
19
|
-
|
|
20
|
-
class SceneTree {
|
|
21
|
-
_elements: Map<string, ElementInstanceTypes> = new Map()
|
|
22
|
-
_deletedMap: Map<string, ElementInstanceTypes> = new Map()
|
|
23
|
-
workspace: string = ''
|
|
24
|
-
workspaceList: string[] = []
|
|
25
|
-
changes: SceneTreeChange[] = []
|
|
26
|
-
|
|
27
|
-
_init(): void {
|
|
28
|
-
if (!this.workspace && !this.workspaceList.length) {
|
|
29
|
-
const initWorkspace = createWorkspace() as ElementInstanceTypes
|
|
30
|
-
if (initWorkspace) {
|
|
31
|
-
this.addToMap(initWorkspace)
|
|
32
|
-
this.workspaceList = [initWorkspace.get('id')]
|
|
33
|
-
this.workspace = this.workspaceList[0]
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
init() {
|
|
39
|
-
this._init()
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
load(data: SceneTreeDataType) {
|
|
43
|
-
if (!data) return
|
|
44
|
-
|
|
45
|
-
if (data.elements) {
|
|
46
|
-
for (const elementId in data.elements) {
|
|
47
|
-
const elementData = data.elements[elementId]
|
|
48
|
-
let element
|
|
49
|
-
if (elementData.type === EntityTypes.WORKSPACE) {
|
|
50
|
-
element = createWorkspace(elementData as WorkspaceRawData)
|
|
51
|
-
} else {
|
|
52
|
-
element = createElement(elementData)
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
this.addToMap(element as ElementInstanceTypes)
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
if (data.workspace) {
|
|
60
|
-
this.workspace = data.workspace
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
if (data.workspaceList) {
|
|
64
|
-
this.workspaceList = data.workspaceList
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
save() {
|
|
69
|
-
const data: SceneTreeRawData = {
|
|
70
|
-
workspace: this.workspace,
|
|
71
|
-
workspaceList: this.workspaceList,
|
|
72
|
-
elements: {}
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
this._elements.forEach((element, id) => {
|
|
76
|
-
data.elements[id] = element.save()
|
|
77
|
-
})
|
|
78
|
-
|
|
79
|
-
return data
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
addChange(change: SceneTreeChange) {
|
|
83
|
-
this.changes.push(change)
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
cleanChanges() {
|
|
87
|
-
this.changes = []
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
getAllElements() {
|
|
91
|
-
return this._elements
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
getElementById(elementId: string): ElementInstanceTypes | undefined {
|
|
95
|
-
return this._elements.get(elementId)
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
addToMap(element: ElementInstanceTypes) {
|
|
99
|
-
const elId = element.get('id')
|
|
100
|
-
if (!element || !elId) {
|
|
101
|
-
return
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
this.removeFromDeleteMap(elId)
|
|
105
|
-
this._elements.set(elId, element)
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
removeFromMap(element: ElementInstanceTypes) {
|
|
109
|
-
const elId = element.get('id')
|
|
110
|
-
if (!element || !elId) {
|
|
111
|
-
return
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
this.addToDeleteMap(element)
|
|
115
|
-
this._elements.delete(elId)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
getRestoreElementById(elementId: string): ElementInstanceTypes {
|
|
119
|
-
const restoredElement = this._deletedMap.get(
|
|
120
|
-
elementId
|
|
121
|
-
) as ElementInstanceTypes
|
|
122
|
-
this.addChangeForAddElement(restoredElement)
|
|
123
|
-
return restoredElement
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
addToDeleteMap(element: ElementInstanceTypes) {
|
|
127
|
-
this._deletedMap.set(element.get('id'), element)
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
removeFromDeleteMap(elementId: string) {
|
|
131
|
-
this._deletedMap.delete(elementId)
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
addChangeForAddElement(element: ElementInstanceTypes) {
|
|
135
|
-
this.addChange({
|
|
136
|
-
eventName: EventTypes.ADD_ELEMENT,
|
|
137
|
-
data: element.save(),
|
|
138
|
-
action: SCENE_TREE_ACTIONS.ADD_ELEMENT,
|
|
139
|
-
owner: OWNER.SCENE_TREE,
|
|
140
|
-
undoType: EventTypes.REMOVE_ELEMENT,
|
|
141
|
-
undoAction: EventTypes.REMOVE_ELEMENT
|
|
142
|
-
})
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
addChangeForRemoveElement(element: ElementInstanceTypes) {
|
|
146
|
-
this.addChange({
|
|
147
|
-
eventName: EventTypes.REMOVE_ELEMENT,
|
|
148
|
-
data: element.save(),
|
|
149
|
-
action: SCENE_TREE_ACTIONS.REMOVE_ELEMENT,
|
|
150
|
-
owner: OWNER.SCENE_TREE,
|
|
151
|
-
undoType: EventTypes.ADD_ELEMENT,
|
|
152
|
-
undoAction: EventTypes.ADD_ELEMENT
|
|
153
|
-
})
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
get currentWorkspace() {
|
|
157
|
-
return this.getElementById(this.workspace)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
createElement(
|
|
161
|
-
elementData: Partial<ElementRawData>
|
|
162
|
-
): ElementInstanceTypes | null {
|
|
163
|
-
if (elementData.type === EntityTypes.WORKSPACE) {
|
|
164
|
-
return null
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const newElement = createElement(elementData) as ElementInstanceTypes
|
|
168
|
-
this.addChangeForAddElement(newElement)
|
|
169
|
-
return newElement
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
addNewElement(
|
|
173
|
-
elementData: CreateElementData,
|
|
174
|
-
parent?: GroupInstanceTypes,
|
|
175
|
-
index = -1,
|
|
176
|
-
inUndoRedo = false
|
|
177
|
-
): string {
|
|
178
|
-
const workspace = this.currentWorkspace as Workspace
|
|
179
|
-
if (!workspace) {
|
|
180
|
-
return ''
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
let newElement: ElementInstanceTypes | null = null
|
|
184
|
-
|
|
185
|
-
const propOverrides = stripNonRawFields(elementData)
|
|
186
|
-
if (inUndoRedo) {
|
|
187
|
-
newElement = this.getRestoreElementById(elementData.id as string)
|
|
188
|
-
} else {
|
|
189
|
-
newElement = this.createElement(elementData)
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
if (newElement) {
|
|
193
|
-
// Override props after finish creating new instance
|
|
194
|
-
Object.keys(propOverrides).forEach((propKey) => {
|
|
195
|
-
newElement.updateComputedData(
|
|
196
|
-
propKey as keyof ComputedAttrs,
|
|
197
|
-
propOverrides[propKey]
|
|
198
|
-
)
|
|
199
|
-
})
|
|
200
|
-
propsManager.commitChanges()
|
|
201
|
-
|
|
202
|
-
workspace.addNewElement(newElement, parent, index)
|
|
203
|
-
|
|
204
|
-
this.commitSceneTreeTransaction()
|
|
205
|
-
|
|
206
|
-
return newElement.get('id')
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
return ''
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
removeElement(
|
|
213
|
-
data: Partial<ElementRawData>,
|
|
214
|
-
index: number,
|
|
215
|
-
parent?: GroupInstanceTypes
|
|
216
|
-
) {
|
|
217
|
-
const workspace = this.currentWorkspace as Workspace
|
|
218
|
-
if (!workspace) {
|
|
219
|
-
return
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
const elementId = data.id as string
|
|
223
|
-
const element = this.getElementById(elementId)
|
|
224
|
-
if (!element) {
|
|
225
|
-
return
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
this.addChangeForRemoveElement(element)
|
|
229
|
-
workspace.removeElement(element, index, parent)
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
updateComputedData<K extends keyof ComputedAttrs>(
|
|
233
|
-
elementId: string,
|
|
234
|
-
key: K,
|
|
235
|
-
data: ComputedAttrs[K]
|
|
236
|
-
) {
|
|
237
|
-
const element = this.getElementById(elementId)
|
|
238
|
-
if (!element) {
|
|
239
|
-
return
|
|
240
|
-
}
|
|
241
|
-
|
|
242
|
-
element.updateComputedData(key, data)
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
commitSceneTreeTransaction(options?: EVENT_OPTIONS) {
|
|
246
|
-
this.changes.forEach((change) => {
|
|
247
|
-
updateTransaction(change.eventName, change, options)
|
|
248
|
-
})
|
|
249
|
-
this.cleanChanges()
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
|
|
253
|
-
export { SceneTree }
|
|
254
|
-
|
|
255
|
-
const sceneTree = new SceneTree()
|
|
256
|
-
export default sceneTree
|
package/src/subscribes.ts
DELETED
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
subscribeToRemoveElement,
|
|
3
|
-
subscribeToChangeComputedData,
|
|
4
|
-
subscribeToUpdateComputedData,
|
|
5
|
-
subscribeToSceneTreeInit,
|
|
6
|
-
subscribeToSceneTreeLoadData,
|
|
7
|
-
subscribeToAddElement,
|
|
8
|
-
subscribeToUpdateUndoRedoStatus
|
|
9
|
-
} from '@asyra/reactive-events'
|
|
10
|
-
import { CreateElementData, UNDO, type ComputedAttrs } from '@asyra/utils'
|
|
11
|
-
import sceneTree from './sceneTree'
|
|
12
|
-
|
|
13
|
-
export const initSceneTreeSubscribes = () => {
|
|
14
|
-
let inUndoRedo = false
|
|
15
|
-
subscribeToUpdateUndoRedoStatus(({ payload }) => {
|
|
16
|
-
inUndoRedo = payload.status !== UNDO.NONE
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
subscribeToSceneTreeInit(() => {
|
|
20
|
-
sceneTree.init()
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
subscribeToSceneTreeLoadData(({ payload }) => {
|
|
24
|
-
sceneTree.load(payload.data)
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
subscribeToAddElement(({ payload }) => {
|
|
28
|
-
const { data, parent, index } = payload
|
|
29
|
-
sceneTree.addNewElement(
|
|
30
|
-
data as CreateElementData,
|
|
31
|
-
parent,
|
|
32
|
-
index,
|
|
33
|
-
inUndoRedo
|
|
34
|
-
)
|
|
35
|
-
|
|
36
|
-
sceneTree.commitSceneTreeTransaction()
|
|
37
|
-
})
|
|
38
|
-
|
|
39
|
-
subscribeToRemoveElement(({ payload }) => {
|
|
40
|
-
const { data, parent, index } = payload
|
|
41
|
-
sceneTree.removeElement(data, index, parent)
|
|
42
|
-
|
|
43
|
-
sceneTree.commitSceneTreeTransaction()
|
|
44
|
-
})
|
|
45
|
-
|
|
46
|
-
subscribeToChangeComputedData(async ({ payload, options }) => {
|
|
47
|
-
const { elementIds, key, data } = payload
|
|
48
|
-
|
|
49
|
-
elementIds.forEach((elementId) => {
|
|
50
|
-
type KEY = keyof ComputedAttrs
|
|
51
|
-
sceneTree.updateComputedData(
|
|
52
|
-
elementId,
|
|
53
|
-
key as KEY,
|
|
54
|
-
data as ComputedAttrs[KEY]
|
|
55
|
-
)
|
|
56
|
-
})
|
|
57
|
-
sceneTree.commitSceneTreeTransaction(options)
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
subscribeToUpdateComputedData(({ payload }) => {
|
|
61
|
-
const { id, key, after } = payload
|
|
62
|
-
|
|
63
|
-
sceneTree.updateComputedData(
|
|
64
|
-
id,
|
|
65
|
-
key as keyof ComputedAttrs,
|
|
66
|
-
after as ComputedAttrs[keyof ComputedAttrs]
|
|
67
|
-
)
|
|
68
|
-
sceneTree.commitSceneTreeTransaction()
|
|
69
|
-
})
|
|
70
|
-
}
|
package/src/utils.ts
DELETED
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
import { ComputedAttrs, ElementRawData, EntityTypes } from '@asyra/utils'
|
|
2
|
-
import Frame from './components/frame'
|
|
3
|
-
import Group from './components/group'
|
|
4
|
-
import Rectangle from './components/rectangle'
|
|
5
|
-
import Workspace from './components/workspace'
|
|
6
|
-
|
|
7
|
-
const entityClassMap = {
|
|
8
|
-
[EntityTypes.UNDEFINED]: undefined,
|
|
9
|
-
[EntityTypes.FRAME]: Frame,
|
|
10
|
-
[EntityTypes.GROUP]: Group,
|
|
11
|
-
[EntityTypes.RECTANGLE]: Rectangle,
|
|
12
|
-
[EntityTypes.OVAL]: Rectangle // FIXME: Change this after finish OVAL component
|
|
13
|
-
} as const
|
|
14
|
-
|
|
15
|
-
const initWorkspaceData = {
|
|
16
|
-
type: EntityTypes.WORKSPACE
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
export const createElement = (elementData: Partial<ElementRawData>) => {
|
|
20
|
-
if (
|
|
21
|
-
elementData.type === EntityTypes.WORKSPACE ||
|
|
22
|
-
elementData.type === EntityTypes.ELEMENT ||
|
|
23
|
-
elementData.type === EntityTypes.UNDEFINED
|
|
24
|
-
) {
|
|
25
|
-
return null
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const elementType = elementData.type ?? EntityTypes.UNDEFINED
|
|
29
|
-
const EntityClass = entityClassMap[elementType]
|
|
30
|
-
if (!EntityClass) {
|
|
31
|
-
throw new Error('Ivalid entity type.')
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
// Already know what type we need, and it should be insert by the component itself
|
|
35
|
-
delete elementData.type
|
|
36
|
-
|
|
37
|
-
return new EntityClass(elementData)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
export const createWorkspace = (workspaceData = initWorkspaceData) => {
|
|
41
|
-
if (workspaceData.type !== EntityTypes.WORKSPACE) {
|
|
42
|
-
return null
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
const newWorkspace = new Workspace()
|
|
46
|
-
newWorkspace.load(workspaceData)
|
|
47
|
-
return newWorkspace
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
|
51
|
-
type UnknownObject = Record<string, any>
|
|
52
|
-
|
|
53
|
-
const DefaultRawKeys: (keyof ElementRawData)[] = ['id', 'type', 'name', 'props']
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* Removes non-raw fields from an element object and returns the stripped fields.
|
|
57
|
-
*
|
|
58
|
-
* @param elementData - The original element object which may contain extra fields.
|
|
59
|
-
* @param rawKeys - Keys that should be kept in the original object (defaults to ElementRawData keys).
|
|
60
|
-
* @returns An object containing the stripped (non-raw) fields.
|
|
61
|
-
*/
|
|
62
|
-
export const stripNonRawFields = (
|
|
63
|
-
elementData: UnknownObject,
|
|
64
|
-
rawKeys: (keyof ElementRawData)[] = DefaultRawKeys
|
|
65
|
-
): Record<string, ComputedAttrs[keyof ComputedAttrs]> => {
|
|
66
|
-
const stripped = {} as UnknownObject
|
|
67
|
-
|
|
68
|
-
for (const key in elementData) {
|
|
69
|
-
if (!rawKeys.includes(key as keyof ElementRawData)) {
|
|
70
|
-
stripped[key] = elementData[key]
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
// Remove all non-raw keys from the original object
|
|
75
|
-
Object.keys(stripped).forEach((key) => {
|
|
76
|
-
/* eslint-disable-next-line @typescript-eslint/no-dynamic-delete */
|
|
77
|
-
delete elementData[key]
|
|
78
|
-
})
|
|
79
|
-
|
|
80
|
-
return stripped
|
|
81
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"module": "ESNext",
|
|
5
|
-
"declaration": true,
|
|
6
|
-
"declarationMap": true,
|
|
7
|
-
"sourceMap": true,
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"strict": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"skipLibCheck": true,
|
|
12
|
-
"moduleResolution": "Node",
|
|
13
|
-
"resolveJsonModule": true
|
|
14
|
-
},
|
|
15
|
-
"include": ["src"],
|
|
16
|
-
"exclude": ["node_modules", "dist"]
|
|
17
|
-
}
|