@asyra/props-manager 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/components/base.d.ts +12 -2
- package/dist/components/base.d.ts.map +1 -1
- package/dist/components/base.js +78 -4
- package/dist/components/base.js.map +1 -1
- package/dist/components/index.d.ts +4 -4
- package/dist/components/index.d.ts.map +1 -1
- package/dist/components/index.js +2 -3
- package/dist/components/index.js.map +1 -1
- package/dist/components/props-change-handler.d.ts +2 -1
- package/dist/components/props-change-handler.d.ts.map +1 -1
- package/dist/components/props-change-handler.js +2 -3
- package/dist/components/props-change-handler.js.map +1 -1
- package/dist/factories/create-property.d.ts +6 -0
- package/dist/factories/create-property.d.ts.map +1 -0
- package/dist/factories/create-property.js +24 -0
- package/dist/factories/create-property.js.map +1 -0
- package/dist/index.d.ts +19 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +12 -3
- package/dist/index.js.map +1 -1
- package/dist/manager/component-accessor.d.ts +12 -0
- package/dist/manager/component-accessor.d.ts.map +1 -0
- package/dist/manager/component-accessor.js +23 -0
- package/dist/manager/component-accessor.js.map +1 -0
- package/dist/manager/props-manager.d.ts +209 -0
- package/dist/manager/props-manager.d.ts.map +1 -0
- package/dist/manager/props-manager.js +3848 -0
- package/dist/manager/props-manager.js.map +1 -0
- package/dist/manager/subscribes.d.ts.map +1 -0
- package/dist/manager/subscribes.js +76 -0
- package/dist/manager/subscribes.js.map +1 -0
- package/dist/registries/declarative-property-type.d.ts +39 -0
- package/dist/registries/declarative-property-type.d.ts.map +1 -0
- package/dist/registries/declarative-property-type.js +482 -0
- package/dist/registries/declarative-property-type.js.map +1 -0
- package/dist/registries/property-component.d.ts +50 -0
- package/dist/registries/property-component.d.ts.map +1 -0
- package/dist/registries/property-component.js +151 -0
- package/dist/registries/property-component.js.map +1 -0
- package/dist/registries/property-definition-value.d.ts +5 -0
- package/dist/registries/property-definition-value.d.ts.map +1 -0
- package/dist/registries/property-definition-value.js +19 -0
- package/dist/registries/property-definition-value.js.map +1 -0
- package/dist/registries/property-definition.d.ts +48 -0
- package/dist/registries/property-definition.d.ts.map +1 -0
- package/dist/registries/property-definition.js +107 -0
- package/dist/registries/property-definition.js.map +1 -0
- package/dist/registries/property-registration.d.ts +36 -0
- package/dist/registries/property-registration.d.ts.map +1 -0
- package/dist/registries/property-registration.js +61 -0
- package/dist/registries/property-registration.js.map +1 -0
- package/dist/registries/property-schema.d.ts +19 -0
- package/dist/registries/property-schema.d.ts.map +1 -0
- package/dist/registries/property-schema.js +75 -0
- package/dist/registries/property-schema.js.map +1 -0
- package/dist/registries/property-value-kind.d.ts +3 -0
- package/dist/registries/property-value-kind.d.ts.map +1 -0
- package/dist/registries/property-value-kind.js +18 -0
- package/dist/registries/property-value-kind.js.map +1 -0
- package/dist/registries/registration-options.d.ts +4 -0
- package/dist/registries/registration-options.d.ts.map +1 -0
- package/dist/registries/registration-options.js +2 -0
- package/dist/registries/registration-options.js.map +1 -0
- package/dist/registries/state.d.ts +14 -0
- package/dist/registries/state.d.ts.map +1 -0
- package/dist/registries/state.js +53 -0
- package/dist/registries/state.js.map +1 -0
- package/package.json +24 -4
- package/.turbo/turbo-test$colon$ci.log +0 -130
- package/.turbo/turbo-test$colon$local.log +0 -50
- package/.turbo/turbo-test.log +0 -0
- package/CHANGELOG.md +0 -46
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -368
- package/coverage/coverage-final.json +0 -5904
- 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/base.ts.html +0 -262
- package/coverage/src/components/dimension.ts.html +0 -253
- package/coverage/src/components/index.html +0 -176
- package/coverage/src/components/index.ts.html +0 -106
- package/coverage/src/components/position.ts.html +0 -250
- package/coverage/src/components/props-change-handler.ts.html +0 -145
- package/coverage/src/index.html +0 -161
- package/coverage/src/index.ts.html +0 -106
- package/coverage/src/props-manager.ts.html +0 -574
- package/coverage/src/subscribes.ts.html +0 -247
- package/coverage/src/utils.ts.html +0 -226
- package/dist/__tests__/props-manager.test.d.ts +0 -2
- package/dist/__tests__/props-manager.test.d.ts.map +0 -1
- package/dist/__tests__/props-manager.test.js +0 -290
- package/dist/__tests__/props-manager.test.js.map +0 -1
- package/dist/components/dimension.d.ts +0 -12
- package/dist/components/dimension.d.ts.map +0 -1
- package/dist/components/dimension.js +0 -43
- package/dist/components/dimension.js.map +0 -1
- package/dist/components/position.d.ts +0 -12
- package/dist/components/position.d.ts.map +0 -1
- package/dist/components/position.js +0 -42
- package/dist/components/position.js.map +0 -1
- package/dist/props-manager.d.ts +0 -28
- package/dist/props-manager.d.ts.map +0 -1
- package/dist/props-manager.js +0 -120
- package/dist/props-manager.js.map +0 -1
- package/dist/subscribes.d.ts.map +0 -1
- package/dist/subscribes.js +0 -35
- package/dist/subscribes.js.map +0 -1
- package/dist/utils.d.ts +0 -3
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js +0 -31
- package/dist/utils.js.map +0 -1
- package/src/__tests__/props-manager.test.ts +0 -362
- package/src/components/base.ts +0 -59
- package/src/components/dimension.ts +0 -56
- package/src/components/index.ts +0 -7
- package/src/components/position.ts +0 -55
- package/src/components/props-change-handler.ts +0 -20
- package/src/index.ts +0 -7
- package/src/props-manager.ts +0 -163
- package/src/subscribes.ts +0 -54
- package/src/utils.ts +0 -47
- package/tsconfig.json +0 -17
- /package/dist/{subscribes.d.ts → manager/subscribes.d.ts} +0 -0
package/dist/utils.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { PropertyTypes, DefaultPositionData, DefaultDimensionData, id, loadId, IDTypes, isNil } from '@asyra/utils';
|
|
2
|
-
import { PositionComponent, DimensionComponent } from './components';
|
|
3
|
-
const PropClassMap = {
|
|
4
|
-
[PropertyTypes.POSITION]: PositionComponent,
|
|
5
|
-
[PropertyTypes.DIMENSION]: DimensionComponent
|
|
6
|
-
};
|
|
7
|
-
const DefaultDataMap = {
|
|
8
|
-
[PropertyTypes.POSITION]: DefaultPositionData,
|
|
9
|
-
[PropertyTypes.DIMENSION]: DefaultDimensionData
|
|
10
|
-
};
|
|
11
|
-
export const createProperty = (data) => {
|
|
12
|
-
const type = data.type;
|
|
13
|
-
const PropClass = PropClassMap[type];
|
|
14
|
-
if (!PropClass) {
|
|
15
|
-
return;
|
|
16
|
-
}
|
|
17
|
-
let comId = data.id;
|
|
18
|
-
if (isNil(comId)) {
|
|
19
|
-
comId = id(IDTypes.PROPS);
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
loadId(data.id, IDTypes.PROPS);
|
|
23
|
-
}
|
|
24
|
-
const defaultData = DefaultDataMap[type];
|
|
25
|
-
return new PropClass({
|
|
26
|
-
id: comId,
|
|
27
|
-
...defaultData,
|
|
28
|
-
...data
|
|
29
|
-
});
|
|
30
|
-
};
|
|
31
|
-
//# sourceMappingURL=utils.js.map
|
package/dist/utils.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,aAAa,EAEb,mBAAmB,EACnB,oBAAoB,EACpB,EAAE,EACF,MAAM,EACN,OAAO,EAEP,KAAK,EACN,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,iBAAiB,EACjB,kBAAkB,EAEnB,MAAM,cAAc,CAAA;AAErB,MAAM,YAAY,GAAiD;IACjE,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,iBAAiB;IAC3C,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,kBAAkB;CAC9C,CAAA;AACD,MAAM,cAAc,GAAkC;IACpD,CAAC,aAAa,CAAC,QAAQ,CAAC,EAAE,mBAAmB;IAC7C,CAAC,aAAa,CAAC,SAAS,CAAC,EAAE,oBAAoB;CAChD,CAAA;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAuC,EAAE,EAAE;IACxE,MAAM,IAAI,GAAG,IAAI,CAAC,IAAqB,CAAA;IACvC,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,CAAA;IACpC,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAM;IACR,CAAC;IAED,IAAI,KAAK,GAAG,IAAI,CAAC,EAAE,CAAA;IACnB,IAAI,KAAK,CAAC,KAAK,CAAC,EAAE,CAAC;QACjB,KAAK,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IAC3B,CAAC;SAAM,CAAC;QACN,MAAM,CAAC,IAAI,CAAC,EAAY,EAAE,OAAO,CAAC,KAAK,CAAC,CAAA;IAC1C,CAAC;IACD,MAAM,WAAW,GAAG,cAAc,CAAC,IAAI,CAAC,CAAA;IAExC,OAAO,IAAI,SAAS,CAAC;QACnB,EAAE,EAAE,KAAK;QACT,GAAG,WAAW;QACd,GAAG,IAAI;KACR,CAAmC,CAAA;AACtC,CAAC,CAAA"}
|
|
@@ -1,362 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
2
|
-
import * as ReactiveEventsModule from '@asyra/reactive-events'
|
|
3
|
-
import {
|
|
4
|
-
PROPS_ACTIONS,
|
|
5
|
-
PropertyComponentInstanceTypes,
|
|
6
|
-
PropertyComponentInstanceDataTypes,
|
|
7
|
-
PropertyTypes,
|
|
8
|
-
Unit,
|
|
9
|
-
PropsChange
|
|
10
|
-
} from '@asyra/utils'
|
|
11
|
-
import { PropsManager } from '../props-manager'
|
|
12
|
-
import { createProperty } from '../utils'
|
|
13
|
-
|
|
14
|
-
vi.mock('@asyra/reactive-events', async (importOriginal) => {
|
|
15
|
-
const actual = await importOriginal<typeof import('@asyra/reactive-events')>()
|
|
16
|
-
|
|
17
|
-
return {
|
|
18
|
-
...actual,
|
|
19
|
-
updateTransaction: vi.fn()
|
|
20
|
-
}
|
|
21
|
-
})
|
|
22
|
-
|
|
23
|
-
describe('PropsManager', () => {
|
|
24
|
-
let propsManager: PropsManager
|
|
25
|
-
|
|
26
|
-
beforeEach(() => {
|
|
27
|
-
vi.clearAllMocks()
|
|
28
|
-
|
|
29
|
-
propsManager = new PropsManager()
|
|
30
|
-
})
|
|
31
|
-
|
|
32
|
-
// Test load and save
|
|
33
|
-
it('should load data correctly', () => {
|
|
34
|
-
const dataToLoad = {
|
|
35
|
-
'pp-1': {
|
|
36
|
-
id: 'pp-1',
|
|
37
|
-
type: PropertyTypes.POSITION,
|
|
38
|
-
x: 0,
|
|
39
|
-
y: 0,
|
|
40
|
-
xUnit: Unit.PX,
|
|
41
|
-
yUnit: Unit.PX
|
|
42
|
-
},
|
|
43
|
-
'pp-2': {
|
|
44
|
-
id: 'pp-2',
|
|
45
|
-
type: PropertyTypes.DIMENSION,
|
|
46
|
-
width: 100,
|
|
47
|
-
height: 100,
|
|
48
|
-
widthUnit: Unit.PX,
|
|
49
|
-
heightUnit: Unit.PX
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
propsManager.load(dataToLoad)
|
|
54
|
-
|
|
55
|
-
expect(propsManager.getComponentById('pp-1')?.get('id')).toBe('pp-1')
|
|
56
|
-
expect(propsManager.getComponentById('pp-2')?.get('id')).toBe('pp-2')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should save data correctly', () => {
|
|
60
|
-
const dataToLoad = {
|
|
61
|
-
'pp-1': {
|
|
62
|
-
id: 'pp-1',
|
|
63
|
-
type: PropertyTypes.POSITION,
|
|
64
|
-
x: 0,
|
|
65
|
-
y: 0,
|
|
66
|
-
xUnit: Unit.PX,
|
|
67
|
-
yUnit: Unit.PX
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
propsManager.load(dataToLoad)
|
|
71
|
-
|
|
72
|
-
const savedData = propsManager.save()
|
|
73
|
-
|
|
74
|
-
expect(savedData['pp-1']).toEqual(dataToLoad['pp-1'])
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
// Test change tracking
|
|
78
|
-
it('should add a change to the changes array', () => {
|
|
79
|
-
const change = {
|
|
80
|
-
eventName: ReactiveEventsModule.EventTypes.ADD_PROPERTY
|
|
81
|
-
} as unknown as PropsChange
|
|
82
|
-
|
|
83
|
-
propsManager.addChange(change)
|
|
84
|
-
|
|
85
|
-
expect(propsManager.changes).toEqual([change])
|
|
86
|
-
})
|
|
87
|
-
|
|
88
|
-
it('should clean all changes', () => {
|
|
89
|
-
propsManager.addChange({} as unknown as PropsChange)
|
|
90
|
-
|
|
91
|
-
propsManager.cleanChanges()
|
|
92
|
-
|
|
93
|
-
expect(propsManager.changes).toEqual([])
|
|
94
|
-
})
|
|
95
|
-
|
|
96
|
-
it('should add a change for adding a property', () => {
|
|
97
|
-
const p1Data = {
|
|
98
|
-
id: 'pp-1',
|
|
99
|
-
type: PropertyTypes.POSITION,
|
|
100
|
-
x: 0,
|
|
101
|
-
y: 0,
|
|
102
|
-
xUnit: Unit.PX,
|
|
103
|
-
yUnit: Unit.PX
|
|
104
|
-
}
|
|
105
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
106
|
-
|
|
107
|
-
propsManager.addChangeForAddProperty(p1Component)
|
|
108
|
-
|
|
109
|
-
expect(propsManager.changes.length).toBe(1)
|
|
110
|
-
expect(propsManager.changes[0].action).toBe(PROPS_ACTIONS.ADD_PROPERTY)
|
|
111
|
-
})
|
|
112
|
-
|
|
113
|
-
it('should add a change for removing a property', () => {
|
|
114
|
-
const p1Data = {
|
|
115
|
-
id: 'pp-1',
|
|
116
|
-
type: PropertyTypes.POSITION,
|
|
117
|
-
x: 0,
|
|
118
|
-
y: 0,
|
|
119
|
-
xUnit: Unit.PX,
|
|
120
|
-
yUnit: Unit.PX
|
|
121
|
-
}
|
|
122
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
123
|
-
|
|
124
|
-
propsManager.addChangeForRemoveProperty(p1Component)
|
|
125
|
-
|
|
126
|
-
expect(propsManager.changes.length).toBe(1)
|
|
127
|
-
expect(propsManager.changes[0].action).toBe(PROPS_ACTIONS.REMOVE_PROPERTY)
|
|
128
|
-
})
|
|
129
|
-
|
|
130
|
-
// Test component management
|
|
131
|
-
it('should get a component by ID', () => {
|
|
132
|
-
const p1Data = {
|
|
133
|
-
id: 'pp-1',
|
|
134
|
-
type: PropertyTypes.POSITION,
|
|
135
|
-
x: 0,
|
|
136
|
-
y: 0,
|
|
137
|
-
xUnit: Unit.PX,
|
|
138
|
-
yUnit: Unit.PX
|
|
139
|
-
}
|
|
140
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
141
|
-
|
|
142
|
-
propsManager.addToMap(p1Component)
|
|
143
|
-
|
|
144
|
-
expect(propsManager.getComponentById('pp-1')).toBe(p1Component)
|
|
145
|
-
})
|
|
146
|
-
|
|
147
|
-
it('should add a component to the map', () => {
|
|
148
|
-
const p1Data = {
|
|
149
|
-
id: 'pp-1',
|
|
150
|
-
type: PropertyTypes.POSITION,
|
|
151
|
-
x: 0,
|
|
152
|
-
y: 0,
|
|
153
|
-
xUnit: Unit.PX,
|
|
154
|
-
yUnit: Unit.PX
|
|
155
|
-
}
|
|
156
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
157
|
-
|
|
158
|
-
propsManager.addToMap(p1Component)
|
|
159
|
-
|
|
160
|
-
expect(propsManager._components.has('pp-1')).toBe(true)
|
|
161
|
-
})
|
|
162
|
-
|
|
163
|
-
it('should remove a component from the map', () => {
|
|
164
|
-
const p1Data = {
|
|
165
|
-
id: 'pp-1',
|
|
166
|
-
type: PropertyTypes.POSITION,
|
|
167
|
-
x: 0,
|
|
168
|
-
y: 0,
|
|
169
|
-
xUnit: Unit.PX,
|
|
170
|
-
yUnit: Unit.PX
|
|
171
|
-
}
|
|
172
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
173
|
-
propsManager.addToMap(p1Component)
|
|
174
|
-
|
|
175
|
-
propsManager.removeFromMap('pp-1')
|
|
176
|
-
|
|
177
|
-
expect(propsManager._components.has('pp-1')).toBe(false)
|
|
178
|
-
})
|
|
179
|
-
|
|
180
|
-
// Test deleted map functionality
|
|
181
|
-
it('should add a component to the deleted map', () => {
|
|
182
|
-
const p1Data = {
|
|
183
|
-
id: 'pp-1',
|
|
184
|
-
type: PropertyTypes.POSITION,
|
|
185
|
-
x: 0,
|
|
186
|
-
y: 0,
|
|
187
|
-
xUnit: Unit.PX,
|
|
188
|
-
yUnit: Unit.PX
|
|
189
|
-
}
|
|
190
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
191
|
-
|
|
192
|
-
propsManager.addToDeletedMap(p1Component)
|
|
193
|
-
|
|
194
|
-
expect(propsManager._deletedMap.has('pp-1')).toBe(true)
|
|
195
|
-
})
|
|
196
|
-
|
|
197
|
-
it('should remove a component from the deleted map', () => {
|
|
198
|
-
const p1Data = {
|
|
199
|
-
id: 'pp-1',
|
|
200
|
-
type: PropertyTypes.POSITION,
|
|
201
|
-
x: 0,
|
|
202
|
-
y: 0,
|
|
203
|
-
xUnit: Unit.PX,
|
|
204
|
-
yUnit: Unit.PX
|
|
205
|
-
}
|
|
206
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
207
|
-
propsManager.addToDeletedMap(p1Component)
|
|
208
|
-
|
|
209
|
-
propsManager.removeFromDeletedMap('pp-1')
|
|
210
|
-
|
|
211
|
-
expect(propsManager._deletedMap.has('pp-1')).toBe(false)
|
|
212
|
-
})
|
|
213
|
-
|
|
214
|
-
it('should get a restored component by ID', () => {
|
|
215
|
-
const p1Data = {
|
|
216
|
-
id: 'pp-1',
|
|
217
|
-
type: PropertyTypes.POSITION,
|
|
218
|
-
x: 0,
|
|
219
|
-
y: 0,
|
|
220
|
-
xUnit: Unit.PX,
|
|
221
|
-
yUnit: Unit.PX
|
|
222
|
-
}
|
|
223
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
224
|
-
|
|
225
|
-
propsManager.addToDeletedMap(p1Component)
|
|
226
|
-
expect(propsManager.getRestoreComponentById('pp-1')).toBe(p1Component)
|
|
227
|
-
})
|
|
228
|
-
|
|
229
|
-
// Test createProperty
|
|
230
|
-
it('should create a property and add a change', () => {
|
|
231
|
-
const p1Data = {
|
|
232
|
-
id: 'pp-1',
|
|
233
|
-
type: PropertyTypes.POSITION,
|
|
234
|
-
x: 0,
|
|
235
|
-
y: 0,
|
|
236
|
-
xUnit: Unit.PX,
|
|
237
|
-
yUnit: Unit.PX
|
|
238
|
-
}
|
|
239
|
-
const newProp = propsManager.createProperty(p1Data)
|
|
240
|
-
|
|
241
|
-
expect(newProp?.get('id')).toBe('pp-1')
|
|
242
|
-
expect(propsManager.changes.length).toBe(1)
|
|
243
|
-
expect(propsManager.changes[0].action).toBe(PROPS_ACTIONS.ADD_PROPERTY)
|
|
244
|
-
})
|
|
245
|
-
|
|
246
|
-
it('should throw error if type is not provided for createProperty', () => {
|
|
247
|
-
expect(() => propsManager.createProperty({})).toThrow('Type is required!')
|
|
248
|
-
})
|
|
249
|
-
|
|
250
|
-
// Test addProperty
|
|
251
|
-
it('should add multiple properties and return their IDs mapped by type', () => {
|
|
252
|
-
const p1Data = {
|
|
253
|
-
id: 'pp-1',
|
|
254
|
-
type: PropertyTypes.POSITION,
|
|
255
|
-
x: 0,
|
|
256
|
-
y: 0,
|
|
257
|
-
xUnit: Unit.PX,
|
|
258
|
-
yUnit: Unit.PX
|
|
259
|
-
}
|
|
260
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
261
|
-
const p2Data = {
|
|
262
|
-
id: 'pp-2',
|
|
263
|
-
type: PropertyTypes.DIMENSION,
|
|
264
|
-
width: 100,
|
|
265
|
-
height: 100,
|
|
266
|
-
widthUnit: Unit.PX,
|
|
267
|
-
heightUnit: Unit.PX
|
|
268
|
-
}
|
|
269
|
-
const p2Component = createProperty(p2Data) as PropertyComponentInstanceTypes
|
|
270
|
-
|
|
271
|
-
const result = propsManager.addProperty([p1Component, p2Component])
|
|
272
|
-
|
|
273
|
-
expect(propsManager._components.has('pp-1')).toBe(true)
|
|
274
|
-
expect(propsManager._components.has('pp-2')).toBe(true)
|
|
275
|
-
expect(result).toEqual({
|
|
276
|
-
[PropertyTypes.POSITION]: 'pp-1',
|
|
277
|
-
[PropertyTypes.DIMENSION]: 'pp-2'
|
|
278
|
-
})
|
|
279
|
-
})
|
|
280
|
-
|
|
281
|
-
// Test removeProperty
|
|
282
|
-
it('should remove multiple properties', () => {
|
|
283
|
-
const p1Data = {
|
|
284
|
-
id: 'pp-1',
|
|
285
|
-
type: PropertyTypes.POSITION,
|
|
286
|
-
x: 0,
|
|
287
|
-
y: 0,
|
|
288
|
-
xUnit: Unit.PX,
|
|
289
|
-
yUnit: Unit.PX
|
|
290
|
-
}
|
|
291
|
-
const p1Component = createProperty(p1Data) as PropertyComponentInstanceTypes
|
|
292
|
-
propsManager.addToMap(p1Component)
|
|
293
|
-
const p2Data = {
|
|
294
|
-
id: 'pp-2',
|
|
295
|
-
type: PropertyTypes.POSITION,
|
|
296
|
-
x: 0,
|
|
297
|
-
y: 0,
|
|
298
|
-
xUnit: Unit.PX,
|
|
299
|
-
yUnit: Unit.PX
|
|
300
|
-
}
|
|
301
|
-
const p2Component = createProperty(p2Data) as PropertyComponentInstanceTypes
|
|
302
|
-
propsManager.addToMap(p2Component)
|
|
303
|
-
|
|
304
|
-
propsManager.removeProperty(['pp-1', 'pp-2'])
|
|
305
|
-
|
|
306
|
-
expect(propsManager._components.has('pp-1')).toBe(false)
|
|
307
|
-
expect(propsManager._components.has('pp-2')).toBe(false)
|
|
308
|
-
expect(propsManager._deletedMap.has('pp-1')).toBe(true)
|
|
309
|
-
expect(propsManager._deletedMap.has('pp-2')).toBe(true)
|
|
310
|
-
})
|
|
311
|
-
|
|
312
|
-
// Test updatePropsData
|
|
313
|
-
it('should update props data on a component', () => {
|
|
314
|
-
const positionData = {
|
|
315
|
-
id: 'pp-1',
|
|
316
|
-
type: PropertyTypes.POSITION,
|
|
317
|
-
x: 0,
|
|
318
|
-
y: 0,
|
|
319
|
-
xUnit: Unit.PX,
|
|
320
|
-
yUnit: Unit.PX
|
|
321
|
-
}
|
|
322
|
-
const positionComponent = createProperty(
|
|
323
|
-
positionData
|
|
324
|
-
) as PropertyComponentInstanceTypes
|
|
325
|
-
vi.spyOn(positionComponent, 'set')
|
|
326
|
-
|
|
327
|
-
propsManager.addToMap(positionComponent)
|
|
328
|
-
// Type assertion needed because updatePropsData uses union type for keys
|
|
329
|
-
// 'x' is a valid key for PositionAttrs, which is part of PropertyComponentInstanceDataTypes
|
|
330
|
-
propsManager.updatePropsData(
|
|
331
|
-
'pp-1',
|
|
332
|
-
'x' as unknown as keyof PropertyComponentInstanceDataTypes,
|
|
333
|
-
100 as unknown as PropertyComponentInstanceDataTypes[keyof PropertyComponentInstanceDataTypes]
|
|
334
|
-
)
|
|
335
|
-
expect(positionComponent.set).toHaveBeenCalledWith('x', 100)
|
|
336
|
-
})
|
|
337
|
-
|
|
338
|
-
// Test commitChanges
|
|
339
|
-
it('should commit changes and clean the changes array', () => {
|
|
340
|
-
const change1 = {
|
|
341
|
-
eventName: ReactiveEventsModule.EventTypes.ADD_PROPERTY
|
|
342
|
-
} as unknown as PropsChange
|
|
343
|
-
const change2 = {
|
|
344
|
-
eventName: ReactiveEventsModule.EventTypes.REMOVE_PROPERTY
|
|
345
|
-
} as unknown as PropsChange
|
|
346
|
-
propsManager.addChange(change1)
|
|
347
|
-
propsManager.addChange(change2)
|
|
348
|
-
|
|
349
|
-
propsManager.commitChanges()
|
|
350
|
-
|
|
351
|
-
expect(ReactiveEventsModule.updateTransaction).toHaveBeenCalledTimes(2)
|
|
352
|
-
expect(ReactiveEventsModule.updateTransaction).toHaveBeenCalledWith(
|
|
353
|
-
change1.eventName,
|
|
354
|
-
change1
|
|
355
|
-
)
|
|
356
|
-
expect(ReactiveEventsModule.updateTransaction).toHaveBeenCalledWith(
|
|
357
|
-
change2.eventName,
|
|
358
|
-
change2
|
|
359
|
-
)
|
|
360
|
-
expect(propsManager.changes).toEqual([])
|
|
361
|
-
})
|
|
362
|
-
})
|
package/src/components/base.ts
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
IProperty,
|
|
3
|
-
PositionAttrs,
|
|
4
|
-
PropertyComponentInstanceDataTypes,
|
|
5
|
-
PropertyComponentRawData
|
|
6
|
-
} from '@asyra/utils'
|
|
7
|
-
import { Setter, Unit, isNil } from '@asyra/utils'
|
|
8
|
-
import PropsChangeHandler from './props-change-handler'
|
|
9
|
-
|
|
10
|
-
const propsChangeHandler = new PropsChangeHandler()
|
|
11
|
-
|
|
12
|
-
abstract class BaseComponent<
|
|
13
|
-
T extends PropertyComponentInstanceDataTypes = PositionAttrs
|
|
14
|
-
>
|
|
15
|
-
extends Setter<T>
|
|
16
|
-
implements IProperty
|
|
17
|
-
{
|
|
18
|
-
propNames!: string[]
|
|
19
|
-
|
|
20
|
-
constructor() {
|
|
21
|
-
super(propsChangeHandler.addChange)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
_init(data: Partial<T>) {
|
|
25
|
-
Object.keys(data).forEach((dataKey) => {
|
|
26
|
-
const key = dataKey as keyof T
|
|
27
|
-
if (this.isValidKey(key) && !isNil(data[key])) {
|
|
28
|
-
this.data[key] = data[key] as T[Extract<keyof T, string>]
|
|
29
|
-
}
|
|
30
|
-
})
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
update(data: Partial<T>) {
|
|
34
|
-
Object.keys(data).forEach((dataKey) => {
|
|
35
|
-
const key = dataKey as keyof T
|
|
36
|
-
if (this.isValidKey(key) && !isNil(data[key])) {
|
|
37
|
-
this.set(key, data[key] as T[Extract<keyof T, string>])
|
|
38
|
-
}
|
|
39
|
-
})
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
abstract getValue(): Record<string, number>
|
|
43
|
-
abstract getUnit(): Record<string, Unit>
|
|
44
|
-
|
|
45
|
-
protected isValidKey(key: keyof T) {
|
|
46
|
-
return key in this.data
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
abstract load(data: PropertyComponentRawData): void
|
|
50
|
-
|
|
51
|
-
save(): PropertyComponentRawData {
|
|
52
|
-
return {
|
|
53
|
-
id: this.get('id'),
|
|
54
|
-
type: this.get('type')
|
|
55
|
-
} as PropertyComponentRawData
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
export default BaseComponent
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
Unit,
|
|
3
|
-
PropertyTypes,
|
|
4
|
-
DefaultDimensionData,
|
|
5
|
-
DimensionAttrs,
|
|
6
|
-
DimensionComponentRawData
|
|
7
|
-
} from '@asyra/utils'
|
|
8
|
-
import BaseComponent from './base'
|
|
9
|
-
|
|
10
|
-
class DimensionComponent extends BaseComponent<DimensionAttrs> {
|
|
11
|
-
data: DimensionAttrs = {
|
|
12
|
-
id: '',
|
|
13
|
-
type: PropertyTypes.DIMENSION,
|
|
14
|
-
...DefaultDimensionData
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
constructor(data: Partial<DimensionAttrs>) {
|
|
18
|
-
super()
|
|
19
|
-
|
|
20
|
-
this.data.type = PropertyTypes.DIMENSION
|
|
21
|
-
this._init(data)
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
save(): DimensionComponentRawData {
|
|
25
|
-
return {
|
|
26
|
-
...super.save(),
|
|
27
|
-
width: this.get('width'),
|
|
28
|
-
height: this.get('height'),
|
|
29
|
-
widthUnit: this.get('widthUnit'),
|
|
30
|
-
heightUnit: this.get('heightUnit')
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
load(data: DimensionComponentRawData): void {
|
|
35
|
-
this.data.width = data.width
|
|
36
|
-
this.data.height = data.height
|
|
37
|
-
this.data.widthUnit = data.widthUnit
|
|
38
|
-
this.data.heightUnit = data.heightUnit
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
getValue(): Record<string, number> {
|
|
42
|
-
return {
|
|
43
|
-
width: this.data.width,
|
|
44
|
-
height: this.data.height
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getUnit(): Record<string, Unit> {
|
|
49
|
-
return {
|
|
50
|
-
widthUnit: this.data.widthUnit,
|
|
51
|
-
heightUnit: this.data.heightUnit
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
export default DimensionComponent
|
package/src/components/index.ts
DELETED
|
@@ -1,55 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DefaultPositionData,
|
|
3
|
-
PositionAttrs,
|
|
4
|
-
PositionComponentRawData,
|
|
5
|
-
PropertyTypes,
|
|
6
|
-
Unit
|
|
7
|
-
} from '@asyra/utils'
|
|
8
|
-
import BaseComponent from './base'
|
|
9
|
-
|
|
10
|
-
class PositionComponent extends BaseComponent<PositionAttrs> {
|
|
11
|
-
data: PositionAttrs = {
|
|
12
|
-
id: '',
|
|
13
|
-
type: PropertyTypes.POSITION,
|
|
14
|
-
...DefaultPositionData
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
constructor(data: Partial<PositionAttrs>) {
|
|
18
|
-
super()
|
|
19
|
-
|
|
20
|
-
this._init(data)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
save(): PositionComponentRawData {
|
|
24
|
-
return {
|
|
25
|
-
...super.save(),
|
|
26
|
-
x: this.get('x'),
|
|
27
|
-
y: this.get('y'),
|
|
28
|
-
xUnit: this.get('xUnit'),
|
|
29
|
-
yUnit: this.get('yUnit')
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
load(data: PositionComponentRawData): void {
|
|
34
|
-
this.data.x = data.x
|
|
35
|
-
this.data.y = data.y
|
|
36
|
-
this.data.xUnit = data.xUnit
|
|
37
|
-
this.data.yUnit = data.yUnit
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
getValue(): Record<string, number> {
|
|
41
|
-
return {
|
|
42
|
-
x: this.data.x,
|
|
43
|
-
y: this.data.y
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
getUnit(): Record<string, Unit> {
|
|
48
|
-
return {
|
|
49
|
-
xUnit: this.data.xUnit,
|
|
50
|
-
yUnit: this.data.yUnit
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
export default PositionComponent
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import type { ChangeHandler, DataTypes } from '@asyra/utils'
|
|
2
|
-
import { OWNER, PROPS_ACTIONS } from '@asyra/utils'
|
|
3
|
-
import { EventTypes } from '@asyra/reactive-events'
|
|
4
|
-
import propsManager from '../props-manager'
|
|
5
|
-
|
|
6
|
-
export default class PropsChangeHandler implements ChangeHandler {
|
|
7
|
-
addChange(data: {
|
|
8
|
-
id: string
|
|
9
|
-
key: string
|
|
10
|
-
before: DataTypes
|
|
11
|
-
after: DataTypes
|
|
12
|
-
}): void {
|
|
13
|
-
propsManager.addChange({
|
|
14
|
-
action: PROPS_ACTIONS.UPDATE_PROPERTY,
|
|
15
|
-
owner: OWNER.SCENE_TREE,
|
|
16
|
-
eventName: EventTypes.UPDATE_PROPERTY,
|
|
17
|
-
...data
|
|
18
|
-
})
|
|
19
|
-
}
|
|
20
|
-
}
|