@asyra/system-context 0.2.4 → 0.5.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.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -1
  3. package/dist/apis/index.d.ts +11 -10
  4. package/dist/apis/index.js +3 -11
  5. package/dist/apis/managed-property-state.d.ts +39 -0
  6. package/dist/apis/managed-property-state.js +53 -0
  7. package/dist/apis/root.d.ts +1 -1
  8. package/dist/apis/root.js +18 -11
  9. package/dist/index.d.ts +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/states/index.d.ts +2 -6
  12. package/dist/states/index.js +2 -6
  13. package/dist/states/managed-property-state.d.ts +46 -0
  14. package/dist/states/managed-property-state.js +192 -0
  15. package/dist/system-context.d.ts +11 -11
  16. package/dist/system-context.js +13 -20
  17. package/dist/types/deps.d.ts +2 -10
  18. package/dist/types/index.d.ts +5 -9
  19. package/dist/types/index.js +1 -1
  20. package/dist/types/managed-property-state.d.ts +15 -0
  21. package/package.json +22 -4
  22. package/.turbo/turbo-test$colon$ci.log +0 -77
  23. package/.turbo/turbo-test$colon$local.log +0 -23
  24. package/.turbo/turbo-test.log +0 -359
  25. package/CHANGELOG.md +0 -37
  26. package/coverage/base.css +0 -224
  27. package/coverage/block-navigation.js +0 -87
  28. package/coverage/clover.xml +0 -345
  29. package/coverage/coverage-final.json +0 -5831
  30. package/coverage/favicon.png +0 -0
  31. package/coverage/index.html +0 -176
  32. package/coverage/prettify.css +0 -1
  33. package/coverage/prettify.js +0 -2
  34. package/coverage/sort-arrow-sprite.png +0 -0
  35. package/coverage/sorter.js +0 -196
  36. package/coverage/src/apis/index.html +0 -206
  37. package/coverage/src/apis/index.ts.html +0 -133
  38. package/coverage/src/apis/key-state.ts.html +0 -124
  39. package/coverage/src/apis/mouse-state.ts.html +0 -124
  40. package/coverage/src/apis/primary-tool-state.ts.html +0 -124
  41. package/coverage/src/apis/root.ts.html +0 -139
  42. package/coverage/src/apis/system-state.ts.html +0 -112
  43. package/coverage/src/apis/target-state.ts.html +0 -121
  44. package/coverage/src/index.html +0 -131
  45. package/coverage/src/index.ts.html +0 -97
  46. package/coverage/src/states/index.html +0 -191
  47. package/coverage/src/states/index.ts.html +0 -139
  48. package/coverage/src/states/key-state.ts.html +0 -148
  49. package/coverage/src/states/mouse-state.ts.html +0 -184
  50. package/coverage/src/states/primary-tool-state.ts.html +0 -130
  51. package/coverage/src/states/system-state.ts.html +0 -130
  52. package/coverage/src/states/target-state.ts.html +0 -154
  53. package/coverage/src/subscribe/index.html +0 -191
  54. package/coverage/src/subscribe/index.ts.html +0 -187
  55. package/coverage/src/subscribe/key-state.ts.html +0 -109
  56. package/coverage/src/subscribe/mouse-state.ts.html +0 -109
  57. package/coverage/src/subscribe/primary-tool-state.ts.html +0 -136
  58. package/coverage/src/subscribe/system-state.ts.html +0 -94
  59. package/coverage/src/subscribe/target-state.ts.html +0 -109
  60. package/coverage/src/system-context.ts.html +0 -247
  61. package/coverage/src/types/deps.ts.html +0 -145
  62. package/coverage/src/types/index.html +0 -221
  63. package/coverage/src/types/index.ts.html +0 -157
  64. package/coverage/src/types/key-state.ts.html +0 -118
  65. package/coverage/src/types/mouse-state.ts.html +0 -118
  66. package/coverage/src/types/primary-tool-state.ts.html +0 -121
  67. package/coverage/src/types/root.ts.html +0 -106
  68. package/coverage/src/types/system-state.ts.html +0 -106
  69. package/coverage/src/types/target-state.ts.html +0 -118
  70. package/dist/__tests__/system-context.test.js +0 -63
  71. package/dist/apis/key-state.d.ts +0 -2
  72. package/dist/apis/key-state.js +0 -8
  73. package/dist/apis/mouse-state copy.d.ts +0 -2
  74. package/dist/apis/mouse-state copy.js +0 -8
  75. package/dist/apis/mouse-state.d.ts +0 -2
  76. package/dist/apis/mouse-state.js +0 -8
  77. package/dist/apis/primary-tool-state.d.ts +0 -2
  78. package/dist/apis/primary-tool-state.js +0 -8
  79. package/dist/apis/system-state.d.ts +0 -2
  80. package/dist/apis/system-state.js +0 -5
  81. package/dist/apis/target-state.d.ts +0 -2
  82. package/dist/apis/target-state.js +0 -8
  83. package/dist/states/key-state.d.ts +0 -9
  84. package/dist/states/key-state.js +0 -16
  85. package/dist/states/mouse-state copy.d.ts +0 -9
  86. package/dist/states/mouse-state copy.js +0 -28
  87. package/dist/states/mouse-state.d.ts +0 -9
  88. package/dist/states/mouse-state.js +0 -28
  89. package/dist/states/primary-tool-state.d.ts +0 -8
  90. package/dist/states/primary-tool-state.js +0 -11
  91. package/dist/states/system-state.d.ts +0 -8
  92. package/dist/states/system-state.js +0 -11
  93. package/dist/states/target-state.d.ts +0 -9
  94. package/dist/states/target-state.js +0 -17
  95. package/dist/subscribe/index.d.ts +0 -2
  96. package/dist/subscribe/index.js +0 -24
  97. package/dist/subscribe/key-state.d.ts +0 -2
  98. package/dist/subscribe/key-state.js +0 -6
  99. package/dist/subscribe/mouse-state copy.d.ts +0 -2
  100. package/dist/subscribe/mouse-state copy.js +0 -6
  101. package/dist/subscribe/mouse-state.d.ts +0 -2
  102. package/dist/subscribe/mouse-state.js +0 -6
  103. package/dist/subscribe/primary-tool-state.d.ts +0 -2
  104. package/dist/subscribe/primary-tool-state.js +0 -10
  105. package/dist/subscribe/root.d.ts +0 -2
  106. package/dist/subscribe/root.js +0 -7
  107. package/dist/subscribe/system-state.d.ts +0 -1
  108. package/dist/subscribe/system-state.js +0 -3
  109. package/dist/subscribe/target-state.d.ts +0 -2
  110. package/dist/subscribe/target-state.js +0 -6
  111. package/dist/types/key-state.d.ts +0 -8
  112. package/dist/types/key-state.js +0 -1
  113. package/dist/types/mouse-state copy.d.ts +0 -8
  114. package/dist/types/mouse-state copy.js +0 -1
  115. package/dist/types/mouse-state.d.ts +0 -8
  116. package/dist/types/mouse-state.js +0 -1
  117. package/dist/types/primary-tool-state.d.ts +0 -8
  118. package/dist/types/primary-tool-state.js +0 -1
  119. package/dist/types/system-state.d.ts +0 -5
  120. package/dist/types/system-state.js +0 -1
  121. package/dist/types/target-state.d.ts +0 -8
  122. package/dist/types/target-state.js +0 -1
  123. package/src/__tests__/system-context.test.ts +0 -79
  124. package/src/apis/index.ts +0 -16
  125. package/src/apis/key-state.ts +0 -13
  126. package/src/apis/mouse-state.ts +0 -13
  127. package/src/apis/primary-tool-state.ts +0 -13
  128. package/src/apis/root.ts +0 -18
  129. package/src/apis/system-state.ts +0 -9
  130. package/src/apis/target-state.ts +0 -12
  131. package/src/index.ts +0 -4
  132. package/src/states/index.ts +0 -18
  133. package/src/states/key-state.ts +0 -21
  134. package/src/states/mouse-state.ts +0 -33
  135. package/src/states/primary-tool-state.ts +0 -15
  136. package/src/states/system-state.ts +0 -15
  137. package/src/states/target-state.ts +0 -23
  138. package/src/subscribe/index.ts +0 -34
  139. package/src/subscribe/key-state.ts +0 -8
  140. package/src/subscribe/mouse-state.ts +0 -8
  141. package/src/subscribe/primary-tool-state.ts +0 -17
  142. package/src/subscribe/system-state.ts +0 -3
  143. package/src/subscribe/target-state.ts +0 -8
  144. package/src/system-context.ts +0 -54
  145. package/src/types/deps.ts +0 -20
  146. package/src/types/index.ts +0 -24
  147. package/src/types/key-state.ts +0 -11
  148. package/src/types/mouse-state.ts +0 -11
  149. package/src/types/primary-tool-state.ts +0 -12
  150. package/src/types/root.ts +0 -7
  151. package/src/types/system-state.ts +0 -7
  152. package/src/types/target-state.ts +0 -11
  153. package/tsconfig.json +0 -17
  154. /package/dist/{__tests__/system-context.test.d.ts → types/managed-property-state.js} +0 -0
@@ -1,28 +0,0 @@
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();
@@ -1,9 +0,0 @@
1
- import { MouseSnapshot } from '@asyra/utils';
2
- export declare class MouseState {
3
- private _state;
4
- constructor();
5
- set(mouseSnapshot: MouseSnapshot): void;
6
- get current(): MouseSnapshot;
7
- }
8
- declare const _default: MouseState;
9
- export default _default;
@@ -1,28 +0,0 @@
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();
@@ -1,8 +0,0 @@
1
- import { PrimaryToolType } from '@asyra/utils';
2
- export declare class PrimaryToolState {
3
- private _state;
4
- set(tool: PrimaryToolType): void;
5
- get current(): PrimaryToolType;
6
- }
7
- declare const _default: PrimaryToolState;
8
- export default _default;
@@ -1,11 +0,0 @@
1
- import { DefaultPrimaryTool } from '@asyra/utils';
2
- export class PrimaryToolState {
3
- _state = DefaultPrimaryTool;
4
- set(tool) {
5
- this._state = tool;
6
- }
7
- get current() {
8
- return this._state;
9
- }
10
- }
11
- export default new PrimaryToolState();
@@ -1,8 +0,0 @@
1
- import { SystemMode } from '@asyra/utils';
2
- export declare class SystemState {
3
- private _mode;
4
- set(mode: SystemMode): void;
5
- get mode(): SystemMode;
6
- }
7
- declare const _default: SystemState;
8
- export default _default;
@@ -1,11 +0,0 @@
1
- import { DefaultSystemSnapshot } from '@asyra/utils';
2
- export class SystemState {
3
- _mode = DefaultSystemSnapshot.mode;
4
- set(mode) {
5
- this._mode = mode;
6
- }
7
- get mode() {
8
- return this._mode;
9
- }
10
- }
11
- export default new SystemState();
@@ -1,9 +0,0 @@
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;
@@ -1,17 +0,0 @@
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();
@@ -1,2 +0,0 @@
1
- import { SystemContextAPIs } from '../types';
2
- export declare const initSystemContextSubscribe: (apis: SystemContextAPIs) => void;
@@ -1,24 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { KeyStateAPIs } from '../types';
2
- export declare const initKeyStateSubscribe: (apis: KeyStateAPIs) => void;
@@ -1,6 +0,0 @@
1
- import { subscribeToUpdateKeyState } from '@asyra/reactive-events';
2
- export const initKeyStateSubscribe = (apis) => {
3
- subscribeToUpdateKeyState(({ payload }) => {
4
- apis.updateKeyState(payload);
5
- });
6
- };
@@ -1,2 +0,0 @@
1
- import { MouseStateAPIs } from '../types';
2
- export declare const initMouseStateSubscribe: (apis: MouseStateAPIs) => void;
@@ -1,6 +0,0 @@
1
- import { subscribeToUpdateMouseState } from '@asyra/reactive-events';
2
- export const initMouseStateSubscribe = (apis) => {
3
- subscribeToUpdateMouseState(({ payload }) => {
4
- apis.updateMouseState(payload);
5
- });
6
- };
@@ -1,2 +0,0 @@
1
- import { MouseStateAPIs } from '../types';
2
- export declare const initMouseStateSubscribe: (apis: MouseStateAPIs) => void;
@@ -1,6 +0,0 @@
1
- import { subscribeToUpdateMouseState } from '@asyra/reactive-events';
2
- export const initMouseStateSubscribe = (apis) => {
3
- subscribeToUpdateMouseState(({ payload }) => {
4
- apis.updateMouseState(payload);
5
- });
6
- };
@@ -1,2 +0,0 @@
1
- import { PrimaryToolStateAPIs } from '../types';
2
- export declare const initPrimaryToolStateSubscribe: (apis: PrimaryToolStateAPIs) => void;
@@ -1,10 +0,0 @@
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
- };
@@ -1,2 +0,0 @@
1
- import { RootAPIs } from '../types';
2
- export declare const initRootSubscribe: (apis: RootAPIs) => void;
@@ -1,7 +0,0 @@
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
- };
@@ -1 +0,0 @@
1
- export declare const initSystemStateSubscribe: () => void;
@@ -1,3 +0,0 @@
1
- export const initSystemStateSubscribe = () => {
2
- // TODO: add SystemMode and FeatureFlags
3
- };
@@ -1,2 +0,0 @@
1
- import { TargetStateAPIs } from '../types';
2
- export declare const initTargetStateSubscribe: (apis: TargetStateAPIs) => void;
@@ -1,6 +0,0 @@
1
- import { subscribeToUpdateHoveredElementId } from '@asyra/reactive-events';
2
- export const initTargetStateSubscribe = (apis) => {
3
- subscribeToUpdateHoveredElementId(({ payload }) => {
4
- apis.updateHoveredElementId(payload.elementId);
5
- });
6
- };
@@ -1,8 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import { SystemMode } from '@asyra/utils';
2
- export interface SystemStateRawAPIs {
3
- getSystemMode: () => SystemMode;
4
- }
5
- export type SystemStateAPIs = SystemStateRawAPIs;
@@ -1 +0,0 @@
1
- export {};
@@ -1,8 +0,0 @@
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;
@@ -1 +0,0 @@
1
- export {};
@@ -1,79 +0,0 @@
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
- })
package/src/apis/index.ts DELETED
@@ -1,16 +0,0 @@
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
- })
@@ -1,13 +0,0 @@
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
- })
@@ -1,13 +0,0 @@
1
- import { MouseSnapshot } from '@asyra/utils'
2
- import { HandlerDeps, MouseStateAPIs } from '../types'
3
-
4
- export const createMouseStateAPIs = (
5
- mouseState: HandlerDeps['mouseState']
6
- ): MouseStateAPIs => ({
7
- updateMouseState(mouseSnapshot: MouseSnapshot) {
8
- mouseState.set(mouseSnapshot)
9
- },
10
- getMouseState() {
11
- return mouseState.current
12
- }
13
- })
@@ -1,13 +0,0 @@
1
- import { PrimaryToolType } from '@asyra/utils'
2
- import { HandlerDeps, PrimaryToolStateAPIs } from '../types'
3
-
4
- export const createPrimaryToolStateAPIs = (
5
- primaryToolState: HandlerDeps['primaryToolState']
6
- ): PrimaryToolStateAPIs => ({
7
- getCurrentPrimaryTool(): PrimaryToolType {
8
- return primaryToolState.current
9
- },
10
- switchPrimaryTool(tool: PrimaryToolType) {
11
- primaryToolState.set(tool)
12
- }
13
- })
package/src/apis/root.ts DELETED
@@ -1,18 +0,0 @@
1
- import { SystemContextSnapshot } from '@asyra/utils'
2
- import { HandlerDeps, RootAPIs } from '../types'
3
-
4
- export const createRootAPIs = (deps: HandlerDeps): RootAPIs => ({
5
- getSystemContextSnapshot(): SystemContextSnapshot {
6
- return {
7
- primaryTool: deps.primaryToolState.current,
8
- mouse: deps.mouseState.current,
9
- system: {
10
- mode: deps.systemState.mode,
11
- featureFlags: {},
12
- permissions: {}
13
- },
14
- key: deps.keyState.current,
15
- target: deps.targetState.current
16
- }
17
- }
18
- })
@@ -1,9 +0,0 @@
1
- import { HandlerDeps, SystemStateAPIs } from '../types'
2
-
3
- export const createSystemAPIs = (
4
- systemState: HandlerDeps['systemState']
5
- ): SystemStateAPIs => ({
6
- getSystemMode() {
7
- return systemState.mode
8
- }
9
- })
@@ -1,12 +0,0 @@
1
- import { HandlerDeps, TargetStateAPIs } from '../types'
2
-
3
- export const createTargetStateAPIs = (
4
- targetState: HandlerDeps['targetState']
5
- ): TargetStateAPIs => ({
6
- updateHoveredElementId(elementId: string | null) {
7
- targetState.updateHoveredElementId(elementId)
8
- },
9
- getTargetState() {
10
- return targetState.current
11
- }
12
- })
package/src/index.ts DELETED
@@ -1,4 +0,0 @@
1
- import systemContext, { SystemContext } from './system-context'
2
-
3
- export { SystemContext }
4
- export default systemContext
@@ -1,18 +0,0 @@
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
-
7
- export {
8
- systemState,
9
- SystemState,
10
- primaryToolState,
11
- PrimaryToolState,
12
- mouseState,
13
- MouseState,
14
- keyState,
15
- KeyState,
16
- targetState,
17
- TargetState
18
- }
@@ -1,21 +0,0 @@
1
- import { DefaultKeySnapshot, KeySnapshot } from '@asyra/utils'
2
-
3
- export class KeyState {
4
- private _state: KeySnapshot
5
-
6
- constructor() {
7
- this._state = {
8
- ...DefaultKeySnapshot
9
- }
10
- }
11
-
12
- set(keySnapshot: KeySnapshot) {
13
- this._state = { ...keySnapshot }
14
- }
15
-
16
- get current() {
17
- return this._state
18
- }
19
- }
20
-
21
- export default new KeyState()
@@ -1,33 +0,0 @@
1
- import { DefaultPosition, MouseButton, MouseSnapshot } from '@asyra/utils'
2
-
3
- export class MouseState {
4
- private _state: MouseSnapshot
5
-
6
- constructor() {
7
- this._state = {
8
- dragStart: DefaultPosition,
9
- position: DefaultPosition,
10
- delta: DefaultPosition,
11
- button: MouseButton.NONE,
12
- down: false,
13
- dragging: false
14
- }
15
- }
16
-
17
- set(mouseSnapshot: MouseSnapshot) {
18
- if (mouseSnapshot.dragStart) {
19
- this._state.dragStart = { ...mouseSnapshot.dragStart }
20
- }
21
- this._state.position = { ...mouseSnapshot.position }
22
- this._state.delta = { ...mouseSnapshot.delta }
23
- this._state.button = mouseSnapshot.button
24
- this._state.down = mouseSnapshot.down
25
- this._state.dragging = mouseSnapshot.dragging
26
- }
27
-
28
- get current() {
29
- return this._state
30
- }
31
- }
32
-
33
- export default new MouseState()
@@ -1,15 +0,0 @@
1
- import { DefaultPrimaryTool, PrimaryToolType } from '@asyra/utils'
2
-
3
- export class PrimaryToolState {
4
- private _state: PrimaryToolType = DefaultPrimaryTool
5
-
6
- set(tool: PrimaryToolType) {
7
- this._state = tool
8
- }
9
-
10
- get current() {
11
- return this._state
12
- }
13
- }
14
-
15
- export default new PrimaryToolState()
@@ -1,15 +0,0 @@
1
- import { DefaultSystemSnapshot, SystemMode } from '@asyra/utils'
2
-
3
- export class SystemState {
4
- private _mode: SystemMode = DefaultSystemSnapshot.mode
5
-
6
- set(mode: SystemMode) {
7
- this._mode = mode
8
- }
9
-
10
- get mode() {
11
- return this._mode
12
- }
13
- }
14
-
15
- export default new SystemState()