dyo-tools 0.2.0 → 0.3.2
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/dist/constants.js +4 -4
- package/dist/constants.js.map +1 -1
- package/dist/core/DTAction.d.ts +10 -0
- package/dist/core/DTAction.js +24 -0
- package/dist/core/DTAction.js.map +1 -0
- package/dist/core/DTBunch.d.ts +6 -7
- package/dist/core/DTBunch.js +17 -14
- package/dist/core/DTBunch.js.map +1 -1
- package/dist/core/DTComponentPhysical.d.ts +7 -4
- package/dist/core/DTComponentPhysical.js +6 -0
- package/dist/core/DTComponentPhysical.js.map +1 -1
- package/dist/core/DTElement.d.ts +5 -0
- package/dist/core/DTElement.js +12 -2
- package/dist/core/DTElement.js.map +1 -1
- package/dist/core/DTManager.d.ts +3 -1
- package/dist/core/DTManager.js +24 -14
- package/dist/core/DTManager.js.map +1 -1
- package/dist/core/DTMaster.d.ts +24 -0
- package/dist/core/DTMaster.js +133 -0
- package/dist/core/DTMaster.js.map +1 -0
- package/dist/core/DTModule.d.ts +14 -0
- package/dist/core/DTModule.js +39 -0
- package/dist/core/DTModule.js.map +1 -0
- package/dist/index.d.ts +5 -1
- package/dist/index.js +11 -3
- package/dist/index.js.map +1 -1
- package/dist/libs/player/DTPlayer.element.d.ts +5 -0
- package/dist/libs/player/DTPlayer.element.js +11 -0
- package/dist/libs/player/DTPlayer.element.js.map +1 -0
- package/dist/libs/player/DTPlayer.manager.d.ts +11 -0
- package/dist/libs/player/DTPlayer.manager.js +42 -0
- package/dist/libs/player/DTPlayer.manager.js.map +1 -0
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/dist/types/core.d.ts +103 -0
- package/dist/types/core.js +15 -0
- package/dist/types/core.js.map +1 -0
- package/dist/types/index.d.ts +2 -98
- package/dist/types/index.js +16 -12
- package/dist/types/index.js.map +1 -1
- package/dist/types/player.d.ts +5 -0
- package/dist/types/player.js +3 -0
- package/dist/types/player.js.map +1 -0
- package/docs/assets/highlight.css +29 -29
- package/docs/assets/main.js +4 -3
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -1
- package/docs/assets/style.css +72 -25
- package/docs/classes/core_DTAction.DYOToolsAction.html +89 -0
- package/docs/classes/core_DTBunch.DYOToolsBunch.html +254 -0
- package/docs/classes/core_DTComponent.DYOToolsComponent.html +76 -0
- package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +110 -0
- package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +96 -0
- package/docs/classes/core_DTElement.DYOToolsElement.html +135 -0
- package/docs/classes/core_DTError.DYOToolsError.html +37 -0
- package/docs/classes/core_DTManager.DYOToolsManager.html +237 -0
- package/docs/classes/core_DTMaster.DYOToolsMaster.html +150 -0
- package/docs/classes/core_DTModule.DYOToolsModule.html +92 -0
- package/docs/classes/libs_DYOFinder.DYOFinder.html +34 -0
- package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +134 -0
- package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +243 -0
- package/docs/enums/types_core.FilterOperatorType.html +10 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +1 -46
- package/docs/interfaces/types_core.DTBunchFilters.html +6 -0
- package/docs/interfaces/types_core.DTBunchOptions.html +19 -0
- package/docs/interfaces/types_core.DTBunchToObject.html +7 -0
- package/docs/interfaces/types_core.DTComponentOptions.html +5 -0
- package/docs/interfaces/types_core.DTComponentToObject.html +4 -0
- package/docs/interfaces/types_core.DTElementToObject.html +7 -0
- package/docs/interfaces/types_core.DTManagerFilters.html +6 -0
- package/docs/interfaces/types_core.DTManagerOptions.html +8 -0
- package/docs/interfaces/types_core.DTManagerToObject.html +5 -0
- package/docs/interfaces/types_core.DTMasterToObject.html +8 -0
- package/docs/interfaces/types_core.DTModuleToObject.html +6 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +4 -0
- package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +4 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +5 -0
- package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +5 -0
- package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +3 -0
- package/docs/modules/constants.html +6 -0
- package/docs/modules/core_DTAction.html +2 -0
- package/docs/modules/core_DTBunch.html +2 -0
- package/docs/modules/core_DTComponent.html +2 -0
- package/docs/modules/core_DTComponentPhysical.html +2 -0
- package/docs/modules/core_DTComponentWithMeta.html +2 -0
- package/docs/modules/core_DTElement.html +2 -0
- package/docs/modules/core_DTError.html +2 -0
- package/docs/modules/core_DTManager.html +2 -0
- package/docs/modules/core_DTMaster.html +2 -0
- package/docs/modules/core_DTModule.html +2 -0
- package/docs/modules/libs_DYOFinder.html +2 -0
- package/docs/modules/libs_player_DTPlayer_element.html +2 -0
- package/docs/modules/libs_player_DTPlayer_manager.html +2 -0
- package/docs/modules/types.html +29 -0
- package/docs/modules/types_core.html +28 -0
- package/docs/modules/types_player.html +2 -0
- package/docs/types/types_core.DTAcceptedMetaData.html +2 -0
- package/docs/types/types_core.DTManagerItemType.html +1 -0
- package/docs/types/types_core.DTManagerItemsType.html +2 -0
- package/docs/types/types_core.DYOFinderComponentType.html +1 -0
- package/docs/types/types_core.DYOFinderConfiguration.html +2 -0
- package/docs/types/types_core.DYOFinderConfigurationProp.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperator.html +1 -0
- package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +1 -0
- package/docs/types/types_core.DYOFinderFilters.html +1 -0
- package/docs/types/types_core.StandardPrimitiveType.html +2 -0
- package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +1 -0
- package/docs/variables/constants.bunchDefaultOptions.html +2 -0
- package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +1 -0
- package/docs/variables/constants.managerDefaultOptions.html +2 -0
- package/package.json +16 -17
- package/src/constants.ts +4 -4
- package/src/core/DTAction.ts +52 -0
- package/src/core/DTBunch.ts +36 -30
- package/src/core/DTComponent.ts +1 -1
- package/src/core/DTComponentPhysical.ts +20 -5
- package/src/core/DTElement.ts +35 -2
- package/src/core/DTManager.ts +37 -18
- package/src/core/DTMaster.ts +318 -0
- package/src/core/DTModule.ts +90 -0
- package/src/index.ts +9 -1
- package/src/libs/player/DTPlayer.element.ts +9 -0
- package/src/libs/player/DTPlayer.manager.ts +84 -0
- package/src/types/core.ts +169 -0
- package/src/types/index.ts +2 -162
- package/src/types/player.ts +6 -0
- package/test/core/DTAction.double.ts +78 -0
- package/test/core/DTAction.spec.ts +76 -0
- package/test/core/DTBunch.double.ts +18 -10
- package/test/core/DTBunch.spec.ts +83 -68
- package/test/core/DTComponentPhysical.double.ts +3 -3
- package/test/core/DTComponentPhysical.spec.ts +25 -11
- package/test/core/DTElement.double.ts +21 -5
- package/test/core/DTElement.spec.ts +52 -8
- package/test/core/DTError.double.ts +1 -1
- package/test/core/DTManager.double.ts +29 -5
- package/test/core/DTManager.spec.ts +80 -17
- package/test/core/DTMaster.double.ts +141 -0
- package/test/core/DTMaster.spec.ts +584 -0
- package/test/core/DTModule.double.ts +80 -0
- package/test/core/DTModule.spec.ts +138 -0
- package/test/core/copy.spec.ts +20 -4
- package/test/{core/DTPlayer.double.ts → libs/player/DTPlayer.element.double.ts} +15 -24
- package/test/libs/player/DTPlayer.element.spec.ts +28 -0
- package/test/libs/player/DTPlayer.manager.double.ts +92 -0
- package/test/libs/player/DTPlayer.manager.spec.ts +178 -0
- package/LICENSE +0 -21
- package/cucumber.js +0 -9
- package/dist/core/DTPlayer.d.ts +0 -8
- package/dist/core/DTPlayer.js +0 -30
- package/dist/core/DTPlayer.js.map +0 -1
- package/e2e/0.2.0/epic1.feature +0 -29
- package/e2e/0.2.0/epic2.feature +0 -22
- package/e2e/0.2.0/epic3.feature +0 -25
- package/e2e/0.2.0/resources/dominion.js +0 -195
- package/e2e/0.2.0/resources/utils.js +0 -27
- package/e2e/0.2.0/support/steps.js +0 -108
- package/e2e/future/epic4.feature +0 -39
- package/e2e/future/resources/dominion.js +0 -238
- package/e2e/future/resources/utils.js +0 -27
- package/src/core/DTPlayer.ts +0 -57
- package/test/core/DTPlayer.spec.ts +0 -80
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dyo-tools",
|
|
3
|
-
"version": "0.2
|
|
3
|
+
"version": "0.3.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,8 +13,7 @@
|
|
|
13
13
|
"test": "jest",
|
|
14
14
|
"test:coverage": "c8 --check-coverage npm test",
|
|
15
15
|
"test:coverage:verify": "c8 --check-coverage --lines 97 --functions 97 --branches 97 --statements 97 npm test",
|
|
16
|
-
"
|
|
17
|
-
"typedoc": "typedoc --tsconfig tsconfig.dev.json src/**/*.ts"
|
|
16
|
+
"typedoc": "typedoc --plugin typedoc-plugin-rename-defaults --entryPointStrategy expand ./src --exclude 'src/index.ts'"
|
|
18
17
|
},
|
|
19
18
|
"repository": {
|
|
20
19
|
"type": "git",
|
|
@@ -30,23 +29,23 @@
|
|
|
30
29
|
},
|
|
31
30
|
"homepage": "https://gitlab.com/dyo-system/dyo-tools#readme",
|
|
32
31
|
"devDependencies": {
|
|
33
|
-
"@babel/preset-env": "^7.
|
|
34
|
-
"@types/jest": "^
|
|
35
|
-
"@types/uuid": "^9.0.
|
|
36
|
-
"@typescript-eslint/eslint-plugin": "^
|
|
37
|
-
"@typescript-eslint/parser": "^
|
|
38
|
-
"c8": "^
|
|
39
|
-
"eslint": "^8.
|
|
32
|
+
"@babel/preset-env": "^7.23.9",
|
|
33
|
+
"@types/jest": "^29.5.12",
|
|
34
|
+
"@types/uuid": "^9.0.8",
|
|
35
|
+
"@typescript-eslint/eslint-plugin": "^6.21.0",
|
|
36
|
+
"@typescript-eslint/parser": "^6.21.0",
|
|
37
|
+
"c8": "^9.1.0",
|
|
38
|
+
"eslint": "^8.56.0",
|
|
40
39
|
"eslint-config-airbnb-base": "^15.0.0",
|
|
41
|
-
"eslint-config-airbnb-typescript": "^17.
|
|
42
|
-
"eslint-plugin-import": "^2.
|
|
43
|
-
"jest": "^
|
|
44
|
-
"ts-jest": "^
|
|
45
|
-
"typedoc": "^0.
|
|
40
|
+
"eslint-config-airbnb-typescript": "^17.1.0",
|
|
41
|
+
"eslint-plugin-import": "^2.29.1",
|
|
42
|
+
"jest": "^29.7.0",
|
|
43
|
+
"ts-jest": "^29.1.2",
|
|
44
|
+
"typedoc": "^0.25.8",
|
|
45
|
+
"typedoc-plugin-rename-defaults": "^0.7.0",
|
|
46
46
|
"typescript": "4.8.4"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"
|
|
50
|
-
"uuid": "^9.0.0"
|
|
49
|
+
"uuid": "^9.0.1"
|
|
51
50
|
}
|
|
52
51
|
}
|
package/src/constants.ts
CHANGED
|
@@ -17,7 +17,7 @@ export const bunchDefaultOptions: DTBunchOptions = {
|
|
|
17
17
|
uniqueKey: false,
|
|
18
18
|
inheritOwner: false,
|
|
19
19
|
replaceIndex: false,
|
|
20
|
-
|
|
20
|
+
virtualContainer: false,
|
|
21
21
|
};
|
|
22
22
|
|
|
23
23
|
/** DTManager constants * */
|
|
@@ -54,7 +54,7 @@ export const componentPhysicalDefaultFinderConfiguration: DYOFinderConfiguration
|
|
|
54
54
|
},
|
|
55
55
|
owner: {
|
|
56
56
|
operators: baseOperators,
|
|
57
|
-
getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) =>
|
|
57
|
+
getValue: (item: DTComponentPhysical<DTAcceptedMetaData>) => item.getOwner(),
|
|
58
58
|
objectSearch: false,
|
|
59
59
|
},
|
|
60
60
|
meta: {
|
|
@@ -77,9 +77,9 @@ export const componentManagerDefaultFinderConfiguration: DYOFinderConfiguration
|
|
|
77
77
|
|
|
78
78
|
export const componentBunchDefaultFinderConfiguration: DYOFinderConfiguration = {
|
|
79
79
|
...componentPhysicalDefaultFinderConfiguration,
|
|
80
|
-
|
|
80
|
+
container: {
|
|
81
81
|
operators: baseOperators,
|
|
82
|
-
getValue: (item:
|
|
82
|
+
getValue: (item: DTElement<DTAcceptedMetaData>) => (item.getContainer() ? item.getContainer().getId() : null),
|
|
83
83
|
objectSearch: false,
|
|
84
84
|
},
|
|
85
85
|
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import DYOToolsComponent from './DTComponent';
|
|
2
|
+
import { DTComponentToObject } from '../types';
|
|
3
|
+
import DYOToolsMaster from './DTMaster';
|
|
4
|
+
|
|
5
|
+
export default abstract class DYOToolsAction<Payload = unknown> extends DYOToolsComponent {
|
|
6
|
+
/**
|
|
7
|
+
* Defining component type to "action".
|
|
8
|
+
*/
|
|
9
|
+
protected _componentType: string = 'action';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Returns Master component from context, or undefined.
|
|
13
|
+
*/
|
|
14
|
+
getMaster(): DYOToolsMaster | undefined {
|
|
15
|
+
return this.getContext<DYOToolsMaster>('master');
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Abstract method for action execution process.
|
|
20
|
+
*
|
|
21
|
+
* @param payload Object Payload to pass for action execution.
|
|
22
|
+
* @returns Promise
|
|
23
|
+
*/
|
|
24
|
+
abstract execute(payload: Payload): Promise<void>;
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Return String representation of the Action instance.
|
|
28
|
+
*
|
|
29
|
+
* @returns String representation of the Action.
|
|
30
|
+
*/
|
|
31
|
+
toString(): string {
|
|
32
|
+
return `Component ${this._key} - Type: Action`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Return JSON Object representation of the Action instance.
|
|
37
|
+
*
|
|
38
|
+
* JSON Object returned has the following structure :
|
|
39
|
+
* * **id** : _id property of the Action.
|
|
40
|
+
* * **key** : _key property of the Action.
|
|
41
|
+
* * **type** : _componentType property of the Action.
|
|
42
|
+
*
|
|
43
|
+
* @returns JSON Object representation of the Action.
|
|
44
|
+
*/
|
|
45
|
+
toObject(): DTComponentToObject {
|
|
46
|
+
return {
|
|
47
|
+
id: this._id,
|
|
48
|
+
key: this._key,
|
|
49
|
+
type: this._componentType,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
package/src/core/DTBunch.ts
CHANGED
|
@@ -3,14 +3,13 @@ import DYOToolsManager from './DTManager';
|
|
|
3
3
|
import {
|
|
4
4
|
DTAcceptedMetaData, DTBunchFilters, DTBunchOptions, DTBunchToObject, DYOFinderConfiguration,
|
|
5
5
|
} from '../types';
|
|
6
|
-
import DYOToolsPlayer from './DTPlayer';
|
|
7
6
|
import DYOToolsError from './DTError';
|
|
8
7
|
import DYOToolsComponentPhysical from './DTComponentPhysical';
|
|
9
8
|
import { bunchDefaultOptions as defaultOptions, componentBunchDefaultFinderConfiguration } from '../constants';
|
|
10
9
|
import DYOFinder from '../libs/DYOFinder';
|
|
11
10
|
|
|
12
11
|
export default class DYOToolsBunch<
|
|
13
|
-
IBunchItem extends DYOToolsElement<DTAcceptedMetaData>,
|
|
12
|
+
IBunchItem extends DYOToolsElement<DTAcceptedMetaData> = DYOToolsElement<DTAcceptedMetaData>,
|
|
14
13
|
IComponentMeta extends DTAcceptedMetaData = DTAcceptedMetaData,
|
|
15
14
|
> extends DYOToolsComponentPhysical<IComponentMeta, DTBunchOptions> {
|
|
16
15
|
/**
|
|
@@ -68,7 +67,7 @@ export default class DYOToolsBunch<
|
|
|
68
67
|
*
|
|
69
68
|
* If **inheritOwner** is *true*, apply new **owner** to each item.
|
|
70
69
|
*/
|
|
71
|
-
setOwner(value:
|
|
70
|
+
setOwner(value: string): void {
|
|
72
71
|
super.setOwner(value);
|
|
73
72
|
|
|
74
73
|
// Update owner elements
|
|
@@ -102,7 +101,7 @@ export default class DYOToolsBunch<
|
|
|
102
101
|
* saved in current _options property. Available Options are : **uniqueKey**, **inheritOwner**, **replaceIndex**
|
|
103
102
|
* and **errors**.
|
|
104
103
|
*/
|
|
105
|
-
add(item: IBunchItem, options: Partial<Omit<DTBunchOptions, '
|
|
104
|
+
add(item: IBunchItem, options: Partial<Omit<DTBunchOptions, 'virtualContainer'>> = {}): void {
|
|
106
105
|
this.addAtIndex(item, this._items.length, options);
|
|
107
106
|
}
|
|
108
107
|
|
|
@@ -114,8 +113,8 @@ export default class DYOToolsBunch<
|
|
|
114
113
|
* * Option **uniqueKey** = *true*. If the added item has the same _key than existing item,
|
|
115
114
|
* an error occurred (depending on **errors** option).
|
|
116
115
|
* * Option **inheritOwner** = *true*. When the new item is added, its owner is replaced by the current bunch owner.
|
|
117
|
-
* * Option **
|
|
118
|
-
* instance. The item is removed from the old
|
|
116
|
+
* * Option **virtualContainer** = *false*. When the new item is added, its container is replaced by the current bunch
|
|
117
|
+
* instance. The item is removed from the old container.
|
|
119
118
|
* * If an item already exists at the specified index, the new item is added at the index, and following items are
|
|
120
119
|
* automatically affected at next indexes. If **replaceIndex** option is *true*, the new item replaces the former one
|
|
121
120
|
* at the index instead.
|
|
@@ -129,9 +128,9 @@ export default class DYOToolsBunch<
|
|
|
129
128
|
* saved in current _options property. Available Options are : **uniqueKey**, **inheritOwner**, **replaceIndex**
|
|
130
129
|
* and **errors**.
|
|
131
130
|
*/
|
|
132
|
-
addAtIndex(item: IBunchItem, index: number, options: Partial<Omit<DTBunchOptions, '
|
|
131
|
+
addAtIndex(item: IBunchItem, index: number, options: Partial<Omit<DTBunchOptions, ''>> = {}): void {
|
|
133
132
|
const {
|
|
134
|
-
uniqueKey, replaceIndex, inheritOwner,
|
|
133
|
+
uniqueKey, replaceIndex, inheritOwner, virtualContainer,
|
|
135
134
|
}: Partial<DTBunchOptions> = { ...this._options, ...options };
|
|
136
135
|
let hasError = false;
|
|
137
136
|
let finalIndex = index;
|
|
@@ -171,13 +170,17 @@ export default class DYOToolsBunch<
|
|
|
171
170
|
finalIndex = this._items.length;
|
|
172
171
|
}
|
|
173
172
|
|
|
174
|
-
// Update Context
|
|
175
|
-
if (
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
173
|
+
// Update Context with manager
|
|
174
|
+
if (this._context) {
|
|
175
|
+
item.setContext(this._context);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
if (!virtualContainer) {
|
|
179
|
+
const oldContainer = item.getContainer();
|
|
180
|
+
if (oldContainer && oldContainer.getComponentType() === 'bunch') {
|
|
181
|
+
(oldContainer as DYOToolsBunch<IBunchItem, DTAcceptedMetaData>).remove(item.getId());
|
|
179
182
|
}
|
|
180
|
-
item.
|
|
183
|
+
item.setContainer(this);
|
|
181
184
|
}
|
|
182
185
|
|
|
183
186
|
// Update Owner
|
|
@@ -188,7 +191,7 @@ export default class DYOToolsBunch<
|
|
|
188
191
|
// Update Manager library
|
|
189
192
|
if (this.getContext('manager')) {
|
|
190
193
|
const manager: DYOToolsManager<IBunchItem> = this.getContext('manager') as DYOToolsManager<IBunchItem>;
|
|
191
|
-
if (!manager.getLibrary().get(item.getId())) {
|
|
194
|
+
if (manager.getLibrary().getId() !== this._id && !manager.getLibrary().get(item.getId())) {
|
|
192
195
|
manager.getLibrary().add(item);
|
|
193
196
|
}
|
|
194
197
|
}
|
|
@@ -214,7 +217,7 @@ export default class DYOToolsBunch<
|
|
|
214
217
|
* saved in current _options property. Available Options are : **uniqueKey**, **inheritOwner**, **replaceIndex**
|
|
215
218
|
* and **errors**.
|
|
216
219
|
*/
|
|
217
|
-
addMany(items: IBunchItem[], options: Partial<Omit<DTBunchOptions, '
|
|
220
|
+
addMany(items: IBunchItem[], options: Partial<Omit<DTBunchOptions, 'virtualContainer'>> = {}): void {
|
|
218
221
|
this.addManyAtIndex(items, this._items.length, options);
|
|
219
222
|
}
|
|
220
223
|
|
|
@@ -231,7 +234,7 @@ export default class DYOToolsBunch<
|
|
|
231
234
|
* saved in current _options property. Available Options are : **uniqueKey**, **inheritOwner**, **replaceIndex**
|
|
232
235
|
* and **errors**.
|
|
233
236
|
*/
|
|
234
|
-
addManyAtIndex(items: IBunchItem[], index: number, options: Partial<Omit<DTBunchOptions, '
|
|
237
|
+
addManyAtIndex(items: IBunchItem[], index: number, options: Partial<Omit<DTBunchOptions, 'virtualContainer'>> = {}): void {
|
|
235
238
|
const previousItems = this._items;
|
|
236
239
|
const { errors }: Partial<DTBunchOptions> = { ...this._options, ...options };
|
|
237
240
|
let currentIndex = index;
|
|
@@ -302,7 +305,8 @@ export default class DYOToolsBunch<
|
|
|
302
305
|
* * If a Number is provided, remove the DTElement instance at the corresponding index into _items.
|
|
303
306
|
* * If a String is provided, remove the DTElement instance with the corresponding _id property into _items.
|
|
304
307
|
*
|
|
305
|
-
* Note : Remove also the current
|
|
308
|
+
* Note : Remove also affectation to the current container of the removed item
|
|
309
|
+
* (only if Option **virtualContainer** is *false*).
|
|
306
310
|
*
|
|
307
311
|
* @param index Number index value or String _id value.
|
|
308
312
|
*/
|
|
@@ -321,24 +325,25 @@ export default class DYOToolsBunch<
|
|
|
321
325
|
* * If a Number Array is provided, remove DTElement instances at corresponding indexes into _items.
|
|
322
326
|
* * If a String Array is provided, remove DTElement instances with corresponding _id properties into _items.
|
|
323
327
|
*
|
|
324
|
-
* Note : Remove also the current
|
|
328
|
+
* Note : Remove also affectation to the current container of removed items
|
|
329
|
+
* (only if Option **virtualContainer** is *false*).
|
|
325
330
|
*
|
|
326
331
|
* @param indexes Number Array index values or String Array _id values.
|
|
327
332
|
*/
|
|
328
333
|
removeMany(indexes: string[] | number[]): void {
|
|
329
|
-
const {
|
|
334
|
+
const { virtualContainer } = this._options;
|
|
330
335
|
const newItems = [];
|
|
331
336
|
for (let i = 0; i < this._items.length; i += 1) {
|
|
332
337
|
if (typeof indexes[0] === 'number') {
|
|
333
338
|
if (!(indexes as number[]).includes(i)) {
|
|
334
339
|
newItems.push(this._items[i]);
|
|
335
|
-
} else if (!
|
|
336
|
-
this._items[i].
|
|
340
|
+
} else if (!virtualContainer) {
|
|
341
|
+
this._items[i].removeContainer();
|
|
337
342
|
}
|
|
338
343
|
} else if (!(indexes as string[]).includes(this._items[i].getId())) {
|
|
339
344
|
newItems.push(this._items[i]);
|
|
340
|
-
} else if (!
|
|
341
|
-
this._items[i].
|
|
345
|
+
} else if (!virtualContainer) {
|
|
346
|
+
this._items[i].removeContainer();
|
|
342
347
|
}
|
|
343
348
|
}
|
|
344
349
|
|
|
@@ -348,7 +353,8 @@ export default class DYOToolsBunch<
|
|
|
348
353
|
/**
|
|
349
354
|
* Remove all DTElement instances into the _items property.
|
|
350
355
|
*
|
|
351
|
-
* Note : Remove also the current
|
|
356
|
+
* Note : Remove also affectation to the current container of removed items
|
|
357
|
+
* (only if Option **virtualContainer** is *false*).
|
|
352
358
|
*/
|
|
353
359
|
removeAll(): void {
|
|
354
360
|
const keysToRemove: number[] = this._items.map((item, index) => index);
|
|
@@ -363,8 +369,8 @@ export default class DYOToolsBunch<
|
|
|
363
369
|
* Search filters can be applied on following DTElement properties :
|
|
364
370
|
* * **id** : property _id. Basic operators only.
|
|
365
371
|
* * **key** : property _key. Basic operators only.
|
|
366
|
-
* * **
|
|
367
|
-
* * **owner** : property
|
|
372
|
+
* * **container** : property _id of current _container instance. Basic operators only.
|
|
373
|
+
* * **owner** : property _owner. Basic operators only.
|
|
368
374
|
* * **meta** : each meta Key of _meta property. Extended operators can be used.
|
|
369
375
|
*
|
|
370
376
|
* Examples of **filters** argument :
|
|
@@ -397,7 +403,7 @@ export default class DYOToolsBunch<
|
|
|
397
403
|
*/
|
|
398
404
|
copy(): DYOToolsBunch<IBunchItem, IComponentMeta> {
|
|
399
405
|
let copyItems;
|
|
400
|
-
if (this._options.
|
|
406
|
+
if (this._options.virtualContainer) {
|
|
401
407
|
copyItems = this._items;
|
|
402
408
|
} else {
|
|
403
409
|
copyItems = this._items.length === 0 ? [] : this._items.map((item) => item.copy() as IBunchItem);
|
|
@@ -417,7 +423,7 @@ export default class DYOToolsBunch<
|
|
|
417
423
|
* * **key** : _key property of the Bunch.
|
|
418
424
|
* * **type** : _componentType property of the Bunch.
|
|
419
425
|
* * **items** : Array of JSON Object representation for each DTElement instance in _items property of the Bunch.
|
|
420
|
-
* * **owner** : String
|
|
426
|
+
* * **owner** : String current value of _owner property of the Bunch (only if defined).
|
|
421
427
|
* * **meta** : JSON Object of all current metadata in _meta property of the Bunch (only if not empty).
|
|
422
428
|
*
|
|
423
429
|
* @returns JSON Object representation of the Bunch.
|
|
@@ -453,7 +459,7 @@ export default class DYOToolsBunch<
|
|
|
453
459
|
toString(): string {
|
|
454
460
|
let ownerKey = '';
|
|
455
461
|
if (this._owner) {
|
|
456
|
-
ownerKey = ` - Owner: ${this._owner
|
|
462
|
+
ownerKey = ` - Owner: ${this._owner}`;
|
|
457
463
|
}
|
|
458
464
|
|
|
459
465
|
return `Component ${this._key} - Type: Bunch${ownerKey} - Items: ${this._items.length}`;
|
package/src/core/DTComponent.ts
CHANGED
|
@@ -20,7 +20,7 @@ export default abstract class DYOToolsComponent<IComponentOptions extends DTComp
|
|
|
20
20
|
/**
|
|
21
21
|
* Component Parent Context.
|
|
22
22
|
*
|
|
23
|
-
* A component can have only one *
|
|
23
|
+
* A component can have only one *context*, and be managed by a parent Component.
|
|
24
24
|
*/
|
|
25
25
|
protected _context?: DYOToolsComponent;
|
|
26
26
|
|
|
@@ -1,27 +1,42 @@
|
|
|
1
1
|
import { DTAcceptedMetaData, DTComponentOptions } from '../types';
|
|
2
2
|
import DYOToolsComponentWithMeta from './DTComponentWithMeta';
|
|
3
|
-
import
|
|
3
|
+
import DYOToolsMaster from './DTMaster';
|
|
4
|
+
import DYOToolsManager from "./DTManager";
|
|
4
5
|
|
|
5
6
|
export default abstract class DYOToolsComponentPhysical<
|
|
6
7
|
IComponentMeta extends DTAcceptedMetaData,
|
|
7
8
|
IComponentOptions extends DTComponentOptions = DTComponentOptions,
|
|
8
9
|
> extends DYOToolsComponentWithMeta<IComponentMeta, IComponentOptions> {
|
|
9
10
|
/**
|
|
10
|
-
* Owner
|
|
11
|
+
* Owner string representation, if defined.
|
|
11
12
|
*/
|
|
12
|
-
protected _owner?:
|
|
13
|
+
protected _owner?: string;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Returns Manager component from context, or undefined.
|
|
17
|
+
*/
|
|
18
|
+
getManager(): DYOToolsManager | undefined {
|
|
19
|
+
return this.getContext<DYOToolsManager>('manager');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Returns Master component from context, or undefined.
|
|
24
|
+
*/
|
|
25
|
+
getMaster(): DYOToolsMaster | undefined {
|
|
26
|
+
return this.getContext<DYOToolsMaster>('master');
|
|
27
|
+
}
|
|
13
28
|
|
|
14
29
|
/**
|
|
15
30
|
* Getter for _owner property.
|
|
16
31
|
*/
|
|
17
|
-
getOwner():
|
|
32
|
+
getOwner(): string {
|
|
18
33
|
return this._owner;
|
|
19
34
|
}
|
|
20
35
|
|
|
21
36
|
/**
|
|
22
37
|
* Setter for _owner property.
|
|
23
38
|
*/
|
|
24
|
-
setOwner(value:
|
|
39
|
+
setOwner(value: string): void {
|
|
25
40
|
this._owner = value;
|
|
26
41
|
}
|
|
27
42
|
|
package/src/core/DTElement.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { DTAcceptedMetaData, DTElementToObject } from '../types';
|
|
2
2
|
import DYOToolsComponentPhysical from './DTComponentPhysical';
|
|
3
|
+
import DYOToolsBunch from './DTBunch';
|
|
3
4
|
|
|
4
5
|
export default class DYOToolsElement<
|
|
5
6
|
IComponentMeta extends DTAcceptedMetaData,
|
|
@@ -9,6 +10,37 @@ export default class DYOToolsElement<
|
|
|
9
10
|
*/
|
|
10
11
|
protected _componentType = 'element';
|
|
11
12
|
|
|
13
|
+
/**
|
|
14
|
+
* Component current **Container**.
|
|
15
|
+
*
|
|
16
|
+
* A container is a parent component which "contains" the current instance.
|
|
17
|
+
* **Context** and **container** are different components, with different purpose.
|
|
18
|
+
* For DYOToolsElement instances, a container is a DYOToolsBunch instance.
|
|
19
|
+
* @protected
|
|
20
|
+
*/
|
|
21
|
+
protected _container: DYOToolsBunch;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Getter for _container property.
|
|
25
|
+
*/
|
|
26
|
+
getContainer(): DYOToolsBunch | undefined {
|
|
27
|
+
return this._container;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Setter for _container property.
|
|
32
|
+
*/
|
|
33
|
+
setContainer(container: DYOToolsBunch): void {
|
|
34
|
+
this._container = container;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Remove the current container of Element instance.
|
|
39
|
+
*/
|
|
40
|
+
removeContainer(): void {
|
|
41
|
+
this._container = undefined;
|
|
42
|
+
}
|
|
43
|
+
|
|
12
44
|
/**
|
|
13
45
|
* Create and return a new DTElement instance by applying from current instance :
|
|
14
46
|
* - Copy _key property
|
|
@@ -61,9 +93,10 @@ export default class DYOToolsElement<
|
|
|
61
93
|
toString(): string {
|
|
62
94
|
let ownerKey = '';
|
|
63
95
|
if (this._owner) {
|
|
64
|
-
ownerKey = ` - Owner: ${this._owner
|
|
96
|
+
ownerKey = ` - Owner: ${this._owner}`;
|
|
65
97
|
}
|
|
98
|
+
const domainLabel = this._domain ? ` ${this._domain}` : '';
|
|
66
99
|
|
|
67
|
-
return `Component ${this._key} - Type: Element${ownerKey}`;
|
|
100
|
+
return `Component${domainLabel} ${this._key} - Type: Element${ownerKey}`;
|
|
68
101
|
}
|
|
69
102
|
}
|
package/src/core/DTManager.ts
CHANGED
|
@@ -14,9 +14,10 @@ import {
|
|
|
14
14
|
import DYOFinder from '../libs/DYOFinder';
|
|
15
15
|
import { componentManagerDefaultFinderConfiguration, managerDefaultOptions as defaultOptions } from '../constants';
|
|
16
16
|
import DYOToolsElement from './DTElement';
|
|
17
|
+
import DYOToolsMaster from './DTMaster';
|
|
17
18
|
|
|
18
19
|
export default class DYOToolsManager<
|
|
19
|
-
IBunchItem extends DYOToolsElement<DTAcceptedMetaData>,
|
|
20
|
+
IBunchItem extends DYOToolsElement<DTAcceptedMetaData> = DYOToolsElement<DTAcceptedMetaData>,
|
|
20
21
|
> extends DYOToolsComponent<DTManagerOptions> {
|
|
21
22
|
/**
|
|
22
23
|
* Defining component type to "manager".
|
|
@@ -81,7 +82,9 @@ export default class DYOToolsManager<
|
|
|
81
82
|
'virtual',
|
|
82
83
|
...scopes,
|
|
83
84
|
];
|
|
84
|
-
this._library = new DYOToolsBunch('library', elements, {
|
|
85
|
+
this._library = new DYOToolsBunch('library', elements, { virtualContainer: true });
|
|
86
|
+
this._library.setContext(this);
|
|
87
|
+
|
|
85
88
|
this._finder = new DYOFinder(this, this.getFinderConfiguration());
|
|
86
89
|
}
|
|
87
90
|
|
|
@@ -126,8 +129,8 @@ export default class DYOToolsManager<
|
|
|
126
129
|
* The adding process has the following specifications :
|
|
127
130
|
* * If the added item has the same _id than existing item, an error occurred (depending on **errors** option).
|
|
128
131
|
* * The bunch item is automatically added to a scope depending on its virtual context :
|
|
129
|
-
* * * *default* if the bunch option **
|
|
130
|
-
* * * *virtual* if the bunch option **
|
|
132
|
+
* * * *default* if the bunch option **virtualContainer** is false.
|
|
133
|
+
* * * *virtual* if the bunch option **virtualContainer** is true.
|
|
131
134
|
* * An optional parameter **targetScope** can be passed to force the scope affectation.
|
|
132
135
|
* An error occurred if the affection doesn't conform to the following restrictions :
|
|
133
136
|
* * * Virtual context bunch must be affected to the 'virtual' scope.
|
|
@@ -154,12 +157,12 @@ export default class DYOToolsManager<
|
|
|
154
157
|
}
|
|
155
158
|
|
|
156
159
|
// Define scope validity
|
|
157
|
-
const {
|
|
160
|
+
const { virtualContainer } = item.getOptions();
|
|
158
161
|
let scope;
|
|
159
162
|
if (!targetScope) {
|
|
160
|
-
scope =
|
|
163
|
+
scope = virtualContainer ? 'virtual' : 'default';
|
|
161
164
|
} else {
|
|
162
|
-
const { code: errorCode, message: errorMessage } = this.getErrorDataForScope(targetScope,
|
|
165
|
+
const { code: errorCode, message: errorMessage } = this.getErrorDataForScope(targetScope, virtualContainer);
|
|
163
166
|
|
|
164
167
|
if (errorCode && errorMessage) {
|
|
165
168
|
this.triggerError(new DYOToolsError(errorCode, errorMessage, this, item));
|
|
@@ -178,12 +181,18 @@ export default class DYOToolsManager<
|
|
|
178
181
|
}
|
|
179
182
|
|
|
180
183
|
// Update context
|
|
184
|
+
// Bunch
|
|
181
185
|
item.setContext<DYOToolsManager<IBunchItem>>(this);
|
|
182
186
|
const oldContext = item.getContext();
|
|
183
187
|
if (oldContext && oldContext.getComponentType() === 'manager') {
|
|
184
188
|
(oldContext as DYOToolsManager<IBunchItem>).remove(item.getId());
|
|
185
189
|
}
|
|
186
190
|
|
|
191
|
+
// Elements children
|
|
192
|
+
item.getAll().forEach((element) => {
|
|
193
|
+
element.setContext<DYOToolsManager<IBunchItem>>(this);
|
|
194
|
+
});
|
|
195
|
+
|
|
187
196
|
// Add the new item
|
|
188
197
|
this._items[item.getId()] = {
|
|
189
198
|
scope,
|
|
@@ -235,8 +244,8 @@ export default class DYOToolsManager<
|
|
|
235
244
|
|
|
236
245
|
const bunch = this._items[bunchId].item;
|
|
237
246
|
|
|
238
|
-
const {
|
|
239
|
-
const { code: errorCode, message: errorMessage } = this.getErrorDataForScope(targetScope,
|
|
247
|
+
const { virtualContainer } = bunch.getOptions();
|
|
248
|
+
const { code: errorCode, message: errorMessage } = this.getErrorDataForScope(targetScope, virtualContainer);
|
|
240
249
|
if (errorCode && errorMessage) {
|
|
241
250
|
this.triggerError(new DYOToolsError(errorCode, errorMessage, this, bunch));
|
|
242
251
|
return;
|
|
@@ -282,6 +291,13 @@ export default class DYOToolsManager<
|
|
|
282
291
|
return this._items[id] && this._items[id].scope;
|
|
283
292
|
}
|
|
284
293
|
|
|
294
|
+
/**
|
|
295
|
+
* Returns Master component from context, or undefined.
|
|
296
|
+
*/
|
|
297
|
+
getMaster(): DYOToolsMaster | undefined {
|
|
298
|
+
return this.getContext<DYOToolsMaster>('master');
|
|
299
|
+
}
|
|
300
|
+
|
|
285
301
|
/**
|
|
286
302
|
* Remove one bunch into the _items property of the Manager, depending on its id.
|
|
287
303
|
*
|
|
@@ -309,12 +325,14 @@ export default class DYOToolsManager<
|
|
|
309
325
|
|
|
310
326
|
ids.forEach((id: string) => {
|
|
311
327
|
if (this._items[id]) {
|
|
312
|
-
|
|
313
|
-
|
|
328
|
+
this._items[id].item.getAll().forEach((item: IBunchItem) => {
|
|
329
|
+
if (libraryDeletion) {
|
|
314
330
|
this._library.remove(item.getId());
|
|
315
|
-
}
|
|
316
|
-
|
|
331
|
+
}
|
|
332
|
+
item.removeContext();
|
|
333
|
+
});
|
|
317
334
|
|
|
335
|
+
this._items[id].item.removeContext();
|
|
318
336
|
delete this._items[id];
|
|
319
337
|
}
|
|
320
338
|
});
|
|
@@ -415,28 +433,29 @@ export default class DYOToolsManager<
|
|
|
415
433
|
*/
|
|
416
434
|
toString(): string {
|
|
417
435
|
const libraryLabel = `Library: ${this._library.getAll().length}`;
|
|
436
|
+
const domainLabel = this._domain ? ` ${this._domain}` : '';
|
|
418
437
|
|
|
419
|
-
return `Component ${this._key} - Type: Manager - ${libraryLabel} - Items: ${Object.keys(this._items).length}`;
|
|
438
|
+
return `Component${domainLabel} ${this._key} - Type: Manager - ${libraryLabel} - Items: ${Object.keys(this._items).length}`;
|
|
420
439
|
}
|
|
421
440
|
|
|
422
441
|
/**
|
|
423
442
|
* Get error data for scope affectation. Used in method which performs scope affectation.
|
|
424
443
|
*
|
|
425
444
|
* @param targetScope scope name to check for affectation.
|
|
426
|
-
* @param
|
|
445
|
+
* @param virtualContainer boolean if the bunch to affect has **virtualContainer** option enabled or not. Default *false*.
|
|
427
446
|
* @returns An Object with error code and message.
|
|
428
447
|
*/
|
|
429
|
-
private getErrorDataForScope(targetScope: string,
|
|
448
|
+
private getErrorDataForScope(targetScope: string, virtualContainer = false): { code: string, message: string } {
|
|
430
449
|
const response = { code: '', message: '' };
|
|
431
450
|
if (!this.isValidScope(targetScope)) {
|
|
432
451
|
response.code = 'invalid_scope';
|
|
433
452
|
response.message = "Scope provided doesn't exist in the manager";
|
|
434
453
|
}
|
|
435
|
-
if (
|
|
454
|
+
if (virtualContainer && targetScope !== 'virtual') {
|
|
436
455
|
response.code = 'forbidden_scope';
|
|
437
456
|
response.message = 'Scope provided cannot be associated to a virtual bunch';
|
|
438
457
|
}
|
|
439
|
-
if (!
|
|
458
|
+
if (!virtualContainer && targetScope === 'virtual') {
|
|
440
459
|
response.code = 'forbidden_virtual_scope';
|
|
441
460
|
response.message = 'Virtual Scope provided cannot be associated to a physical bunch';
|
|
442
461
|
}
|