@vived/host 3.0.0 → 3.1.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/lib/Components/Assets/Entities/AssetEntity.d.ts +1 -1
- package/lib/Components/Assets/Entities/AssetEntity.js +11 -9
- package/lib/Components/Assets/Mocks/MockPrefetchAssets.d.ts +8 -0
- package/lib/Components/Assets/Mocks/MockPrefetchAssets.js +15 -0
- package/lib/Components/Assets/Mocks/index.d.ts +1 -0
- package/lib/Components/Assets/Mocks/index.js +1 -0
- package/lib/Components/Assets/UCs/PrefetchAssetsUC.d.ts +7 -0
- package/lib/Components/Assets/UCs/PrefetchAssetsUC.js +69 -0
- package/lib/Components/Assets/UCs/index.d.ts +9 -8
- package/lib/Components/Assets/UCs/index.js +1 -0
- package/lib/Components/Handler/UCs/HasNextStateHandler.js +15 -2
- package/lib/Components/Handler/UCs/HasPreviousStateHandler.js +15 -2
- package/lib/Components/Handler/UCs/OnStateChangeHandler.d.ts +3 -1
- package/lib/Components/Handler/UCs/OnStateChangeHandler.js +39 -2
- package/lib/Components/StateMachine/Adapters/hostStateMachinePMAdapter.d.ts +3 -0
- package/lib/Components/StateMachine/Adapters/hostStateMachinePMAdapter.js +23 -0
- package/lib/Components/StateMachine/Adapters/hostStateMachinePMAdater.d.ts +3 -0
- package/lib/Components/StateMachine/Adapters/hostStateMachinePMAdater.js +23 -0
- package/lib/Components/StateMachine/Adapters/index.d.ts +2 -0
- package/lib/Components/StateMachine/Adapters/index.js +14 -0
- package/lib/Components/StateMachine/Adapters/isEditingPMAdapter.d.ts +3 -0
- package/lib/Components/StateMachine/Adapters/isEditingPMAdapter.js +23 -0
- package/lib/Components/StateMachine/Controllers/deleteState.d.ts +2 -0
- package/lib/Components/StateMachine/Controllers/deleteState.js +13 -0
- package/lib/Components/StateMachine/Controllers/duplicateState.d.ts +2 -0
- package/lib/Components/StateMachine/Controllers/duplicateState.js +13 -0
- package/lib/Components/StateMachine/Controllers/index.d.ts +2 -0
- package/lib/Components/StateMachine/Controllers/index.js +14 -0
- package/lib/Components/StateMachine/Entities/HostEditingStateEntity.d.ts +16 -0
- package/lib/Components/StateMachine/Entities/HostEditingStateEntity.js +121 -0
- package/lib/Components/StateMachine/Entities/HostStateEntity.d.ts +31 -0
- package/lib/Components/StateMachine/Entities/HostStateEntity.js +124 -0
- package/lib/Components/StateMachine/Entities/HostStateMachine.d.ts +20 -0
- package/lib/Components/StateMachine/Entities/HostStateMachine.js +161 -0
- package/lib/Components/StateMachine/Entities/index.d.ts +3 -0
- package/lib/Components/StateMachine/Entities/index.js +15 -0
- package/lib/Components/StateMachine/Mocks/MockDeleteStateUC.d.ts +8 -0
- package/lib/Components/StateMachine/Mocks/MockDeleteStateUC.js +15 -0
- package/lib/Components/StateMachine/Mocks/MockDuplicateStateUC.d.ts +8 -0
- package/lib/Components/StateMachine/Mocks/MockDuplicateStateUC.js +15 -0
- package/lib/Components/StateMachine/Mocks/MockHostEditingStateEntity.d.ts +16 -0
- package/lib/Components/StateMachine/Mocks/MockHostEditingStateEntity.js +30 -0
- package/lib/Components/StateMachine/Mocks/MockHostStateMachinePM.d.ts +8 -0
- package/lib/Components/StateMachine/Mocks/MockHostStateMachinePM.js +15 -0
- package/lib/Components/StateMachine/Mocks/MockIsEditingStatePM.d.ts +8 -0
- package/lib/Components/StateMachine/Mocks/MockIsEditingStatePM.js +15 -0
- package/lib/Components/StateMachine/Mocks/MockStateEntity.d.ts +16 -0
- package/lib/Components/StateMachine/Mocks/MockStateEntity.js +27 -0
- package/lib/Components/StateMachine/Mocks/index.d.ts +6 -0
- package/lib/Components/StateMachine/Mocks/index.js +18 -0
- package/lib/Components/StateMachine/PMs/EditingStatePM.d.ts +19 -0
- package/lib/Components/StateMachine/PMs/EditingStatePM.js +54 -0
- package/lib/Components/StateMachine/PMs/HostStateMachinePM.d.ts +23 -0
- package/lib/Components/StateMachine/PMs/HostStateMachinePM.js +70 -0
- package/lib/Components/StateMachine/PMs/IsEditingStatePM.d.ts +13 -0
- package/lib/Components/StateMachine/PMs/IsEditingStatePM.js +36 -0
- package/lib/Components/StateMachine/PMs/index.d.ts +2 -0
- package/lib/Components/StateMachine/PMs/index.js +14 -0
- package/lib/Components/StateMachine/UCs/DeleteStateUC.d.ts +7 -0
- package/lib/Components/StateMachine/UCs/DeleteStateUC.js +37 -0
- package/lib/Components/StateMachine/UCs/DuplicateStateUC.d.ts +7 -0
- package/lib/Components/StateMachine/UCs/DuplicateStateUC.js +39 -0
- package/lib/Components/StateMachine/UCs/index.d.ts +2 -0
- package/lib/Components/StateMachine/UCs/index.js +14 -0
- package/lib/Components/StateMachine/index.d.ts +6 -0
- package/lib/Components/StateMachine/index.js +18 -0
- package/lib/Components/index.d.ts +1 -0
- package/lib/Components/index.js +1 -0
- package/lib/Types/ReactHookPmAdapter.d.ts +6 -0
- package/lib/Types/ReactHookPmAdapter.js +2 -0
- package/lib/Types/index.d.ts +1 -0
- package/lib/Types/index.js +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeHostEditingStateEntity = exports.HostEditingStateEntity = void 0;
|
|
4
|
+
const Entities_1 = require("../../../Entities");
|
|
5
|
+
const HostAppObject_1 = require("../../../HostAppObject");
|
|
6
|
+
const HostStateMachine_1 = require("./HostStateMachine");
|
|
7
|
+
class HostEditingStateEntity extends HostAppObject_1.HostAppObjectEntity {
|
|
8
|
+
static get(appObjects) {
|
|
9
|
+
return HostAppObject_1.getSingletonComponent(HostEditingStateEntity.type, appObjects);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
exports.HostEditingStateEntity = HostEditingStateEntity;
|
|
13
|
+
HostEditingStateEntity.type = "HostEditingStateEntity";
|
|
14
|
+
function makeHostEditingStateEntity(appObject) {
|
|
15
|
+
return new HostEditingStateEntityImp(appObject);
|
|
16
|
+
}
|
|
17
|
+
exports.makeHostEditingStateEntity = makeHostEditingStateEntity;
|
|
18
|
+
class HostEditingStateEntityImp extends HostEditingStateEntity {
|
|
19
|
+
constructor(appObject) {
|
|
20
|
+
super(appObject, HostEditingStateEntity.type);
|
|
21
|
+
this._isNewState = false;
|
|
22
|
+
this.memoizedSomethingHasChanged = new Entities_1.MemoizedBoolean(false, this.notifyOnChange);
|
|
23
|
+
this.checkForChange = () => {
|
|
24
|
+
var _a, _b;
|
|
25
|
+
if (!this._editingState)
|
|
26
|
+
return false;
|
|
27
|
+
if (!this.originalStateData)
|
|
28
|
+
return true;
|
|
29
|
+
if (this._editingState.name !== this.originalStateData.name)
|
|
30
|
+
return true;
|
|
31
|
+
if (this._editingState.expectedResponse !== this.originalStateData.response)
|
|
32
|
+
return true;
|
|
33
|
+
if (this._editingState.assets.length !== this.originalStateData.assets.length)
|
|
34
|
+
return true;
|
|
35
|
+
let assetsHaveChanged = false;
|
|
36
|
+
this._editingState.assets.forEach((currentAssetID, i) => {
|
|
37
|
+
const originalAssetId = this.originalStateData.assets[i];
|
|
38
|
+
if (originalAssetId !== currentAssetID) {
|
|
39
|
+
assetsHaveChanged = true;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
if (assetsHaveChanged) {
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
const currentDataString = JSON.stringify(this._editingState.stateData);
|
|
46
|
+
const originalData = JSON.stringify((_b = (_a = this.originalStateData) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : "");
|
|
47
|
+
if (currentDataString !== originalData)
|
|
48
|
+
return true;
|
|
49
|
+
return false;
|
|
50
|
+
};
|
|
51
|
+
this.onStateEntityChange = () => {
|
|
52
|
+
this.memoizedSomethingHasChanged.val = this.checkForChange();
|
|
53
|
+
};
|
|
54
|
+
this.startNewState = () => {
|
|
55
|
+
if (!this.hostStateMachine)
|
|
56
|
+
return;
|
|
57
|
+
this.originalStateData = undefined;
|
|
58
|
+
this._isNewState = true;
|
|
59
|
+
this._editingState = this.hostStateMachine.createNewState();
|
|
60
|
+
this._editingState.addChangeObserver(this.onStateEntityChange);
|
|
61
|
+
this.memoizedSomethingHasChanged.val = true;
|
|
62
|
+
return this._editingState;
|
|
63
|
+
};
|
|
64
|
+
this.startEditing = (state) => {
|
|
65
|
+
this._editingState = state;
|
|
66
|
+
this.originalStateData = state.getDTO();
|
|
67
|
+
this._editingState.addChangeObserver(this.onStateEntityChange);
|
|
68
|
+
this.notifyOnChange();
|
|
69
|
+
};
|
|
70
|
+
this.cancelEditState = () => {
|
|
71
|
+
var _a;
|
|
72
|
+
if (!this._editingState)
|
|
73
|
+
return;
|
|
74
|
+
if (this.originalStateData) {
|
|
75
|
+
this._editingState.setDTO(this.originalStateData);
|
|
76
|
+
}
|
|
77
|
+
else {
|
|
78
|
+
(_a = this.hostStateMachine) === null || _a === void 0 ? void 0 : _a.deleteState(this._editingState.id);
|
|
79
|
+
}
|
|
80
|
+
this.resetInternalState();
|
|
81
|
+
};
|
|
82
|
+
this.finishEditing = () => {
|
|
83
|
+
this.resetInternalState();
|
|
84
|
+
};
|
|
85
|
+
this.resetInternalState = () => {
|
|
86
|
+
if (!this._editingState)
|
|
87
|
+
return;
|
|
88
|
+
this._isNewState = false;
|
|
89
|
+
this._editingState.removeChangeObserver(this.onStateEntityChange);
|
|
90
|
+
this._stateValidationMessage = undefined;
|
|
91
|
+
this._editingState = undefined;
|
|
92
|
+
this.memoizedSomethingHasChanged.val = false;
|
|
93
|
+
this.notifyOnChange();
|
|
94
|
+
};
|
|
95
|
+
this.appObjects.registerSingleton(this);
|
|
96
|
+
}
|
|
97
|
+
get isNewState() {
|
|
98
|
+
return this._isNewState;
|
|
99
|
+
}
|
|
100
|
+
get stateValidationMessage() {
|
|
101
|
+
return this._stateValidationMessage;
|
|
102
|
+
}
|
|
103
|
+
set stateValidationMessage(val) {
|
|
104
|
+
if (this._stateValidationMessage === val)
|
|
105
|
+
return;
|
|
106
|
+
this._stateValidationMessage = val;
|
|
107
|
+
this.notifyOnChange();
|
|
108
|
+
}
|
|
109
|
+
get hostStateMachine() {
|
|
110
|
+
return this.getCachedSingleton(HostStateMachine_1.HostStateMachine.type);
|
|
111
|
+
}
|
|
112
|
+
get somethingHasChanged() {
|
|
113
|
+
return this.memoizedSomethingHasChanged.val;
|
|
114
|
+
}
|
|
115
|
+
get isEditing() {
|
|
116
|
+
return this._editingState !== undefined;
|
|
117
|
+
}
|
|
118
|
+
get editingState() {
|
|
119
|
+
return this._editingState;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { HostAppObject, HostAppObjectEntity, HostAppObjectRepo } from "../../../HostAppObject";
|
|
2
|
+
export declare enum ChallengeResponse {
|
|
3
|
+
NONE = "NONE",
|
|
4
|
+
SCORE = "SCORE",
|
|
5
|
+
HIT = "HIT",
|
|
6
|
+
MULTIHIT = "MULTIHIT",
|
|
7
|
+
PROGRESS = "PROGRESS",
|
|
8
|
+
QUALITY = "QUALITY"
|
|
9
|
+
}
|
|
10
|
+
export interface StateDTO {
|
|
11
|
+
id: string;
|
|
12
|
+
name: string;
|
|
13
|
+
data: object;
|
|
14
|
+
assets: string[];
|
|
15
|
+
response: string | undefined;
|
|
16
|
+
appID: string;
|
|
17
|
+
}
|
|
18
|
+
export declare abstract class HostStateEntity extends HostAppObjectEntity {
|
|
19
|
+
static type: string;
|
|
20
|
+
abstract get id(): string;
|
|
21
|
+
abstract name: string;
|
|
22
|
+
abstract assets: string[];
|
|
23
|
+
abstract expectedResponse: ChallengeResponse | undefined;
|
|
24
|
+
abstract appID: string;
|
|
25
|
+
abstract getDTO(): StateDTO;
|
|
26
|
+
abstract setDTO(dto: StateDTO): void;
|
|
27
|
+
abstract get stateData(): object;
|
|
28
|
+
abstract setStateData(val: object, checkForChange?: boolean): void;
|
|
29
|
+
static get(id: string, appObjects: HostAppObjectRepo): HostStateEntity | undefined;
|
|
30
|
+
}
|
|
31
|
+
export declare function makeHostStateEntity(appObject: HostAppObject): HostStateEntity;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeHostStateEntity = exports.HostStateEntity = exports.ChallengeResponse = void 0;
|
|
4
|
+
const Entities_1 = require("../../../Entities");
|
|
5
|
+
const HostAppObject_1 = require("../../../HostAppObject");
|
|
6
|
+
var ChallengeResponse;
|
|
7
|
+
(function (ChallengeResponse) {
|
|
8
|
+
ChallengeResponse["NONE"] = "NONE";
|
|
9
|
+
ChallengeResponse["SCORE"] = "SCORE";
|
|
10
|
+
ChallengeResponse["HIT"] = "HIT";
|
|
11
|
+
ChallengeResponse["MULTIHIT"] = "MULTIHIT";
|
|
12
|
+
ChallengeResponse["PROGRESS"] = "PROGRESS";
|
|
13
|
+
ChallengeResponse["QUALITY"] = "QUALITY";
|
|
14
|
+
})(ChallengeResponse = exports.ChallengeResponse || (exports.ChallengeResponse = {}));
|
|
15
|
+
class HostStateEntity extends HostAppObject_1.HostAppObjectEntity {
|
|
16
|
+
static get(id, appObjects) {
|
|
17
|
+
const ao = appObjects.get(id);
|
|
18
|
+
return ao === null || ao === void 0 ? void 0 : ao.getComponent(HostStateEntity.type);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
exports.HostStateEntity = HostStateEntity;
|
|
22
|
+
HostStateEntity.type = "HostStateEntity";
|
|
23
|
+
function makeHostStateEntity(appObject) {
|
|
24
|
+
return new HostStateEntityImp(appObject);
|
|
25
|
+
}
|
|
26
|
+
exports.makeHostStateEntity = makeHostStateEntity;
|
|
27
|
+
class HostStateEntityImp extends HostStateEntity {
|
|
28
|
+
constructor(appObject) {
|
|
29
|
+
super(appObject, HostStateEntity.type);
|
|
30
|
+
this.memoizedName = new Entities_1.MemoizedString("", this.notifyOnChange);
|
|
31
|
+
this._data = {};
|
|
32
|
+
this._assets = [];
|
|
33
|
+
this.memoisedAppID = new Entities_1.MemoizedString("", this.notifyOnChange);
|
|
34
|
+
}
|
|
35
|
+
get id() {
|
|
36
|
+
return this.appObject.id;
|
|
37
|
+
}
|
|
38
|
+
get name() {
|
|
39
|
+
return this.memoizedName.val;
|
|
40
|
+
}
|
|
41
|
+
set name(val) {
|
|
42
|
+
this.memoizedName.val = val;
|
|
43
|
+
}
|
|
44
|
+
get stateData() {
|
|
45
|
+
return this._data;
|
|
46
|
+
}
|
|
47
|
+
setStateData(val, checkForChange) {
|
|
48
|
+
let notify = true;
|
|
49
|
+
if (checkForChange) {
|
|
50
|
+
const currentData = JSON.stringify(this._data);
|
|
51
|
+
const newData = JSON.stringify(val);
|
|
52
|
+
if (currentData === newData) {
|
|
53
|
+
notify = false;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
this._data = val;
|
|
57
|
+
if (notify) {
|
|
58
|
+
this.notifyOnChange();
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
get assets() {
|
|
62
|
+
return [...this._assets];
|
|
63
|
+
}
|
|
64
|
+
set assets(val) {
|
|
65
|
+
if (val.length !== this._assets.length) {
|
|
66
|
+
this._assets = val;
|
|
67
|
+
this.notifyOnChange();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
let somethingHasChanged = false;
|
|
71
|
+
val.forEach((newAsset, i) => {
|
|
72
|
+
const existingAsset = this._assets[i];
|
|
73
|
+
if (existingAsset !== newAsset) {
|
|
74
|
+
somethingHasChanged = true;
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
if (!somethingHasChanged) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
this._assets = val;
|
|
81
|
+
this.notifyOnChange();
|
|
82
|
+
}
|
|
83
|
+
get expectedResponse() {
|
|
84
|
+
return this._expectedResponse;
|
|
85
|
+
}
|
|
86
|
+
set expectedResponse(val) {
|
|
87
|
+
if (val === this._expectedResponse)
|
|
88
|
+
return;
|
|
89
|
+
this._expectedResponse = val;
|
|
90
|
+
this.notifyOnChange();
|
|
91
|
+
}
|
|
92
|
+
getDTO() {
|
|
93
|
+
return {
|
|
94
|
+
id: this.id,
|
|
95
|
+
assets: [...this._assets],
|
|
96
|
+
data: this._data,
|
|
97
|
+
name: this.memoizedName.val,
|
|
98
|
+
response: this._expectedResponse,
|
|
99
|
+
appID: this.appID
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
setDTO(dto) {
|
|
103
|
+
if (dto.id !== this.id) {
|
|
104
|
+
this.warn("DTO id does not match my ID. Skipping");
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
this.setStateData(dto.data, true);
|
|
108
|
+
this.assets = [...dto.assets];
|
|
109
|
+
this.memoizedName.val = dto.name;
|
|
110
|
+
this.memoisedAppID.val = dto.appID;
|
|
111
|
+
if (Object.values(ChallengeResponse).includes(dto.response)) {
|
|
112
|
+
this.expectedResponse = dto.response;
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
this.expectedResponse = undefined;
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
get appID() {
|
|
119
|
+
return this.memoisedAppID.val;
|
|
120
|
+
}
|
|
121
|
+
set appID(val) {
|
|
122
|
+
this.memoisedAppID.val = val;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { HostAppObject, HostAppObjectEntity, HostAppObjectRepo } from "../../../HostAppObject";
|
|
2
|
+
import { HostStateEntity } from "./HostStateEntity";
|
|
3
|
+
export declare abstract class HostStateMachine extends HostAppObjectEntity {
|
|
4
|
+
static type: string;
|
|
5
|
+
abstract states: string[];
|
|
6
|
+
abstract activeState: string | undefined;
|
|
7
|
+
abstract previousState: string | undefined;
|
|
8
|
+
abstract nextState: string | undefined;
|
|
9
|
+
abstract setActiveStateByID: (id: string) => void;
|
|
10
|
+
abstract clearActiveState: () => void;
|
|
11
|
+
abstract setStates: (states: HostStateEntity[]) => void;
|
|
12
|
+
abstract createNewState: () => HostStateEntity;
|
|
13
|
+
abstract getStateByID: (id: string) => HostStateEntity | undefined;
|
|
14
|
+
abstract deleteState: (id: string) => void;
|
|
15
|
+
abstract getStateIndex: (id: string) => number | undefined;
|
|
16
|
+
abstract hasState: (id: string) => boolean;
|
|
17
|
+
abstract stateFactory: (id: string) => HostStateEntity;
|
|
18
|
+
static get(appObjects: HostAppObjectRepo): HostStateMachine | undefined;
|
|
19
|
+
}
|
|
20
|
+
export declare function makeHostStateMachine(appObject: HostAppObject): HostStateMachine;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeHostStateMachine = exports.HostStateMachine = void 0;
|
|
4
|
+
const Entities_1 = require("../../../Entities");
|
|
5
|
+
const HostAppObject_1 = require("../../../HostAppObject");
|
|
6
|
+
const Utilities_1 = require("../../../Utilities");
|
|
7
|
+
const HostStateEntity_1 = require("./HostStateEntity");
|
|
8
|
+
class HostStateMachine extends HostAppObject_1.HostAppObjectEntity {
|
|
9
|
+
static get(appObjects) {
|
|
10
|
+
return HostAppObject_1.getSingletonComponent(HostStateMachine.type, appObjects);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.HostStateMachine = HostStateMachine;
|
|
14
|
+
HostStateMachine.type = "HostStateMachine";
|
|
15
|
+
function makeHostStateMachine(appObject) {
|
|
16
|
+
return new HostStateMachineImp(appObject);
|
|
17
|
+
}
|
|
18
|
+
exports.makeHostStateMachine = makeHostStateMachine;
|
|
19
|
+
class HostStateMachineImp extends HostStateMachine {
|
|
20
|
+
constructor(appObject) {
|
|
21
|
+
super(appObject, HostStateMachine.type);
|
|
22
|
+
this._states = [];
|
|
23
|
+
this.memoizedIsAuthoring = new Entities_1.MemoizedBoolean(false, this.notifyOnChange);
|
|
24
|
+
this._lastAssets = [];
|
|
25
|
+
this.hasState = (id) => {
|
|
26
|
+
const state = this.findStateByID(id);
|
|
27
|
+
if (state) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
this.setActiveStateByID = (id) => {
|
|
35
|
+
const state = this.findStateByID(id);
|
|
36
|
+
if (!state)
|
|
37
|
+
return;
|
|
38
|
+
if (state.id === this._activeState)
|
|
39
|
+
return;
|
|
40
|
+
this._activeState = state.id;
|
|
41
|
+
const index = this.getStateIndex(id);
|
|
42
|
+
if (index === undefined) {
|
|
43
|
+
this._nextState = undefined;
|
|
44
|
+
this._previousState = undefined;
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const prevIndex = index - 1;
|
|
48
|
+
const nextIndex = index + 1;
|
|
49
|
+
if (prevIndex >= 0) {
|
|
50
|
+
this._previousState = this._states[prevIndex].id;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
this._previousState = undefined;
|
|
54
|
+
}
|
|
55
|
+
if (nextIndex < this._states.length) {
|
|
56
|
+
this._nextState = this._states[nextIndex].id;
|
|
57
|
+
}
|
|
58
|
+
else {
|
|
59
|
+
this._nextState = undefined;
|
|
60
|
+
}
|
|
61
|
+
this.notifyOnChange();
|
|
62
|
+
};
|
|
63
|
+
this.clearActiveState = () => {
|
|
64
|
+
if (!this.activeState)
|
|
65
|
+
return;
|
|
66
|
+
this._nextState = undefined;
|
|
67
|
+
this._previousState = undefined;
|
|
68
|
+
this._activeState = undefined;
|
|
69
|
+
this.notifyOnChange();
|
|
70
|
+
};
|
|
71
|
+
this.setStates = (states) => {
|
|
72
|
+
this._states = states;
|
|
73
|
+
this.notifyOnChange();
|
|
74
|
+
};
|
|
75
|
+
this.stateFactory = (id) => {
|
|
76
|
+
const ao = this.appObjects.getOrCreate(id);
|
|
77
|
+
return HostStateEntity_1.makeHostStateEntity(ao);
|
|
78
|
+
};
|
|
79
|
+
this.createNewState = () => {
|
|
80
|
+
const newState = this.stateFactory(Utilities_1.generateUniqueID());
|
|
81
|
+
this._states.push(newState);
|
|
82
|
+
this.notifyOnChange();
|
|
83
|
+
return newState;
|
|
84
|
+
};
|
|
85
|
+
this.getStateByID = (id) => {
|
|
86
|
+
return this.findStateByID(id);
|
|
87
|
+
};
|
|
88
|
+
this.deleteState = (id) => {
|
|
89
|
+
const index = this.getStateIndex(id);
|
|
90
|
+
if (index === undefined) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
const state = this.getStateByID(id);
|
|
94
|
+
state === null || state === void 0 ? void 0 : state.appObject.dispose();
|
|
95
|
+
this._states.splice(index, 1);
|
|
96
|
+
this.notifyOnChange();
|
|
97
|
+
};
|
|
98
|
+
this.getStateIndex = (id) => {
|
|
99
|
+
let index = -1;
|
|
100
|
+
this._states.forEach((state, i) => {
|
|
101
|
+
if (state.id === id) {
|
|
102
|
+
index = i;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
if (index >= 0) {
|
|
106
|
+
return index;
|
|
107
|
+
}
|
|
108
|
+
else {
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
};
|
|
112
|
+
this.appObjects.registerSingleton(this);
|
|
113
|
+
}
|
|
114
|
+
get states() {
|
|
115
|
+
return this._states.map((state) => state.id);
|
|
116
|
+
}
|
|
117
|
+
get activeState() {
|
|
118
|
+
return this._activeState;
|
|
119
|
+
}
|
|
120
|
+
get previousState() {
|
|
121
|
+
return this._previousState;
|
|
122
|
+
}
|
|
123
|
+
get nextState() {
|
|
124
|
+
return this._nextState;
|
|
125
|
+
}
|
|
126
|
+
get isAuthoring() {
|
|
127
|
+
return this.memoizedIsAuthoring.val;
|
|
128
|
+
}
|
|
129
|
+
set isAuthoring(val) {
|
|
130
|
+
this.memoizedIsAuthoring.val = val;
|
|
131
|
+
}
|
|
132
|
+
get lastEditingState() {
|
|
133
|
+
return this._lastEditingState;
|
|
134
|
+
}
|
|
135
|
+
set lastEditingState(val) {
|
|
136
|
+
if (this._lastEditingState === undefined && val === undefined)
|
|
137
|
+
return;
|
|
138
|
+
const lastStateStr = this.lastEditingState === undefined
|
|
139
|
+
? ""
|
|
140
|
+
: JSON.stringify(this.lastEditingState);
|
|
141
|
+
const valStateStr = val === undefined ? "" : JSON.stringify(val);
|
|
142
|
+
if (lastStateStr === valStateStr)
|
|
143
|
+
return;
|
|
144
|
+
this._lastEditingState = val;
|
|
145
|
+
this.notifyOnChange();
|
|
146
|
+
}
|
|
147
|
+
get lastAssets() {
|
|
148
|
+
return this._lastAssets;
|
|
149
|
+
}
|
|
150
|
+
set lastAssets(lastAssets) {
|
|
151
|
+
this._lastAssets = lastAssets;
|
|
152
|
+
}
|
|
153
|
+
findStateByID(id) {
|
|
154
|
+
for (const state of this._states) {
|
|
155
|
+
if (state.id === id) {
|
|
156
|
+
return state;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return undefined;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
5
|
+
}) : (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
o[k2] = m[k];
|
|
8
|
+
}));
|
|
9
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
__exportStar(require("./HostEditingStateEntity"), exports);
|
|
14
|
+
__exportStar(require("./HostStateEntity"), exports);
|
|
15
|
+
__exportStar(require("./HostStateMachine"), exports);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
|
|
3
|
+
import { DeleteStateUC } from "../UCs";
|
|
4
|
+
export declare class MockDeleteStateUC extends DeleteStateUC {
|
|
5
|
+
deleteState: jest.Mock<any, any>;
|
|
6
|
+
constructor(appObject: HostAppObject);
|
|
7
|
+
}
|
|
8
|
+
export declare function makeMockDeleteStateUC(appObjects: HostAppObjectRepo): MockDeleteStateUC;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMockDeleteStateUC = exports.MockDeleteStateUC = void 0;
|
|
4
|
+
const UCs_1 = require("../UCs");
|
|
5
|
+
class MockDeleteStateUC extends UCs_1.DeleteStateUC {
|
|
6
|
+
constructor(appObject) {
|
|
7
|
+
super(appObject, UCs_1.DeleteStateUC.type);
|
|
8
|
+
this.deleteState = jest.fn();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MockDeleteStateUC = MockDeleteStateUC;
|
|
12
|
+
function makeMockDeleteStateUC(appObjects) {
|
|
13
|
+
return new MockDeleteStateUC(appObjects.getOrCreate("MockDeleteStateUC"));
|
|
14
|
+
}
|
|
15
|
+
exports.makeMockDeleteStateUC = makeMockDeleteStateUC;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
|
|
3
|
+
import { DuplicateStateUC } from "../UCs";
|
|
4
|
+
export declare class MockDuplicateStateUC extends DuplicateStateUC {
|
|
5
|
+
duplicateState: jest.Mock<any, any>;
|
|
6
|
+
constructor(appObject: HostAppObject);
|
|
7
|
+
}
|
|
8
|
+
export declare function makeMockDuplicateStateUC(appObjects: HostAppObjectRepo): MockDuplicateStateUC;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMockDuplicateStateUC = exports.MockDuplicateStateUC = void 0;
|
|
4
|
+
const UCs_1 = require("../UCs");
|
|
5
|
+
class MockDuplicateStateUC extends UCs_1.DuplicateStateUC {
|
|
6
|
+
constructor(appObject) {
|
|
7
|
+
super(appObject, UCs_1.DuplicateStateUC.type);
|
|
8
|
+
this.duplicateState = jest.fn();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MockDuplicateStateUC = MockDuplicateStateUC;
|
|
12
|
+
function makeMockDuplicateStateUC(appObjects) {
|
|
13
|
+
return new MockDuplicateStateUC(appObjects.getOrCreate("MockDuplicateStateUC"));
|
|
14
|
+
}
|
|
15
|
+
exports.makeMockDuplicateStateUC = makeMockDuplicateStateUC;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
|
|
3
|
+
import { HostEditingStateEntity, HostStateEntity } from "../Entities";
|
|
4
|
+
export declare class MockHostEditingStateEntity extends HostEditingStateEntity {
|
|
5
|
+
get isNewState(): boolean;
|
|
6
|
+
get isEditing(): boolean;
|
|
7
|
+
get editingState(): HostStateEntity | undefined;
|
|
8
|
+
get somethingHasChanged(): boolean;
|
|
9
|
+
stateValidationMessage?: string | undefined;
|
|
10
|
+
startNewState: jest.Mock<any, any>;
|
|
11
|
+
startEditing: jest.Mock<any, any>;
|
|
12
|
+
cancelEditState: jest.Mock<any, any>;
|
|
13
|
+
finishEditing: jest.Mock<any, any>;
|
|
14
|
+
constructor(appObject: HostAppObject);
|
|
15
|
+
}
|
|
16
|
+
export declare function makeMockHostEditingStateEntity(appObjects: HostAppObjectRepo): MockHostEditingStateEntity;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMockHostEditingStateEntity = exports.MockHostEditingStateEntity = void 0;
|
|
4
|
+
const Entities_1 = require("../Entities");
|
|
5
|
+
class MockHostEditingStateEntity extends Entities_1.HostEditingStateEntity {
|
|
6
|
+
constructor(appObject) {
|
|
7
|
+
super(appObject, Entities_1.HostEditingStateEntity.type);
|
|
8
|
+
this.startNewState = jest.fn();
|
|
9
|
+
this.startEditing = jest.fn();
|
|
10
|
+
this.cancelEditState = jest.fn();
|
|
11
|
+
this.finishEditing = jest.fn();
|
|
12
|
+
}
|
|
13
|
+
get isNewState() {
|
|
14
|
+
throw new Error("Method not implemented.");
|
|
15
|
+
}
|
|
16
|
+
get isEditing() {
|
|
17
|
+
throw new Error("Method not implemented.");
|
|
18
|
+
}
|
|
19
|
+
get editingState() {
|
|
20
|
+
throw new Error("Method not implemented.");
|
|
21
|
+
}
|
|
22
|
+
get somethingHasChanged() {
|
|
23
|
+
throw new Error("Method not implemented.");
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
exports.MockHostEditingStateEntity = MockHostEditingStateEntity;
|
|
27
|
+
function makeMockHostEditingStateEntity(appObjects) {
|
|
28
|
+
return new MockHostEditingStateEntity(appObjects.getOrCreate("MockHostEditingStateEntity"));
|
|
29
|
+
}
|
|
30
|
+
exports.makeMockHostEditingStateEntity = makeMockHostEditingStateEntity;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
|
|
3
|
+
import { HostStateMachinePM } from "../PMs";
|
|
4
|
+
export declare class MockHostStateMachinePM extends HostStateMachinePM {
|
|
5
|
+
vmsAreEqual: jest.Mock<any, any>;
|
|
6
|
+
constructor(appObject: HostAppObject);
|
|
7
|
+
}
|
|
8
|
+
export declare function makeMockHostStateMachinePM(appObjects: HostAppObjectRepo): MockHostStateMachinePM;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMockHostStateMachinePM = exports.MockHostStateMachinePM = void 0;
|
|
4
|
+
const PMs_1 = require("../PMs");
|
|
5
|
+
class MockHostStateMachinePM extends PMs_1.HostStateMachinePM {
|
|
6
|
+
constructor(appObject) {
|
|
7
|
+
super(appObject, PMs_1.HostStateMachinePM.type);
|
|
8
|
+
this.vmsAreEqual = jest.fn();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MockHostStateMachinePM = MockHostStateMachinePM;
|
|
12
|
+
function makeMockHostStateMachinePM(appObjects) {
|
|
13
|
+
return new MockHostStateMachinePM(appObjects.getOrCreate("MockHostStateMachinePM"));
|
|
14
|
+
}
|
|
15
|
+
exports.makeMockHostStateMachinePM = makeMockHostStateMachinePM;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
|
|
3
|
+
import { EditingStatePM } from "../PMs";
|
|
4
|
+
export declare class MockIsEditingStatePM extends EditingStatePM {
|
|
5
|
+
vmsAreEqual: jest.Mock<any, any>;
|
|
6
|
+
constructor(appObject: HostAppObject);
|
|
7
|
+
}
|
|
8
|
+
export declare function makeMockIsEditingStatePM(appObjects: HostAppObjectRepo): MockIsEditingStatePM;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.makeMockIsEditingStatePM = exports.MockIsEditingStatePM = void 0;
|
|
4
|
+
const PMs_1 = require("../PMs");
|
|
5
|
+
class MockIsEditingStatePM extends PMs_1.EditingStatePM {
|
|
6
|
+
constructor(appObject) {
|
|
7
|
+
super(appObject, PMs_1.EditingStatePM.type);
|
|
8
|
+
this.vmsAreEqual = jest.fn();
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
exports.MockIsEditingStatePM = MockIsEditingStatePM;
|
|
12
|
+
function makeMockIsEditingStatePM(appObjects) {
|
|
13
|
+
return new MockIsEditingStatePM(appObjects.getOrCreate("MockIsEditingStatePM"));
|
|
14
|
+
}
|
|
15
|
+
exports.makeMockIsEditingStatePM = makeMockIsEditingStatePM;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/// <reference types="jest" />
|
|
2
|
+
import { HostAppObject, HostAppObjectRepo } from "../../../HostAppObject";
|
|
3
|
+
import { ChallengeResponse, HostStateEntity } from "../Entities";
|
|
4
|
+
export declare class MockHostStateEntity extends HostStateEntity {
|
|
5
|
+
get id(): string;
|
|
6
|
+
name: string;
|
|
7
|
+
assets: never[];
|
|
8
|
+
expectedResponse: ChallengeResponse;
|
|
9
|
+
appID: string;
|
|
10
|
+
getDTO: jest.Mock<any, any>;
|
|
11
|
+
setDTO: jest.Mock<any, any>;
|
|
12
|
+
get stateData(): object;
|
|
13
|
+
setStateData: jest.Mock<any, any>;
|
|
14
|
+
constructor(appObject: HostAppObject);
|
|
15
|
+
}
|
|
16
|
+
export declare function makeMockHostStateEntity(id: string, appObjects: HostAppObjectRepo): MockHostStateEntity;
|