dyo-tools 0.3.2 → 0.4.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/.c8rc.json +4 -4
- package/.eslintignore +1 -1
- package/.eslintrc.json +47 -47
- package/Makefile +34 -34
- package/dist/constants.d.ts +1 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +24 -20
- package/dist/constants.js.map +1 -1
- package/dist/core/DTAction.d.ts +6 -4
- package/dist/core/DTAction.d.ts.map +1 -0
- package/dist/core/DTAction.js +3 -6
- package/dist/core/DTAction.js.map +1 -1
- package/dist/core/DTBunch.d.ts +8 -5
- package/dist/core/DTBunch.d.ts.map +1 -0
- package/dist/core/DTBunch.js +53 -19
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponent.d.ts +13 -10
- package/dist/core/DTComponent.d.ts.map +1 -0
- package/dist/core/DTComponent.js +23 -10
- package/dist/core/DTComponent.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +11 -8
- package/dist/core/DTComponentPhysical.d.ts.map +1 -0
- package/dist/core/DTComponentPhysical.js +21 -6
- package/dist/core/DTComponentPhysical.js.map +1 -1
- package/dist/core/DTComponentWithMeta.d.ts +6 -3
- package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
- package/dist/core/DTComponentWithMeta.js +21 -7
- package/dist/core/DTComponentWithMeta.js.map +1 -1
- package/dist/core/DTElement.d.ts +10 -8
- package/dist/core/DTElement.d.ts.map +1 -0
- package/dist/core/DTElement.js +8 -9
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTError.d.ts +8 -7
- package/dist/core/DTError.d.ts.map +1 -0
- package/dist/core/DTError.js +1 -5
- package/dist/core/DTError.js.map +1 -1
- package/dist/core/DTManager.d.ts +17 -14
- package/dist/core/DTManager.d.ts.map +1 -0
- package/dist/core/DTManager.js +84 -26
- package/dist/core/DTManager.js.map +1 -1
- package/dist/core/DTMaster.d.ts +19 -16
- package/dist/core/DTMaster.d.ts.map +1 -0
- package/dist/core/DTMaster.js +48 -31
- package/dist/core/DTMaster.js.map +1 -1
- package/dist/core/DTModule.d.ts +8 -5
- package/dist/core/DTModule.d.ts.map +1 -0
- package/dist/core/DTModule.js +6 -6
- package/dist/core/DTModule.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +12 -28
- package/dist/index.js.map +1 -1
- package/dist/libs/DYOFinder.d.ts +1 -0
- package/dist/libs/DYOFinder.d.ts.map +1 -0
- package/dist/libs/DYOFinder.js +10 -14
- package/dist/libs/DYOFinder.js.map +1 -1
- package/dist/libs/dix/DIXModule.module.d.ts +8 -0
- package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
- package/dist/libs/dix/DIXModule.module.js +73 -0
- package/dist/libs/player/DTPlayer.element.d.ts +3 -2
- package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.element.js +2 -6
- package/dist/libs/player/DTPlayer.element.js.map +1 -1
- package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
- package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
- package/dist/libs/player/DTPlayer.manager.js +13 -20
- package/dist/libs/player/DTPlayer.manager.js.map +1 -1
- package/dist/tsconfig.dev.tsbuildinfo +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/core.d.ts +40 -12
- package/dist/types/core.d.ts.map +1 -0
- package/dist/types/core.js +2 -6
- package/dist/types/core.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +2 -19
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +1 -1
- package/dist/types/player.d.ts.map +1 -0
- package/dist/types/player.js +1 -3
- package/integration/data/components/DTHero.ts +42 -0
- package/integration/data/components/DTHeroManager.ts +11 -0
- package/integration/data/components/DTHeroPlayZone.ts +6 -0
- package/integration/data/components/DTHeroPlayerHand.ts +11 -0
- package/integration/data/components/index.ts +5 -0
- package/integration/data/in/heroIn.helper.ts +8 -0
- package/integration/data/in/playerIn.helper.ts +13 -0
- package/integration/data/out/heroOut.helper.ts +48 -0
- package/integration/endings/synchronisation.ending.ts +25 -0
- package/integration/scenes/drawCard.scene.ts +31 -0
- package/integration/scenes/empty.scene.ts +6 -0
- package/integration/scenes/playCard.scene.ts +23 -0
- package/integration/scenes/playerLeave.scene.ts +33 -0
- package/integration/stages/baseDix.stage.ts +137 -0
- package/integration/stages/syncDix.stage.ts +36 -0
- package/integration/tests/scenario1.spec.ts +55 -0
- package/integration/types/index.ts +24 -0
- package/jest-integration.config.ts +25 -0
- package/jest.config.ts +26 -0
- package/package.json +31 -19
- package/src/constants.ts +2 -0
- package/src/core/DTAction.ts +7 -5
- package/src/core/DTBunch.ts +78 -14
- package/src/core/DTComponent.ts +48 -15
- package/src/core/DTComponentPhysical.ts +45 -11
- package/src/core/DTComponentWithMeta.ts +37 -4
- package/src/core/DTElement.ts +19 -10
- package/src/core/DTError.ts +7 -7
- package/src/core/DTManager.ts +120 -30
- package/src/core/DTMaster.ts +76 -28
- package/src/core/DTModule.ts +12 -6
- package/src/index.ts +17 -17
- package/src/libs/DYOFinder.ts +175 -175
- package/src/libs/dix/DIXModule.module.ts +98 -0
- package/src/libs/player/DTPlayer.element.ts +2 -2
- package/src/libs/player/DTPlayer.manager.ts +20 -34
- package/src/types/core.ts +39 -4
- package/src/types/index.ts +2 -2
- package/src/types/player.ts +0 -1
- package/test/core/DTAction.double.ts +12 -28
- package/test/core/DTAction.spec.ts +8 -16
- package/test/core/DTBunch.double.ts +49 -135
- package/test/core/DTBunch.spec.ts +157 -245
- package/test/core/DTComponent.double.ts +17 -2
- package/test/core/DTComponent.spec.ts +6 -4
- package/test/core/DTComponentPhysical.double.ts +29 -43
- package/test/core/DTComponentPhysical.spec.ts +22 -19
- package/test/core/DTComponentWithMeta.double.ts +38 -31
- package/test/core/DTComponentWithMeta.spec.ts +23 -18
- package/test/core/DTElement.double.ts +32 -53
- package/test/core/DTElement.spec.ts +15 -38
- package/test/core/DTError.double.ts +18 -53
- package/test/core/DTError.spec.ts +21 -32
- package/test/core/DTManager.double.ts +74 -141
- package/test/core/DTManager.spec.ts +289 -380
- package/test/core/DTMaster.double.ts +56 -80
- package/test/core/DTMaster.spec.ts +185 -232
- package/test/core/DTModule.double.ts +12 -25
- package/test/core/DTModule.spec.ts +14 -28
- package/test/core/copy.spec.ts +9 -30
- package/tsconfig.dev.json +5 -8
- package/tsconfig.json +5 -8
- package/cucumber-report.html +0 -48
- package/docs/assets/navigation.js +0 -1
- package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
- package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
- package/docs/classes/core_DTError.DYOToolsError.html +0 -37
- package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
- package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
- package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
- package/docs/enums/types_core.FilterOperatorType.html +0 -10
- package/docs/hierarchy.html +0 -1
- package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
- package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
- package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
- package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
- package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
- package/docs/interfaces/types_core.DTElementToObject.html +0 -7
- package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
- package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
- package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
- package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
- package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
- package/docs/modules/constants.html +0 -6
- package/docs/modules/core_DTAction.html +0 -2
- package/docs/modules/core_DTBunch.html +0 -2
- package/docs/modules/core_DTComponent.html +0 -2
- package/docs/modules/core_DTComponentPhysical.html +0 -2
- package/docs/modules/core_DTComponentWithMeta.html +0 -2
- package/docs/modules/core_DTElement.html +0 -2
- package/docs/modules/core_DTError.html +0 -2
- package/docs/modules/core_DTManager.html +0 -2
- package/docs/modules/core_DTMaster.html +0 -2
- package/docs/modules/core_DTModule.html +0 -2
- package/docs/modules/libs_DYOFinder.html +0 -2
- package/docs/modules/libs_player_DTPlayer_element.html +0 -2
- package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
- package/docs/modules/types.html +0 -29
- package/docs/modules/types_core.html +0 -28
- package/docs/modules/types_player.html +0 -2
- package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
- package/docs/types/types_core.DTManagerItemType.html +0 -1
- package/docs/types/types_core.DTManagerItemsType.html +0 -2
- package/docs/types/types_core.DYOFinderComponentType.html +0 -1
- package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
- package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
- package/docs/types/types_core.DYOFinderFilters.html +0 -1
- package/docs/types/types_core.StandardPrimitiveType.html +0 -2
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
- package/docs/variables/constants.bunchDefaultOptions.html +0 -2
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
- package/docs/variables/constants.managerDefaultOptions.html +0 -2
- package/jest.config.js +0 -6
package/src/core/DTManager.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import DTComponent from './DTComponent';
|
|
2
|
+
import DTBunch from './DTBunch';
|
|
3
|
+
import DTError from './DTError';
|
|
4
4
|
import {
|
|
5
|
+
DIXObject,
|
|
5
6
|
DTAcceptedMetaData,
|
|
6
7
|
DTComponentOptions,
|
|
7
8
|
DTManagerFilters,
|
|
@@ -13,12 +14,13 @@ import {
|
|
|
13
14
|
} from '../types';
|
|
14
15
|
import DYOFinder from '../libs/DYOFinder';
|
|
15
16
|
import { componentManagerDefaultFinderConfiguration, managerDefaultOptions as defaultOptions } from '../constants';
|
|
16
|
-
import
|
|
17
|
-
import
|
|
17
|
+
import DTElement from './DTElement';
|
|
18
|
+
import DTMaster from './DTMaster';
|
|
19
|
+
import DTDIXModule from '../libs/dix/DIXModule.module';
|
|
18
20
|
|
|
19
|
-
export default class
|
|
20
|
-
IBunchItem extends
|
|
21
|
-
> extends
|
|
21
|
+
export default class DTManager<
|
|
22
|
+
IBunchItem extends DTElement<DTAcceptedMetaData> = DTElement<DTAcceptedMetaData>,
|
|
23
|
+
> extends DTComponent<DTManagerOptions> {
|
|
22
24
|
/**
|
|
23
25
|
* Defining component type to "manager".
|
|
24
26
|
*/
|
|
@@ -50,7 +52,7 @@ export default class DYOToolsManager<
|
|
|
50
52
|
* The purpose is the guarantee of id uniqueness when transferring elements between bunches.
|
|
51
53
|
* It also facilitates searching elements in all Manager bunches.
|
|
52
54
|
*/
|
|
53
|
-
protected _library:
|
|
55
|
+
protected _library: DTBunch<IBunchItem>;
|
|
54
56
|
|
|
55
57
|
/**
|
|
56
58
|
* Current DYOFinder instance.
|
|
@@ -73,8 +75,6 @@ export default class DYOToolsManager<
|
|
|
73
75
|
*/
|
|
74
76
|
constructor(key?: string, elements: IBunchItem[] = [], scopes: string[] = [], options: Partial<DTManagerOptions> = {}) {
|
|
75
77
|
super(key, { ...defaultOptions, ...options });
|
|
76
|
-
// Use default _domain as _key
|
|
77
|
-
this._key = !key ? (this.getDomain() || this._id) : key;
|
|
78
78
|
|
|
79
79
|
this._items = {};
|
|
80
80
|
this._scopes = [
|
|
@@ -82,7 +82,7 @@ export default class DYOToolsManager<
|
|
|
82
82
|
'virtual',
|
|
83
83
|
...scopes,
|
|
84
84
|
];
|
|
85
|
-
this._library = new
|
|
85
|
+
this._library = new DTBunch('library', elements, { virtualContainer: true });
|
|
86
86
|
this._library.setContext(this);
|
|
87
87
|
|
|
88
88
|
this._finder = new DYOFinder(this, this.getFinderConfiguration());
|
|
@@ -102,7 +102,7 @@ export default class DYOToolsManager<
|
|
|
102
102
|
/**
|
|
103
103
|
* Getter for _library property.
|
|
104
104
|
*/
|
|
105
|
-
getLibrary():
|
|
105
|
+
getLibrary(): DTBunch<IBunchItem> {
|
|
106
106
|
return this._library;
|
|
107
107
|
}
|
|
108
108
|
|
|
@@ -144,10 +144,10 @@ export default class DYOToolsManager<
|
|
|
144
144
|
* @param item A DTBunch instance to add into the Manager.
|
|
145
145
|
* @param targetScope Optional scope for affectation.
|
|
146
146
|
*/
|
|
147
|
-
add(item:
|
|
147
|
+
add(item: DTBunch<IBunchItem>, targetScope?: string): void {
|
|
148
148
|
// Id conflict
|
|
149
149
|
if (Object.keys(this._items).includes(item.getId())) {
|
|
150
|
-
this.triggerError(new
|
|
150
|
+
this.triggerError(new DTError(
|
|
151
151
|
'id_conflict',
|
|
152
152
|
'Bunch with same id already exists in the manager',
|
|
153
153
|
this,
|
|
@@ -165,7 +165,7 @@ export default class DYOToolsManager<
|
|
|
165
165
|
const { code: errorCode, message: errorMessage } = this.getErrorDataForScope(targetScope, virtualContainer);
|
|
166
166
|
|
|
167
167
|
if (errorCode && errorMessage) {
|
|
168
|
-
this.triggerError(new
|
|
168
|
+
this.triggerError(new DTError(errorCode, errorMessage, this, item));
|
|
169
169
|
return;
|
|
170
170
|
}
|
|
171
171
|
scope = targetScope;
|
|
@@ -182,15 +182,15 @@ export default class DYOToolsManager<
|
|
|
182
182
|
|
|
183
183
|
// Update context
|
|
184
184
|
// Bunch
|
|
185
|
-
item.setContext<DYOToolsManager<IBunchItem>>(this);
|
|
186
185
|
const oldContext = item.getContext();
|
|
187
186
|
if (oldContext && oldContext.getComponentType() === 'manager') {
|
|
188
|
-
(oldContext as
|
|
187
|
+
(oldContext as DTManager<IBunchItem>).remove(item.getId());
|
|
189
188
|
}
|
|
189
|
+
item.setContext<DTManager<IBunchItem>>(this);
|
|
190
190
|
|
|
191
191
|
// Elements children
|
|
192
192
|
item.getAll().forEach((element) => {
|
|
193
|
-
element.setContext<
|
|
193
|
+
element.setContext<DTManager<IBunchItem>>(this);
|
|
194
194
|
});
|
|
195
195
|
|
|
196
196
|
// Add the new item
|
|
@@ -207,12 +207,12 @@ export default class DYOToolsManager<
|
|
|
207
207
|
* @param items An array of DTBunch instances to add into the Manager.
|
|
208
208
|
* @param targetScope Optional scope for affectation (all added items are affected).
|
|
209
209
|
*/
|
|
210
|
-
addMany(items:
|
|
210
|
+
addMany(items: DTBunch<IBunchItem>[], targetScope?: string): void {
|
|
211
211
|
const previousItems = { ...this._items };
|
|
212
212
|
const { errors }: DTComponentOptions = this._options;
|
|
213
213
|
|
|
214
214
|
try {
|
|
215
|
-
items.forEach((item:
|
|
215
|
+
items.forEach((item: DTBunch<IBunchItem>) => {
|
|
216
216
|
this.add(item, targetScope);
|
|
217
217
|
});
|
|
218
218
|
} catch (err: unknown) {
|
|
@@ -234,7 +234,7 @@ export default class DYOToolsManager<
|
|
|
234
234
|
*/
|
|
235
235
|
moveToScope(bunchId: string, targetScope: string): void {
|
|
236
236
|
if (!Object.keys(this._items).includes(bunchId)) {
|
|
237
|
-
this.triggerError(new
|
|
237
|
+
this.triggerError(new DTError(
|
|
238
238
|
'invalid_id',
|
|
239
239
|
'Bunch id provided doesn\'t exist in the manager',
|
|
240
240
|
this,
|
|
@@ -247,7 +247,7 @@ export default class DYOToolsManager<
|
|
|
247
247
|
const { virtualContainer } = bunch.getOptions();
|
|
248
248
|
const { code: errorCode, message: errorMessage } = this.getErrorDataForScope(targetScope, virtualContainer);
|
|
249
249
|
if (errorCode && errorMessage) {
|
|
250
|
-
this.triggerError(new
|
|
250
|
+
this.triggerError(new DTError(errorCode, errorMessage, this, bunch));
|
|
251
251
|
return;
|
|
252
252
|
}
|
|
253
253
|
|
|
@@ -260,7 +260,7 @@ export default class DYOToolsManager<
|
|
|
260
260
|
* @param id bunch id to return.
|
|
261
261
|
* @returns DYOToolsBunch instance that corresponds to the id provided, or undefined if not found.
|
|
262
262
|
*/
|
|
263
|
-
get(id: string):
|
|
263
|
+
get(id: string): DTBunch<IBunchItem> | undefined {
|
|
264
264
|
return this._items[id]?.item ?? undefined;
|
|
265
265
|
}
|
|
266
266
|
|
|
@@ -270,7 +270,7 @@ export default class DYOToolsManager<
|
|
|
270
270
|
* @param scope Optional parameter **scope** to return only bunches which are affected to a specific scope.
|
|
271
271
|
* @returns DYOToolsBunch array.
|
|
272
272
|
*/
|
|
273
|
-
getAll(scope?: string):
|
|
273
|
+
getAll(scope?: string): DTBunch<IBunchItem>[] {
|
|
274
274
|
const finalItems = [];
|
|
275
275
|
Object.values(this._items).forEach((item: DTManagerItemType<IBunchItem>) => {
|
|
276
276
|
if (!scope || item.scope === scope) {
|
|
@@ -294,8 +294,8 @@ export default class DYOToolsManager<
|
|
|
294
294
|
/**
|
|
295
295
|
* Returns Master component from context, or undefined.
|
|
296
296
|
*/
|
|
297
|
-
getMaster():
|
|
298
|
-
return this.getContext<
|
|
297
|
+
getMaster(): DTMaster | undefined {
|
|
298
|
+
return this.getContext<DTMaster>('master');
|
|
299
299
|
}
|
|
300
300
|
|
|
301
301
|
/**
|
|
@@ -329,7 +329,7 @@ export default class DYOToolsManager<
|
|
|
329
329
|
if (libraryDeletion) {
|
|
330
330
|
this._library.remove(item.getId());
|
|
331
331
|
}
|
|
332
|
-
item.
|
|
332
|
+
item.removeContainer();
|
|
333
333
|
});
|
|
334
334
|
|
|
335
335
|
this._items[id].item.removeContext();
|
|
@@ -375,8 +375,8 @@ export default class DYOToolsManager<
|
|
|
375
375
|
* @returns Array of DTBunch instance corresponding to the filters. Empty if no filter or invalid ones are passed.
|
|
376
376
|
* @see DYOFinder
|
|
377
377
|
*/
|
|
378
|
-
find(filters: Partial<DTManagerFilters>):
|
|
379
|
-
return this._finder.execute<
|
|
378
|
+
find(filters: Partial<DTManagerFilters>): DTBunch<IBunchItem>[] {
|
|
379
|
+
return this._finder.execute<DTBunch<IBunchItem>>(filters);
|
|
380
380
|
}
|
|
381
381
|
|
|
382
382
|
/**
|
|
@@ -462,4 +462,94 @@ export default class DYOToolsManager<
|
|
|
462
462
|
|
|
463
463
|
return response;
|
|
464
464
|
}
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Return DIX Object representation of the DTManager instance.
|
|
468
|
+
*
|
|
469
|
+
* @returns DIX Object representation of the DTManager.
|
|
470
|
+
*/
|
|
471
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
472
|
+
const parentDixObject = super.toDIXObject();
|
|
473
|
+
const dixObject: DIXObject = {
|
|
474
|
+
...parentDixObject[this._id],
|
|
475
|
+
items: Object.keys(this._items),
|
|
476
|
+
library: this._library.getId(),
|
|
477
|
+
};
|
|
478
|
+
|
|
479
|
+
// Library Dix Object
|
|
480
|
+
// Empty string for options because not relevant
|
|
481
|
+
const libraryDix: DIXObject = {
|
|
482
|
+
...this._library.toDIXObject()[this._library.getId()],
|
|
483
|
+
options: '',
|
|
484
|
+
};
|
|
485
|
+
|
|
486
|
+
// Add Scopes
|
|
487
|
+
// Only non default scopes
|
|
488
|
+
const scopesForDix = this._scopes.filter((sc) => !['default', 'virtual'].includes(sc));
|
|
489
|
+
if (scopesForDix.length > 0) {
|
|
490
|
+
dixObject.scopes = scopesForDix;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
const finalDix = {
|
|
494
|
+
[this._id]: dixObject,
|
|
495
|
+
...this._library.toDIXObject(),
|
|
496
|
+
[this._library.getId()]: libraryDix,
|
|
497
|
+
};
|
|
498
|
+
|
|
499
|
+
Object.values(this._items).forEach((item) => {
|
|
500
|
+
const itemDix = item.item.toDIXObject();
|
|
501
|
+
itemDix[item.item.getId()].scope = item.scope;
|
|
502
|
+
|
|
503
|
+
Object.assign(finalDix, {
|
|
504
|
+
...itemDix,
|
|
505
|
+
});
|
|
506
|
+
});
|
|
507
|
+
|
|
508
|
+
return finalDix;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* Update the DTManager instance with a DIX Object.
|
|
513
|
+
*
|
|
514
|
+
* @param dix DIX Object to use for updating.
|
|
515
|
+
*/
|
|
516
|
+
updateFromDix(dix: Record<string, DIXObject>): void {
|
|
517
|
+
const dixObject = dix[this._id];
|
|
518
|
+
const dixModule = this.getMaster()?.getModule('dix') as DTDIXModule;
|
|
519
|
+
|
|
520
|
+
if (dixObject && dixModule?.isEnabled()) {
|
|
521
|
+
// Synchronize Library
|
|
522
|
+
if (dixObject.library) {
|
|
523
|
+
this._library = new DTBunch('library', [], { virtualContainer: true, syncId: dixObject.library });
|
|
524
|
+
this._library.setContext(this);
|
|
525
|
+
this._library.updateFromDix(dix);
|
|
526
|
+
}
|
|
527
|
+
|
|
528
|
+
// Synchronize Bunches
|
|
529
|
+
if (dixObject.items) {
|
|
530
|
+
// Remove items
|
|
531
|
+
this.getAll().forEach((it) => {
|
|
532
|
+
if (!dixObject.items.includes(it.getId())) {
|
|
533
|
+
this.remove(it.getId());
|
|
534
|
+
}
|
|
535
|
+
});
|
|
536
|
+
|
|
537
|
+
// Add and update existing items
|
|
538
|
+
dixObject.items.forEach((itemId) => {
|
|
539
|
+
if (this.get(itemId)) {
|
|
540
|
+
this.get(itemId).updateFromDix(dix);
|
|
541
|
+
} else {
|
|
542
|
+
const newBunch = dixModule.syncNewItem(itemId, dix) as DTBunch<IBunchItem>;
|
|
543
|
+
this.add(newBunch);
|
|
544
|
+
newBunch.updateFromDix(dix);
|
|
545
|
+
}
|
|
546
|
+
// Move to scope
|
|
547
|
+
const bunchDixObject = dix[itemId];
|
|
548
|
+
if (bunchDixObject) {
|
|
549
|
+
this.moveToScope(itemId, bunchDixObject.scope);
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
}
|
|
465
555
|
}
|
package/src/core/DTMaster.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import { DTMasterToObject } from '../types';
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import DTComponent from './DTComponent';
|
|
2
|
+
import DTError from './DTError';
|
|
3
|
+
import DTManager from './DTManager';
|
|
4
|
+
import DTAction from './DTAction';
|
|
5
|
+
import DTModule from './DTModule';
|
|
6
|
+
import { DIXObject, DTComponentOptions, DTMasterToObject } from '../types';
|
|
7
|
+
import DTDIXModule from '../libs/dix/DIXModule.module';
|
|
8
|
+
|
|
9
|
+
export default class DTMaster extends DTComponent {
|
|
9
10
|
/**
|
|
10
11
|
* Defining component type to "master".
|
|
11
12
|
*/
|
|
@@ -17,7 +18,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
17
18
|
* The property is an object with _id value of the Manager instance as key, and Manager instance as value.
|
|
18
19
|
* @protected
|
|
19
20
|
*/
|
|
20
|
-
protected _managers: Record<string,
|
|
21
|
+
protected _managers: Record<string, DTManager>;
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* DTAction instances handled by the Master.
|
|
@@ -25,7 +26,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
25
26
|
* The property is an object with _id value of the Action instance as key, and Action instance as value.
|
|
26
27
|
* @protected
|
|
27
28
|
*/
|
|
28
|
-
protected _actions: Record<string,
|
|
29
|
+
protected _actions: Record<string, DTAction>;
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* DTModule instance handled by the Master.
|
|
@@ -33,15 +34,16 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
33
34
|
* The property is an object with _id value of the Module instance as key, and Module instance as value.
|
|
34
35
|
* @protected
|
|
35
36
|
*/
|
|
36
|
-
protected _modules: Record<string,
|
|
37
|
+
protected _modules: Record<string, DTModule>;
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* Applying the parent constructor, and initializing all properties to empty object.
|
|
40
41
|
*
|
|
41
42
|
* @param key
|
|
43
|
+
* @param options
|
|
42
44
|
*/
|
|
43
|
-
constructor(key?: string) {
|
|
44
|
-
super(key);
|
|
45
|
+
constructor(key?: string, options: Partial<DTComponentOptions> = {}) {
|
|
46
|
+
super(key, options);
|
|
45
47
|
|
|
46
48
|
this._managers = {};
|
|
47
49
|
this._actions = {};
|
|
@@ -58,10 +60,10 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
58
60
|
*
|
|
59
61
|
* @param manager DYOToolsManager instance to add.
|
|
60
62
|
*/
|
|
61
|
-
addManager(manager:
|
|
63
|
+
addManager(manager: DTManager): void {
|
|
62
64
|
// Id conflict
|
|
63
65
|
if (Object.keys(this._managers).includes(manager.getId())) {
|
|
64
|
-
this.triggerError(new
|
|
66
|
+
this.triggerError(new DTError(
|
|
65
67
|
'id_conflict',
|
|
66
68
|
'Manager with same id already exists in the Master instance',
|
|
67
69
|
this,
|
|
@@ -72,7 +74,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
72
74
|
|
|
73
75
|
// Key conflict
|
|
74
76
|
if (Object.values(this._managers).find((m) => m.getKey() === manager.getKey())) {
|
|
75
|
-
this.triggerError(new
|
|
77
|
+
this.triggerError(new DTError(
|
|
76
78
|
'key_conflict',
|
|
77
79
|
'Manager with same key already exists in the Master instance',
|
|
78
80
|
this,
|
|
@@ -82,7 +84,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
82
84
|
}
|
|
83
85
|
|
|
84
86
|
this._managers[manager.getId()] = manager;
|
|
85
|
-
manager.setContext<
|
|
87
|
+
manager.setContext<DTMaster>(this);
|
|
86
88
|
}
|
|
87
89
|
|
|
88
90
|
/**
|
|
@@ -92,7 +94,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
92
94
|
* @param idOrKey String id or key to select.
|
|
93
95
|
* @returns DYOToolsManager selected Manager instance, or undefined if not found.
|
|
94
96
|
*/
|
|
95
|
-
getManager(idOrKey: string):
|
|
97
|
+
getManager(idOrKey: string): DTManager | undefined {
|
|
96
98
|
let managerFound = this._managers[idOrKey];
|
|
97
99
|
|
|
98
100
|
if (!managerFound) {
|
|
@@ -125,10 +127,10 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
125
127
|
*
|
|
126
128
|
* @param action DYOToolsAction instance to add.
|
|
127
129
|
*/
|
|
128
|
-
addAction(action:
|
|
130
|
+
addAction(action: DTAction): void {
|
|
129
131
|
// Id conflict
|
|
130
132
|
if (Object.keys(this._actions).includes(action.getId())) {
|
|
131
|
-
this.triggerError(new
|
|
133
|
+
this.triggerError(new DTError(
|
|
132
134
|
'id_conflict',
|
|
133
135
|
'Action with same id already exists in the Master instance',
|
|
134
136
|
this,
|
|
@@ -139,7 +141,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
139
141
|
|
|
140
142
|
// Key conflict
|
|
141
143
|
if (Object.values(this._actions).find((m) => m.getKey() === action.getKey())) {
|
|
142
|
-
this.triggerError(new
|
|
144
|
+
this.triggerError(new DTError(
|
|
143
145
|
'key_conflict',
|
|
144
146
|
'Action with same key already exists in the Master instance',
|
|
145
147
|
this,
|
|
@@ -149,7 +151,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
149
151
|
}
|
|
150
152
|
|
|
151
153
|
this._actions[action.getId()] = action;
|
|
152
|
-
action.setContext<
|
|
154
|
+
action.setContext<DTMaster>(this);
|
|
153
155
|
}
|
|
154
156
|
|
|
155
157
|
/**
|
|
@@ -159,7 +161,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
159
161
|
* @param idOrKey String id or key to select.
|
|
160
162
|
* @returns DYOToolsAction selected Action instance, or undefined if not found.
|
|
161
163
|
*/
|
|
162
|
-
getAction(idOrKey: string):
|
|
164
|
+
getAction(idOrKey: string): DTAction | undefined {
|
|
163
165
|
let actionFound = this._actions[idOrKey];
|
|
164
166
|
|
|
165
167
|
if (!actionFound) {
|
|
@@ -208,10 +210,10 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
208
210
|
*
|
|
209
211
|
* @param module DYOToolsModule instance to add.
|
|
210
212
|
*/
|
|
211
|
-
addModule(module:
|
|
213
|
+
addModule(module: DTModule): void {
|
|
212
214
|
// Id conflict
|
|
213
215
|
if (Object.keys(this._modules).includes(module.getId())) {
|
|
214
|
-
this.triggerError(new
|
|
216
|
+
this.triggerError(new DTError(
|
|
215
217
|
'id_conflict',
|
|
216
218
|
'Module with same id already exists in the Master instance',
|
|
217
219
|
this,
|
|
@@ -222,7 +224,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
222
224
|
|
|
223
225
|
// Key conflict
|
|
224
226
|
if (Object.values(this._modules).find((m) => m.getKey() === module.getKey())) {
|
|
225
|
-
this.triggerError(new
|
|
227
|
+
this.triggerError(new DTError(
|
|
226
228
|
'key_conflict',
|
|
227
229
|
'Module with same key already exists in the Master instance',
|
|
228
230
|
this,
|
|
@@ -232,7 +234,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
232
234
|
}
|
|
233
235
|
|
|
234
236
|
this._modules[module.getId()] = module;
|
|
235
|
-
module.setContext<
|
|
237
|
+
module.setContext<DTMaster>(this);
|
|
236
238
|
}
|
|
237
239
|
|
|
238
240
|
/**
|
|
@@ -242,7 +244,7 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
242
244
|
* @param idOrKey String id or key to select.
|
|
243
245
|
* @returns DYOToolsModule selected Module instance, or undefined if not found.
|
|
244
246
|
*/
|
|
245
|
-
getModule(idOrKey: string):
|
|
247
|
+
getModule(idOrKey: string): DTModule | undefined {
|
|
246
248
|
let moduleFound = this._modules[idOrKey];
|
|
247
249
|
|
|
248
250
|
if (!moduleFound) {
|
|
@@ -315,4 +317,50 @@ export default class DYOToolsMaster extends DYOToolsComponent {
|
|
|
315
317
|
|
|
316
318
|
return toObject;
|
|
317
319
|
}
|
|
320
|
+
|
|
321
|
+
/**
|
|
322
|
+
* Return DIX Object representation of the DTManager instance.
|
|
323
|
+
*
|
|
324
|
+
* @returns DIX Object representation of the DTManager.
|
|
325
|
+
*/
|
|
326
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
327
|
+
const parentDixObject = super.toDIXObject();
|
|
328
|
+
const dixObject: DIXObject = {
|
|
329
|
+
...parentDixObject[this._id],
|
|
330
|
+
items: Object.keys(this._managers),
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
const finalDix = {
|
|
334
|
+
[this._id]: dixObject,
|
|
335
|
+
};
|
|
336
|
+
Object.values(this._managers).forEach((item) => {
|
|
337
|
+
Object.assign(finalDix, {
|
|
338
|
+
...item.toDIXObject(),
|
|
339
|
+
});
|
|
340
|
+
});
|
|
341
|
+
|
|
342
|
+
return finalDix;
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* Update the DTMaster instance with a DIX Object.
|
|
347
|
+
*
|
|
348
|
+
* @param dix DIX Object to use for updating.
|
|
349
|
+
*/
|
|
350
|
+
updateFromDix(dix: Record<string, DIXObject>): void {
|
|
351
|
+
const dixObject = dix[this._id];
|
|
352
|
+
const dixModule = this.getModule('dix') as DTDIXModule;
|
|
353
|
+
if (dixObject && dixObject.items && dixModule?.isEnabled()) {
|
|
354
|
+
// Synchronize Managers
|
|
355
|
+
dixObject.items.forEach((itemId) => {
|
|
356
|
+
if (this.getManager(itemId)) {
|
|
357
|
+
this.getManager(itemId).updateFromDix(dix);
|
|
358
|
+
} else {
|
|
359
|
+
const newManager = dixModule.syncNewItem(itemId, dix) as DTManager;
|
|
360
|
+
this.addManager(newManager);
|
|
361
|
+
newManager.updateFromDix(dix);
|
|
362
|
+
}
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
}
|
|
318
366
|
}
|
package/src/core/DTModule.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { DTModuleToObject } from '../types';
|
|
3
|
-
import
|
|
1
|
+
import DTComponent from './DTComponent';
|
|
2
|
+
import { DIXObject, DTModuleToObject } from '../types';
|
|
3
|
+
import DTMaster from './DTMaster';
|
|
4
4
|
|
|
5
|
-
export default class
|
|
5
|
+
export default class DTModule extends DTComponent {
|
|
6
6
|
/**
|
|
7
7
|
* Defining component type to "module".
|
|
8
8
|
*/
|
|
@@ -28,8 +28,8 @@ export default class DYOToolsModule extends DYOToolsComponent {
|
|
|
28
28
|
/**
|
|
29
29
|
* Returns Master component from context, or undefined.
|
|
30
30
|
*/
|
|
31
|
-
getMaster():
|
|
32
|
-
return this.getContext<
|
|
31
|
+
getMaster(): DTMaster | undefined {
|
|
32
|
+
return this.getContext<DTMaster>('master');
|
|
33
33
|
}
|
|
34
34
|
|
|
35
35
|
/**
|
|
@@ -87,4 +87,10 @@ export default class DYOToolsModule extends DYOToolsComponent {
|
|
|
87
87
|
enabled: this._enabled,
|
|
88
88
|
};
|
|
89
89
|
}
|
|
90
|
+
|
|
91
|
+
toDIXObject(): Record<string, DIXObject> {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
updateFromDix(): void {}
|
|
90
96
|
}
|
package/src/index.ts
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
// All exports
|
|
2
|
-
// CORE
|
|
3
|
-
export { default as DTComponent } from './core/DTComponent';
|
|
4
|
-
export { default as DTComponentWithMeta } from './core/DTComponentWithMeta';
|
|
5
|
-
export { default as DTComponentPhysical } from './core/DTComponentPhysical';
|
|
6
|
-
export { default as DTElement } from './core/DTElement';
|
|
7
|
-
export { default as DTBunch } from './core/DTBunch';
|
|
8
|
-
export { default as DTManager } from './core/DTManager';
|
|
9
|
-
export { default as DTMaster } from './core/DTMaster';
|
|
10
|
-
export { default as DTError } from './core/DTError';
|
|
11
|
-
export { default as DTAction } from './core/DTAction';
|
|
12
|
-
export { default as DTModule } from './core/DTModule';
|
|
13
|
-
|
|
14
|
-
// LIBS
|
|
15
|
-
// PLAYER
|
|
16
|
-
export { default as DTPlayer } from './libs/player/DTPlayer.element';
|
|
17
|
-
export { default as DTPlayerManager } from './libs/player/DTPlayer.manager';
|
|
1
|
+
// All exports
|
|
2
|
+
// CORE
|
|
3
|
+
export { default as DTComponent } from './core/DTComponent';
|
|
4
|
+
export { default as DTComponentWithMeta } from './core/DTComponentWithMeta';
|
|
5
|
+
export { default as DTComponentPhysical } from './core/DTComponentPhysical';
|
|
6
|
+
export { default as DTElement } from './core/DTElement';
|
|
7
|
+
export { default as DTBunch } from './core/DTBunch';
|
|
8
|
+
export { default as DTManager } from './core/DTManager';
|
|
9
|
+
export { default as DTMaster } from './core/DTMaster';
|
|
10
|
+
export { default as DTError } from './core/DTError';
|
|
11
|
+
export { default as DTAction } from './core/DTAction';
|
|
12
|
+
export { default as DTModule } from './core/DTModule';
|
|
13
|
+
|
|
14
|
+
// LIBS
|
|
15
|
+
// PLAYER
|
|
16
|
+
export { default as DTPlayer } from './libs/player/DTPlayer.element';
|
|
17
|
+
export { default as DTPlayerManager } from './libs/player/DTPlayer.manager';
|