@asyra/system-context 0.2.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/.turbo/turbo-test$colon$ci.log +77 -0
- package/.turbo/turbo-test$colon$local.log +23 -0
- package/.turbo/turbo-test.log +359 -0
- package/README.md +1 -0
- package/coverage/base.css +224 -0
- package/coverage/block-navigation.js +87 -0
- package/coverage/clover.xml +345 -0
- package/coverage/coverage-final.json +5831 -0
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +176 -0
- package/coverage/prettify.css +1 -0
- package/coverage/prettify.js +2 -0
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +196 -0
- package/coverage/src/apis/index.html +206 -0
- package/coverage/src/apis/index.ts.html +133 -0
- package/coverage/src/apis/key-state.ts.html +124 -0
- package/coverage/src/apis/mouse-state.ts.html +124 -0
- package/coverage/src/apis/primary-tool-state.ts.html +124 -0
- package/coverage/src/apis/root.ts.html +139 -0
- package/coverage/src/apis/system-state.ts.html +112 -0
- package/coverage/src/apis/target-state.ts.html +121 -0
- package/coverage/src/index.html +131 -0
- package/coverage/src/index.ts.html +97 -0
- package/coverage/src/states/index.html +191 -0
- package/coverage/src/states/index.ts.html +139 -0
- package/coverage/src/states/key-state.ts.html +148 -0
- package/coverage/src/states/mouse-state.ts.html +184 -0
- package/coverage/src/states/primary-tool-state.ts.html +130 -0
- package/coverage/src/states/system-state.ts.html +130 -0
- package/coverage/src/states/target-state.ts.html +154 -0
- package/coverage/src/subscribe/index.html +191 -0
- package/coverage/src/subscribe/index.ts.html +187 -0
- package/coverage/src/subscribe/key-state.ts.html +109 -0
- package/coverage/src/subscribe/mouse-state.ts.html +109 -0
- package/coverage/src/subscribe/primary-tool-state.ts.html +136 -0
- package/coverage/src/subscribe/system-state.ts.html +94 -0
- package/coverage/src/subscribe/target-state.ts.html +109 -0
- package/coverage/src/system-context.ts.html +247 -0
- package/coverage/src/types/deps.ts.html +145 -0
- package/coverage/src/types/index.html +221 -0
- package/coverage/src/types/index.ts.html +157 -0
- package/coverage/src/types/key-state.ts.html +118 -0
- package/coverage/src/types/mouse-state.ts.html +118 -0
- package/coverage/src/types/primary-tool-state.ts.html +121 -0
- package/coverage/src/types/root.ts.html +106 -0
- package/coverage/src/types/system-state.ts.html +106 -0
- package/coverage/src/types/target-state.ts.html +118 -0
- package/dist/__tests__/system-context.test.d.ts +1 -0
- package/dist/__tests__/system-context.test.js +63 -0
- package/dist/apis/index.d.ts +13 -0
- package/dist/apis/index.js +14 -0
- package/dist/apis/key-state.d.ts +2 -0
- package/dist/apis/key-state.js +8 -0
- package/dist/apis/mouse-state copy.d.ts +2 -0
- package/dist/apis/mouse-state copy.js +8 -0
- package/dist/apis/mouse-state.d.ts +2 -0
- package/dist/apis/mouse-state.js +8 -0
- package/dist/apis/primary-tool-state.d.ts +2 -0
- package/dist/apis/primary-tool-state.js +8 -0
- package/dist/apis/root.d.ts +2 -0
- package/dist/apis/root.js +15 -0
- package/dist/apis/system-state.d.ts +2 -0
- package/dist/apis/system-state.js +5 -0
- package/dist/apis/target-state.d.ts +2 -0
- package/dist/apis/target-state.js +8 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/states/index.d.ts +6 -0
- package/dist/states/index.js +6 -0
- package/dist/states/key-state.d.ts +9 -0
- package/dist/states/key-state.js +16 -0
- package/dist/states/mouse-state copy.d.ts +9 -0
- package/dist/states/mouse-state copy.js +28 -0
- package/dist/states/mouse-state.d.ts +9 -0
- package/dist/states/mouse-state.js +28 -0
- package/dist/states/primary-tool-state.d.ts +8 -0
- package/dist/states/primary-tool-state.js +11 -0
- package/dist/states/system-state.d.ts +8 -0
- package/dist/states/system-state.js +11 -0
- package/dist/states/target-state.d.ts +9 -0
- package/dist/states/target-state.js +17 -0
- package/dist/subscribe/index.d.ts +2 -0
- package/dist/subscribe/index.js +24 -0
- package/dist/subscribe/key-state.d.ts +2 -0
- package/dist/subscribe/key-state.js +6 -0
- package/dist/subscribe/mouse-state copy.d.ts +2 -0
- package/dist/subscribe/mouse-state copy.js +6 -0
- package/dist/subscribe/mouse-state.d.ts +2 -0
- package/dist/subscribe/mouse-state.js +6 -0
- package/dist/subscribe/primary-tool-state.d.ts +2 -0
- package/dist/subscribe/primary-tool-state.js +10 -0
- package/dist/subscribe/root.d.ts +2 -0
- package/dist/subscribe/root.js +7 -0
- package/dist/subscribe/system-state.d.ts +1 -0
- package/dist/subscribe/system-state.js +3 -0
- package/dist/subscribe/target-state.d.ts +2 -0
- package/dist/subscribe/target-state.js +6 -0
- package/dist/system-context.d.ts +17 -0
- package/dist/system-context.js +30 -0
- package/dist/types/deps.d.ts +12 -0
- package/dist/types/deps.js +1 -0
- package/dist/types/index.d.ts +9 -0
- package/dist/types/index.js +1 -0
- package/dist/types/key-state.d.ts +8 -0
- package/dist/types/key-state.js +1 -0
- package/dist/types/mouse-state copy.d.ts +8 -0
- package/dist/types/mouse-state copy.js +1 -0
- package/dist/types/mouse-state.d.ts +8 -0
- package/dist/types/mouse-state.js +1 -0
- package/dist/types/primary-tool-state.d.ts +8 -0
- package/dist/types/primary-tool-state.js +1 -0
- package/dist/types/root.d.ts +5 -0
- package/dist/types/root.js +1 -0
- package/dist/types/system-state.d.ts +5 -0
- package/dist/types/system-state.js +1 -0
- package/dist/types/target-state.d.ts +8 -0
- package/dist/types/target-state.js +1 -0
- package/package.json +28 -0
- package/src/__tests__/system-context.test.ts +79 -0
- package/src/apis/index.ts +16 -0
- package/src/apis/key-state.ts +13 -0
- package/src/apis/mouse-state.ts +13 -0
- package/src/apis/primary-tool-state.ts +13 -0
- package/src/apis/root.ts +18 -0
- package/src/apis/system-state.ts +9 -0
- package/src/apis/target-state.ts +12 -0
- package/src/index.ts +4 -0
- package/src/states/index.ts +18 -0
- package/src/states/key-state.ts +21 -0
- package/src/states/mouse-state.ts +33 -0
- package/src/states/primary-tool-state.ts +15 -0
- package/src/states/system-state.ts +15 -0
- package/src/states/target-state.ts +23 -0
- package/src/subscribe/index.ts +34 -0
- package/src/subscribe/key-state.ts +8 -0
- package/src/subscribe/mouse-state.ts +8 -0
- package/src/subscribe/primary-tool-state.ts +17 -0
- package/src/subscribe/system-state.ts +3 -0
- package/src/subscribe/target-state.ts +8 -0
- package/src/system-context.ts +54 -0
- package/src/types/deps.ts +20 -0
- package/src/types/index.ts +24 -0
- package/src/types/key-state.ts +11 -0
- package/src/types/mouse-state.ts +11 -0
- package/src/types/primary-tool-state.ts +12 -0
- package/src/types/root.ts +7 -0
- package/src/types/system-state.ts +7 -0
- package/src/types/target-state.ts +11 -0
- package/tsconfig.json +17 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import systemState, { SystemState } from './system-state';
|
|
2
|
+
import primaryToolState, { PrimaryToolState } from './primary-tool-state';
|
|
3
|
+
import mouseState, { MouseState } from './mouse-state';
|
|
4
|
+
import keyState, { KeyState } from './key-state';
|
|
5
|
+
import targetState, { TargetState } from './target-state';
|
|
6
|
+
export { systemState, SystemState, primaryToolState, PrimaryToolState, mouseState, MouseState, keyState, KeyState, targetState, TargetState };
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import systemState, { SystemState } from './system-state';
|
|
2
|
+
import primaryToolState, { PrimaryToolState } from './primary-tool-state';
|
|
3
|
+
import mouseState, { MouseState } from './mouse-state';
|
|
4
|
+
import keyState, { KeyState } from './key-state';
|
|
5
|
+
import targetState, { TargetState } from './target-state';
|
|
6
|
+
export { systemState, SystemState, primaryToolState, PrimaryToolState, mouseState, MouseState, keyState, KeyState, targetState, TargetState };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { KeySnapshot } from '@asyra/utils';
|
|
2
|
+
export declare class KeyState {
|
|
3
|
+
private _state;
|
|
4
|
+
constructor();
|
|
5
|
+
set(keySnapshot: KeySnapshot): void;
|
|
6
|
+
get current(): import("@asyra/utils").ModifierKeys;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: KeyState;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { DefaultKeySnapshot } from '@asyra/utils';
|
|
2
|
+
export class KeyState {
|
|
3
|
+
_state;
|
|
4
|
+
constructor() {
|
|
5
|
+
this._state = {
|
|
6
|
+
...DefaultKeySnapshot
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
set(keySnapshot) {
|
|
10
|
+
this._state = { ...keySnapshot };
|
|
11
|
+
}
|
|
12
|
+
get current() {
|
|
13
|
+
return this._state;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
export default new KeyState();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DefaultPosition, MouseButton } from '@asyra/utils';
|
|
2
|
+
export class MouseState {
|
|
3
|
+
_state;
|
|
4
|
+
constructor() {
|
|
5
|
+
this._state = {
|
|
6
|
+
dragStart: DefaultPosition,
|
|
7
|
+
position: DefaultPosition,
|
|
8
|
+
delta: DefaultPosition,
|
|
9
|
+
button: MouseButton.NONE,
|
|
10
|
+
down: false,
|
|
11
|
+
dragging: false
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
set(mouseSnapshot) {
|
|
15
|
+
if (mouseSnapshot.dragStart) {
|
|
16
|
+
this._state.dragStart = { ...mouseSnapshot.dragStart };
|
|
17
|
+
}
|
|
18
|
+
this._state.position = { ...mouseSnapshot.position };
|
|
19
|
+
this._state.delta = { ...mouseSnapshot.delta };
|
|
20
|
+
this._state.button = mouseSnapshot.button;
|
|
21
|
+
this._state.down = mouseSnapshot.down;
|
|
22
|
+
this._state.dragging = mouseSnapshot.dragging;
|
|
23
|
+
}
|
|
24
|
+
get current() {
|
|
25
|
+
return this._state;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export default new MouseState();
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { DefaultPosition, MouseButton } from '@asyra/utils';
|
|
2
|
+
export class MouseState {
|
|
3
|
+
_state;
|
|
4
|
+
constructor() {
|
|
5
|
+
this._state = {
|
|
6
|
+
dragStart: DefaultPosition,
|
|
7
|
+
position: DefaultPosition,
|
|
8
|
+
delta: DefaultPosition,
|
|
9
|
+
button: MouseButton.NONE,
|
|
10
|
+
down: false,
|
|
11
|
+
dragging: false
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
set(mouseSnapshot) {
|
|
15
|
+
if (mouseSnapshot.dragStart) {
|
|
16
|
+
this._state.dragStart = { ...mouseSnapshot.dragStart };
|
|
17
|
+
}
|
|
18
|
+
this._state.position = { ...mouseSnapshot.position };
|
|
19
|
+
this._state.delta = { ...mouseSnapshot.delta };
|
|
20
|
+
this._state.button = mouseSnapshot.button;
|
|
21
|
+
this._state.down = mouseSnapshot.down;
|
|
22
|
+
this._state.dragging = mouseSnapshot.dragging;
|
|
23
|
+
}
|
|
24
|
+
get current() {
|
|
25
|
+
return this._state;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export default new MouseState();
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { TargetSnapshot } from '@asyra/utils';
|
|
2
|
+
export declare class TargetState {
|
|
3
|
+
private _state;
|
|
4
|
+
constructor();
|
|
5
|
+
updateHoveredElementId(elementId: string | null): void;
|
|
6
|
+
get current(): TargetSnapshot;
|
|
7
|
+
}
|
|
8
|
+
declare const _default: TargetState;
|
|
9
|
+
export default _default;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
export class TargetState {
|
|
2
|
+
_state;
|
|
3
|
+
constructor() {
|
|
4
|
+
this._state = {
|
|
5
|
+
hoveredElementId: null,
|
|
6
|
+
selectedElementIds: [],
|
|
7
|
+
activeElementId: null
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
updateHoveredElementId(elementId) {
|
|
11
|
+
this._state.hoveredElementId = elementId;
|
|
12
|
+
}
|
|
13
|
+
get current() {
|
|
14
|
+
return this._state;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export default new TargetState();
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { initPrimaryToolStateSubscribe } from './primary-tool-state';
|
|
2
|
+
import { initMouseStateSubscribe } from './mouse-state';
|
|
3
|
+
import { initSystemStateSubscribe } from './system-state';
|
|
4
|
+
import { initKeyStateSubscribe } from './key-state';
|
|
5
|
+
import { initTargetStateSubscribe } from './target-state';
|
|
6
|
+
export const initSystemContextSubscribe = (apis) => {
|
|
7
|
+
initSystemStateSubscribe();
|
|
8
|
+
initPrimaryToolStateSubscribe({
|
|
9
|
+
getCurrentPrimaryTool: () => apis.getCurrentPrimaryTool(),
|
|
10
|
+
switchPrimaryTool: (tool) => apis.switchPrimaryTool(tool)
|
|
11
|
+
});
|
|
12
|
+
initMouseStateSubscribe({
|
|
13
|
+
getMouseState: () => apis.getMouseState(),
|
|
14
|
+
updateMouseState: (mouseSnapshot) => apis.updateMouseState(mouseSnapshot)
|
|
15
|
+
});
|
|
16
|
+
initKeyStateSubscribe({
|
|
17
|
+
getKeyState: () => apis.getKeyState(),
|
|
18
|
+
updateKeyState: (keySnapshot) => apis.updateKeyState(keySnapshot)
|
|
19
|
+
});
|
|
20
|
+
initTargetStateSubscribe({
|
|
21
|
+
getTargetState: () => apis.getTargetState(),
|
|
22
|
+
updateHoveredElementId: (elementId) => apis.updateHoveredElementId(elementId)
|
|
23
|
+
});
|
|
24
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { finishRequestCurrentPrimaryTool, subscribeToRequestCurrentPrimaryTool, subscribeToSwitchPrimaryTool } from '@asyra/reactive-events';
|
|
2
|
+
export const initPrimaryToolStateSubscribe = (apis) => {
|
|
3
|
+
subscribeToSwitchPrimaryTool(({ payload }) => {
|
|
4
|
+
apis.switchPrimaryTool(payload.tool);
|
|
5
|
+
});
|
|
6
|
+
subscribeToRequestCurrentPrimaryTool(({ payload }) => {
|
|
7
|
+
const primaryTool = apis.getCurrentPrimaryTool();
|
|
8
|
+
finishRequestCurrentPrimaryTool(payload.requestId, primaryTool);
|
|
9
|
+
});
|
|
10
|
+
};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { finishRequestSystemContextSnapshot, subscribeToRequestSystemContextSnapshot } from '@asyra/reactive-events';
|
|
2
|
+
export const initRootSubscribe = (apis) => {
|
|
3
|
+
subscribeToRequestSystemContextSnapshot(({ payload }) => {
|
|
4
|
+
const systemContextSnapshot = apis.getSystemContextSnapshot();
|
|
5
|
+
finishRequestSystemContextSnapshot(payload.requestId, systemContextSnapshot);
|
|
6
|
+
});
|
|
7
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const initSystemStateSubscribe: () => void;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HandlerDeps, PrimaryToolStateAPIs, MouseStateAPIs, SystemStateAPIs, SystemContextAPIs, RootAPIs, KeyStateAPIs, TargetStateAPIs } from './types';
|
|
2
|
+
export declare class SystemContext implements SystemContextAPIs {
|
|
3
|
+
private deps;
|
|
4
|
+
getSystemMode: SystemStateAPIs['getSystemMode'];
|
|
5
|
+
getCurrentPrimaryTool: PrimaryToolStateAPIs['getCurrentPrimaryTool'];
|
|
6
|
+
switchPrimaryTool: PrimaryToolStateAPIs['switchPrimaryTool'];
|
|
7
|
+
getMouseState: MouseStateAPIs['getMouseState'];
|
|
8
|
+
updateMouseState: MouseStateAPIs['updateMouseState'];
|
|
9
|
+
getKeyState: KeyStateAPIs['getKeyState'];
|
|
10
|
+
updateKeyState: KeyStateAPIs['updateKeyState'];
|
|
11
|
+
getTargetState: TargetStateAPIs['getTargetState'];
|
|
12
|
+
updateHoveredElementId: TargetStateAPIs['updateHoveredElementId'];
|
|
13
|
+
getSystemContextSnapshot: RootAPIs['getSystemContextSnapshot'];
|
|
14
|
+
constructor(deps: HandlerDeps);
|
|
15
|
+
}
|
|
16
|
+
declare const systemContext: SystemContext;
|
|
17
|
+
export default systemContext;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { createAllAPIs } from './apis';
|
|
2
|
+
import { systemState, primaryToolState, mouseState, keyState, targetState } from './states';
|
|
3
|
+
import { initSystemContextSubscribe } from './subscribe';
|
|
4
|
+
export class SystemContext {
|
|
5
|
+
deps;
|
|
6
|
+
getSystemMode;
|
|
7
|
+
getCurrentPrimaryTool;
|
|
8
|
+
switchPrimaryTool;
|
|
9
|
+
getMouseState;
|
|
10
|
+
updateMouseState;
|
|
11
|
+
getKeyState;
|
|
12
|
+
updateKeyState;
|
|
13
|
+
getTargetState;
|
|
14
|
+
updateHoveredElementId;
|
|
15
|
+
getSystemContextSnapshot;
|
|
16
|
+
constructor(deps) {
|
|
17
|
+
this.deps = deps;
|
|
18
|
+
const apis = createAllAPIs(deps);
|
|
19
|
+
initSystemContextSubscribe(apis);
|
|
20
|
+
Object.assign(this, apis);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const systemContext = new SystemContext({
|
|
24
|
+
systemState,
|
|
25
|
+
primaryToolState,
|
|
26
|
+
mouseState,
|
|
27
|
+
keyState,
|
|
28
|
+
targetState
|
|
29
|
+
});
|
|
30
|
+
export default systemContext;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { SystemState, PrimaryToolState, MouseState, KeyState, TargetState } from '../states';
|
|
2
|
+
export interface HandlerDeps {
|
|
3
|
+
systemState: SystemState;
|
|
4
|
+
primaryToolState: PrimaryToolState;
|
|
5
|
+
mouseState: MouseState;
|
|
6
|
+
keyState: KeyState;
|
|
7
|
+
targetState: TargetState;
|
|
8
|
+
}
|
|
9
|
+
export interface SystemDeps {
|
|
10
|
+
primaryToolState: PrimaryToolState;
|
|
11
|
+
mouseState: MouseState;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { RootAPIs } from './root';
|
|
2
|
+
import { SystemStateAPIs } from './system-state';
|
|
3
|
+
import { PrimaryToolStateAPIs } from './primary-tool-state';
|
|
4
|
+
import { MouseStateAPIs } from './mouse-state';
|
|
5
|
+
import { KeyStateAPIs } from './key-state';
|
|
6
|
+
import { TargetStateAPIs } from './target-state';
|
|
7
|
+
export { RootAPIs, SystemStateAPIs, PrimaryToolStateAPIs, MouseStateAPIs, KeyStateAPIs, TargetStateAPIs };
|
|
8
|
+
export type SystemContextAPIs = RootAPIs & SystemStateAPIs & PrimaryToolStateAPIs & MouseStateAPIs & KeyStateAPIs & TargetStateAPIs;
|
|
9
|
+
export * from './deps';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './deps';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { KeySnapshot } from '@asyra/utils';
|
|
2
|
+
export interface KeyStateRawAPIs {
|
|
3
|
+
getKeyState: () => KeySnapshot;
|
|
4
|
+
}
|
|
5
|
+
export interface KeyStateActionAPIs {
|
|
6
|
+
updateKeyState: (keySnapshot: KeySnapshot) => void;
|
|
7
|
+
}
|
|
8
|
+
export type KeyStateAPIs = KeyStateActionAPIs & KeyStateRawAPIs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MouseSnapshot } from '@asyra/utils';
|
|
2
|
+
export interface MouseStateRawAPIs {
|
|
3
|
+
getMouseState: () => MouseSnapshot;
|
|
4
|
+
}
|
|
5
|
+
export interface MouseStateActionAPIs {
|
|
6
|
+
updateMouseState: (mouseSnapshot: MouseSnapshot) => void;
|
|
7
|
+
}
|
|
8
|
+
export type MouseStateAPIs = MouseStateActionAPIs & MouseStateRawAPIs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { MouseSnapshot } from '@asyra/utils';
|
|
2
|
+
export interface MouseStateRawAPIs {
|
|
3
|
+
getMouseState: () => MouseSnapshot;
|
|
4
|
+
}
|
|
5
|
+
export interface MouseStateActionAPIs {
|
|
6
|
+
updateMouseState: (mouseSnapshot: MouseSnapshot) => void;
|
|
7
|
+
}
|
|
8
|
+
export type MouseStateAPIs = MouseStateActionAPIs & MouseStateRawAPIs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { PrimaryToolType } from '@asyra/utils';
|
|
2
|
+
export interface PrimaryToolStateRawAPIs {
|
|
3
|
+
getCurrentPrimaryTool: () => PrimaryToolType;
|
|
4
|
+
}
|
|
5
|
+
export interface PrimaryToolStateActionAPIs {
|
|
6
|
+
switchPrimaryTool: (tool: PrimaryToolType) => void;
|
|
7
|
+
}
|
|
8
|
+
export type PrimaryToolStateAPIs = PrimaryToolStateRawAPIs & PrimaryToolStateActionAPIs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { TargetSnapshot } from '@asyra/utils';
|
|
2
|
+
export interface TargetStateRawAPIs {
|
|
3
|
+
getTargetState: () => TargetSnapshot;
|
|
4
|
+
}
|
|
5
|
+
export interface TargetStateActionAPIs {
|
|
6
|
+
updateHoveredElementId: (elementId: string | null) => void;
|
|
7
|
+
}
|
|
8
|
+
export type TargetStateAPIs = TargetStateActionAPIs & TargetStateRawAPIs;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@asyra/system-context",
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Provides reactive system parameters, tool states, and feature access control for the core application.",
|
|
5
|
+
"author": "Asa Tsai",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"packageManager": "yarn@4.3.1",
|
|
8
|
+
"main": "dist/index.js",
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "tsc --watch --preserveWatchOutput",
|
|
12
|
+
"build:system-context": "tsc",
|
|
13
|
+
"clean": "rm -rf dist",
|
|
14
|
+
"has:test": "find . -type f \\( -name \"*.test.ts\" -o -name \"*.test.tsx\" \\) | grep -q .",
|
|
15
|
+
"test": "yarn has:test && vitest || echo 'No test files found. Skipping test.'",
|
|
16
|
+
"test:local": "yarn has:test && vitest run || echo 'No test files found. Skipping test:local.'",
|
|
17
|
+
"test:ci": "yarn has:test && vitest run --coverage --reporter=default --reporter=junit || echo 'No test files found. Skipping test:ci.'"
|
|
18
|
+
},
|
|
19
|
+
"devDependencies": {
|
|
20
|
+
"@vitest/coverage-v8": "^2.1.8",
|
|
21
|
+
"typescript": "^5.7.2",
|
|
22
|
+
"vitest": "^2.1.8"
|
|
23
|
+
},
|
|
24
|
+
"dependencies": {
|
|
25
|
+
"@asyra/reactive-events": "workspace:*",
|
|
26
|
+
"@asyra/utils": "workspace:*"
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { describe, it, expect, beforeEach } from 'vitest'
|
|
2
|
+
import { SystemContext } from '../system-context'
|
|
3
|
+
import { KeyState } from '../states/key-state'
|
|
4
|
+
import { MouseState } from '../states/mouse-state'
|
|
5
|
+
import { PrimaryToolState } from '../states/primary-tool-state'
|
|
6
|
+
import { SystemState } from '../states/system-state'
|
|
7
|
+
import { TargetState } from '../states/target-state'
|
|
8
|
+
import {
|
|
9
|
+
DefaultKeySnapshot,
|
|
10
|
+
DefaultPosition,
|
|
11
|
+
MouseButton,
|
|
12
|
+
PrimaryToolType
|
|
13
|
+
} from '@asyra/utils'
|
|
14
|
+
|
|
15
|
+
describe('SystemContext', () => {
|
|
16
|
+
let systemContext: SystemContext
|
|
17
|
+
let keyState: KeyState
|
|
18
|
+
let mouseState: MouseState
|
|
19
|
+
let primaryToolState: PrimaryToolState
|
|
20
|
+
let systemState: SystemState
|
|
21
|
+
let targetState: TargetState
|
|
22
|
+
|
|
23
|
+
beforeEach(() => {
|
|
24
|
+
keyState = new KeyState()
|
|
25
|
+
mouseState = new MouseState()
|
|
26
|
+
primaryToolState = new PrimaryToolState()
|
|
27
|
+
systemState = new SystemState()
|
|
28
|
+
targetState = new TargetState()
|
|
29
|
+
|
|
30
|
+
systemContext = new SystemContext({
|
|
31
|
+
keyState,
|
|
32
|
+
mouseState,
|
|
33
|
+
primaryToolState,
|
|
34
|
+
systemState,
|
|
35
|
+
targetState
|
|
36
|
+
})
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it('should initialize with the correct default state', () => {
|
|
40
|
+
expect(systemContext.getKeyState()).toEqual(DefaultKeySnapshot)
|
|
41
|
+
expect(systemContext.getMouseState()).toEqual({
|
|
42
|
+
dragStart: DefaultPosition,
|
|
43
|
+
position: DefaultPosition,
|
|
44
|
+
delta: DefaultPosition,
|
|
45
|
+
button: MouseButton.NONE,
|
|
46
|
+
down: false,
|
|
47
|
+
dragging: false
|
|
48
|
+
})
|
|
49
|
+
expect(systemContext.getCurrentPrimaryTool()).toEqual(
|
|
50
|
+
PrimaryToolType.SELECT
|
|
51
|
+
)
|
|
52
|
+
})
|
|
53
|
+
|
|
54
|
+
it('should update mouse state correctly', () => {
|
|
55
|
+
const newMouseSnapshot = {
|
|
56
|
+
position: { x: 100, y: 200 },
|
|
57
|
+
delta: { x: 1, y: 1 },
|
|
58
|
+
button: MouseButton.LEFT,
|
|
59
|
+
down: true,
|
|
60
|
+
dragging: true,
|
|
61
|
+
dragStart: { x: 99, y: 199 }
|
|
62
|
+
}
|
|
63
|
+
systemContext.updateMouseState(newMouseSnapshot)
|
|
64
|
+
expect(systemContext.getMouseState()).toEqual(newMouseSnapshot)
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
it('should update tool state correctly', () => {
|
|
68
|
+
systemContext.switchPrimaryTool(PrimaryToolType.RECTANGLE)
|
|
69
|
+
expect(systemContext.getCurrentPrimaryTool()).toEqual(
|
|
70
|
+
PrimaryToolType.RECTANGLE
|
|
71
|
+
)
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
it('should update key state correctly', () => {
|
|
75
|
+
const newKeySnapshot = { ...DefaultKeySnapshot, shift: true }
|
|
76
|
+
systemContext.updateKeyState(newKeySnapshot)
|
|
77
|
+
expect(systemContext.getKeyState()).toEqual(newKeySnapshot)
|
|
78
|
+
})
|
|
79
|
+
})
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createRootAPIs } from './root'
|
|
2
|
+
import { createMouseStateAPIs } from './mouse-state'
|
|
3
|
+
import { createPrimaryToolStateAPIs } from './primary-tool-state'
|
|
4
|
+
import { createSystemAPIs } from './system-state'
|
|
5
|
+
import { createKeyStateAPIs } from './key-state'
|
|
6
|
+
import { createTargetStateAPIs } from './target-state'
|
|
7
|
+
import { HandlerDeps } from '../types'
|
|
8
|
+
|
|
9
|
+
export const createAllAPIs = (deps: HandlerDeps) => ({
|
|
10
|
+
...createRootAPIs(deps),
|
|
11
|
+
...createPrimaryToolStateAPIs(deps.primaryToolState),
|
|
12
|
+
...createMouseStateAPIs(deps.mouseState),
|
|
13
|
+
...createSystemAPIs(deps.systemState),
|
|
14
|
+
...createKeyStateAPIs(deps.keyState),
|
|
15
|
+
...createTargetStateAPIs(deps.targetState)
|
|
16
|
+
})
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { KeySnapshot } from '@asyra/utils'
|
|
2
|
+
import { HandlerDeps, KeyStateAPIs } from '../types'
|
|
3
|
+
|
|
4
|
+
export const createKeyStateAPIs = (
|
|
5
|
+
keyState: HandlerDeps['keyState']
|
|
6
|
+
): KeyStateAPIs => ({
|
|
7
|
+
updateKeyState(keySnapshot: KeySnapshot) {
|
|
8
|
+
keyState.set(keySnapshot)
|
|
9
|
+
},
|
|
10
|
+
getKeyState() {
|
|
11
|
+
return keyState.current
|
|
12
|
+
}
|
|
13
|
+
})
|