@asyra/ui-context 0.2.5 → 0.5.1

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 (137) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -1
  3. package/dist/index.d.ts +5 -3
  4. package/dist/index.d.ts.map +1 -1
  5. package/dist/index.js +4 -3
  6. package/dist/index.js.map +1 -1
  7. package/dist/property-registry.d.ts +78 -0
  8. package/dist/property-registry.d.ts.map +1 -0
  9. package/dist/property-registry.js +119 -0
  10. package/dist/property-registry.js.map +1 -0
  11. package/dist/ui-context.d.ts +9 -21
  12. package/dist/ui-context.d.ts.map +1 -1
  13. package/dist/ui-context.js +58 -81
  14. package/dist/ui-context.js.map +1 -1
  15. package/package.json +24 -9
  16. package/.turbo/turbo-test$colon$ci.log +0 -117
  17. package/.turbo/turbo-test$colon$local.log +0 -23
  18. package/.turbo/turbo-test.log +0 -0
  19. package/CHANGELOG.md +0 -61
  20. package/coverage/base.css +0 -224
  21. package/coverage/block-navigation.js +0 -87
  22. package/coverage/clover.xml +0 -538
  23. package/coverage/coverage-final.json +0 -7443
  24. package/coverage/favicon.png +0 -0
  25. package/coverage/index.html +0 -176
  26. package/coverage/prettify.css +0 -1
  27. package/coverage/prettify.js +0 -2
  28. package/coverage/sort-arrow-sprite.png +0 -0
  29. package/coverage/sorter.js +0 -196
  30. package/coverage/src/index.html +0 -146
  31. package/coverage/src/index.ts.html +0 -97
  32. package/coverage/src/stores/index.html +0 -146
  33. package/coverage/src/stores/render.ts.html +0 -106
  34. package/coverage/src/stores/scene-tree.ts.html +0 -790
  35. package/coverage/src/stores/selection.ts.html +0 -220
  36. package/coverage/src/stores/system-context/index.html +0 -146
  37. package/coverage/src/stores/system-context/index.ts.html +0 -88
  38. package/coverage/src/stores/system-context/primary-tool.ts.html +0 -109
  39. package/coverage/src/stores/system-context/system-context.ts.html +0 -85
  40. package/coverage/src/subscribes/index.html +0 -161
  41. package/coverage/src/subscribes/index.ts.html +0 -124
  42. package/coverage/src/subscribes/render.ts.html +0 -151
  43. package/coverage/src/subscribes/scene-tree.ts.html +0 -373
  44. package/coverage/src/subscribes/selection.ts.html +0 -253
  45. package/coverage/src/subscribes/system-context/index.html +0 -131
  46. package/coverage/src/subscribes/system-context/index.ts.html +0 -100
  47. package/coverage/src/subscribes/system-context/primary-tool.ts.html +0 -151
  48. package/coverage/src/types.ts.html +0 -124
  49. package/coverage/src/ui-context.ts.html +0 -568
  50. package/dist/__tests__/ui-context.test.d.ts +0 -2
  51. package/dist/__tests__/ui-context.test.d.ts.map +0 -1
  52. package/dist/__tests__/ui-context.test.js +0 -170
  53. package/dist/__tests__/ui-context.test.js.map +0 -1
  54. package/dist/stores/__tests__/render.test.d.ts +0 -2
  55. package/dist/stores/__tests__/render.test.d.ts.map +0 -1
  56. package/dist/stores/__tests__/render.test.js +0 -30
  57. package/dist/stores/__tests__/render.test.js.map +0 -1
  58. package/dist/stores/__tests__/selection.test.d.ts +0 -2
  59. package/dist/stores/__tests__/selection.test.d.ts.map +0 -1
  60. package/dist/stores/__tests__/selection.test.js +0 -128
  61. package/dist/stores/__tests__/selection.test.js.map +0 -1
  62. package/dist/stores/render.d.ts +0 -4
  63. package/dist/stores/render.d.ts.map +0 -1
  64. package/dist/stores/render.js +0 -7
  65. package/dist/stores/render.js.map +0 -1
  66. package/dist/stores/scene-tree.d.ts +0 -35
  67. package/dist/stores/scene-tree.d.ts.map +0 -1
  68. package/dist/stores/scene-tree.js +0 -158
  69. package/dist/stores/scene-tree.js.map +0 -1
  70. package/dist/stores/selection.d.ts +0 -8
  71. package/dist/stores/selection.d.ts.map +0 -1
  72. package/dist/stores/selection.js +0 -38
  73. package/dist/stores/selection.js.map +0 -1
  74. package/dist/stores/system-context/__tests__/primary-tool.test.d.ts +0 -2
  75. package/dist/stores/system-context/__tests__/primary-tool.test.d.ts.map +0 -1
  76. package/dist/stores/system-context/__tests__/primary-tool.test.js +0 -27
  77. package/dist/stores/system-context/__tests__/primary-tool.test.js.map +0 -1
  78. package/dist/stores/system-context/index.d.ts +0 -2
  79. package/dist/stores/system-context/index.d.ts.map +0 -1
  80. package/dist/stores/system-context/index.js +0 -2
  81. package/dist/stores/system-context/index.js.map +0 -1
  82. package/dist/stores/system-context/primary-tool.d.ts +0 -5
  83. package/dist/stores/system-context/primary-tool.d.ts.map +0 -1
  84. package/dist/stores/system-context/primary-tool.js +0 -7
  85. package/dist/stores/system-context/primary-tool.js.map +0 -1
  86. package/dist/stores/system-context/system-context.d.ts +0 -1
  87. package/dist/stores/system-context/system-context.d.ts.map +0 -1
  88. package/dist/stores/system-context/system-context.js +0 -2
  89. package/dist/stores/system-context/system-context.js.map +0 -1
  90. package/dist/subscribes/index.d.ts +0 -5
  91. package/dist/subscribes/index.d.ts.map +0 -1
  92. package/dist/subscribes/index.js +0 -12
  93. package/dist/subscribes/index.js.map +0 -1
  94. package/dist/subscribes/render.d.ts +0 -2
  95. package/dist/subscribes/render.d.ts.map +0 -1
  96. package/dist/subscribes/render.js +0 -15
  97. package/dist/subscribes/render.js.map +0 -1
  98. package/dist/subscribes/scene-tree.d.ts +0 -5
  99. package/dist/subscribes/scene-tree.d.ts.map +0 -1
  100. package/dist/subscribes/scene-tree.js +0 -71
  101. package/dist/subscribes/scene-tree.js.map +0 -1
  102. package/dist/subscribes/selection.d.ts +0 -5
  103. package/dist/subscribes/selection.d.ts.map +0 -1
  104. package/dist/subscribes/selection.js +0 -42
  105. package/dist/subscribes/selection.js.map +0 -1
  106. package/dist/subscribes/system-context/index.d.ts +0 -2
  107. package/dist/subscribes/system-context/index.d.ts.map +0 -1
  108. package/dist/subscribes/system-context/index.js +0 -5
  109. package/dist/subscribes/system-context/index.js.map +0 -1
  110. package/dist/subscribes/system-context/primary-tool.d.ts +0 -4
  111. package/dist/subscribes/system-context/primary-tool.d.ts.map +0 -1
  112. package/dist/subscribes/system-context/primary-tool.js +0 -15
  113. package/dist/subscribes/system-context/primary-tool.js.map +0 -1
  114. package/dist/types.d.ts +0 -11
  115. package/dist/types.d.ts.map +0 -1
  116. package/dist/types.js +0 -2
  117. package/dist/types.js.map +0 -1
  118. package/src/__tests__/ui-context.test.ts +0 -220
  119. package/src/index.ts +0 -4
  120. package/src/stores/__tests__/render.test.ts +0 -38
  121. package/src/stores/__tests__/selection.test.ts +0 -190
  122. package/src/stores/render.ts +0 -7
  123. package/src/stores/scene-tree.ts +0 -235
  124. package/src/stores/selection.ts +0 -45
  125. package/src/stores/system-context/__tests__/primary-tool.test.ts +0 -37
  126. package/src/stores/system-context/index.ts +0 -1
  127. package/src/stores/system-context/primary-tool.ts +0 -8
  128. package/src/stores/system-context/system-context.ts +0 -0
  129. package/src/subscribes/index.ts +0 -13
  130. package/src/subscribes/render.ts +0 -22
  131. package/src/subscribes/scene-tree.ts +0 -96
  132. package/src/subscribes/selection.ts +0 -56
  133. package/src/subscribes/system-context/index.ts +0 -5
  134. package/src/subscribes/system-context/primary-tool.ts +0 -22
  135. package/src/types.ts +0 -13
  136. package/src/ui-context.ts +0 -161
  137. package/tsconfig.json +0 -17
@@ -1,38 +0,0 @@
1
- import selectionManager from '@asyra/selection';
2
- import { SELECTION_TYPES } from '@asyra/utils';
3
- import sceneTree from '@asyra/scene-tree';
4
- import uiContext from '../ui-context';
5
- export default class SelectionStore {
6
- constructor() {
7
- this.selectionManager = selectionManager;
8
- }
9
- updateSelection(type) {
10
- const selection = this.selectionManager.get(type);
11
- if (!selection) {
12
- return;
13
- }
14
- const selectedIds = selection.getSelectedIds();
15
- switch (type) {
16
- case SELECTION_TYPES.ELEMENT: {
17
- uiContext.updateElementSelection(selectedIds);
18
- const allElementData = [...selectedIds].reduce((acc, elementId) => {
19
- const element = sceneTree.getElementById(elementId);
20
- if (!element) {
21
- return acc;
22
- }
23
- const elementData = element.getAllComputedData();
24
- acc.push(elementData);
25
- return acc;
26
- }, []);
27
- if (selectedIds.size) {
28
- uiContext.updateComputedProperties(allElementData);
29
- }
30
- break;
31
- }
32
- case SELECTION_TYPES.VERTEX:
33
- uiContext.updateVertexSelection(selectedIds);
34
- break;
35
- }
36
- }
37
- }
38
- //# sourceMappingURL=selection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/stores/selection.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAsC,MAAM,kBAAkB,CAAA;AACrE,OAAO,EAAiB,eAAe,EAAE,MAAM,cAAc,CAAA;AAC7D,OAAO,SAAS,MAAM,mBAAmB,CAAA;AACzC,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,MAAM,CAAC,OAAO,OAAO,cAAc;IAGjC;QACE,IAAI,CAAC,gBAAgB,GAAG,gBAAgB,CAAA;IAC1C,CAAC;IAED,eAAe,CAAC,IAAqB;QACnC,MAAM,SAAS,GAAG,IAAI,CAAC,gBAAgB,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;QACjD,IAAI,CAAC,SAAS,EAAE,CAAC;YACf,OAAM;QACR,CAAC;QAED,MAAM,WAAW,GAAG,SAAS,CAAC,cAAc,EAAE,CAAA;QAE9C,QAAQ,IAAI,EAAE,CAAC;YACb,KAAK,eAAe,CAAC,OAAO,CAAC,CAAC,CAAC;gBAC7B,SAAS,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAA;gBAC7C,MAAM,cAAc,GAAG,CAAC,GAAG,WAAW,CAAC,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,SAAS,EAAE,EAAE;oBAChE,MAAM,OAAO,GAAG,SAAS,CAAC,cAAc,CAAC,SAAS,CAAC,CAAA;oBACnD,IAAI,CAAC,OAAO,EAAE,CAAC;wBACb,OAAO,GAAG,CAAA;oBACZ,CAAC;oBAED,MAAM,WAAW,GAAG,OAAO,CAAC,kBAAkB,EAAmB,CAAA;oBACjE,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;oBACrB,OAAO,GAAG,CAAA;gBACZ,CAAC,EAAE,EAAqB,CAAC,CAAA;gBAEzB,IAAI,WAAW,CAAC,IAAI,EAAE,CAAC;oBACrB,SAAS,CAAC,wBAAwB,CAAC,cAAc,CAAC,CAAA;gBACpD,CAAC;gBACD,MAAK;YACP,CAAC;YACD,KAAK,eAAe,CAAC,MAAM;gBACzB,SAAS,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAA;gBAC5C,MAAK;QACT,CAAC;IACH,CAAC;CACF"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=primary-tool.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primary-tool.test.d.ts","sourceRoot":"","sources":["../../../../src/stores/system-context/__tests__/primary-tool.test.ts"],"names":[],"mappings":""}
@@ -1,27 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest';
2
- import { PrimaryToolStore } from '../primary-tool';
3
- import * as UIContextModule from '../../../ui-context';
4
- import { PrimaryToolType } from '@asyra/utils';
5
- // Mock ui-context
6
- vi.mock('../../../ui-context', () => ({
7
- default: {
8
- updatePrimaryTool: vi.fn()
9
- }
10
- }));
11
- describe('PrimaryToolStore', () => {
12
- let primaryToolStore;
13
- beforeEach(() => {
14
- vi.clearAllMocks();
15
- vi.resetAllMocks();
16
- primaryToolStore = new PrimaryToolStore();
17
- });
18
- it('should update primary tool in ui context', () => {
19
- primaryToolStore.updatePrimaryTool(PrimaryToolType.RECTANGLE);
20
- expect(UIContextModule.default.updatePrimaryTool).toHaveBeenCalledWith(PrimaryToolType.RECTANGLE);
21
- });
22
- it('should update primary tool to SELECT', () => {
23
- primaryToolStore.updatePrimaryTool(PrimaryToolType.SELECT);
24
- expect(UIContextModule.default.updatePrimaryTool).toHaveBeenCalledWith(PrimaryToolType.SELECT);
25
- });
26
- });
27
- //# sourceMappingURL=primary-tool.test.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primary-tool.test.js","sourceRoot":"","sources":["../../../../src/stores/system-context/__tests__/primary-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA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+0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/stores/system-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,2 +0,0 @@
1
- export { PrimaryToolStore } from './primary-tool';
2
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stores/system-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
@@ -1,5 +0,0 @@
1
- import { PrimaryToolType } from '@asyra/utils';
2
- export declare class PrimaryToolStore {
3
- updatePrimaryTool(tool: PrimaryToolType): void;
4
- }
5
- //# sourceMappingURL=primary-tool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primary-tool.d.ts","sourceRoot":"","sources":["../../../src/stores/system-context/primary-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,qBAAa,gBAAgB;IAC3B,iBAAiB,CAAC,IAAI,EAAE,eAAe;CAGxC"}
@@ -1,7 +0,0 @@
1
- import uiContext from '../../ui-context';
2
- export class PrimaryToolStore {
3
- updatePrimaryTool(tool) {
4
- uiContext.updatePrimaryTool(tool);
5
- }
6
- }
7
- //# sourceMappingURL=primary-tool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primary-tool.js","sourceRoot":"","sources":["../../../src/stores/system-context/primary-tool.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,MAAM,kBAAkB,CAAA;AAExC,MAAM,OAAO,gBAAgB;IAC3B,iBAAiB,CAAC,IAAqB;QACrC,SAAS,CAAC,iBAAiB,CAAC,IAAI,CAAC,CAAA;IACnC,CAAC;CACF"}
@@ -1 +0,0 @@
1
- //# sourceMappingURL=system-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system-context.d.ts","sourceRoot":"","sources":["../../../src/stores/system-context/system-context.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=system-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"system-context.js","sourceRoot":"","sources":["../../../src/stores/system-context/system-context.ts"],"names":[],"mappings":""}
@@ -1,5 +0,0 @@
1
- import { sceneTreeStore } from './scene-tree';
2
- import { selectionStore } from './selection';
3
- export declare const initDataContexts: () => void;
4
- export { sceneTreeStore, selectionStore };
5
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/subscribes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAA8B,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,cAAc,EAA8B,MAAM,aAAa,CAAA;AAIxE,eAAO,MAAM,gBAAgB,YAK5B,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAA"}
@@ -1,12 +0,0 @@
1
- import { sceneTreeStore, initSceneTreeDataSubscribe } from './scene-tree';
2
- import { selectionStore, initSelectionDataSubscribe } from './selection';
3
- import { initRenderDataSubscribe } from './render';
4
- import { initSystemContextSubscribe } from './system-context';
5
- export const initDataContexts = () => {
6
- initRenderDataSubscribe();
7
- initSceneTreeDataSubscribe();
8
- initSelectionDataSubscribe();
9
- initSystemContextSubscribe();
10
- };
11
- export { sceneTreeStore, selectionStore };
12
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/subscribes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,cAAc,CAAA;AACzE,OAAO,EAAE,cAAc,EAAE,0BAA0B,EAAE,MAAM,aAAa,CAAA;AACxE,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAClD,OAAO,EAAE,0BAA0B,EAAE,MAAM,kBAAkB,CAAA;AAE7D,MAAM,CAAC,MAAM,gBAAgB,GAAG,GAAG,EAAE;IACnC,uBAAuB,EAAE,CAAA;IACzB,0BAA0B,EAAE,CAAA;IAC5B,0BAA0B,EAAE,CAAA;IAC5B,0BAA0B,EAAE,CAAA;AAC9B,CAAC,CAAA;AAED,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare const initRenderDataSubscribe: () => void;
2
- //# sourceMappingURL=render.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/subscribes/render.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,uBAAuB,YAWnC,CAAA"}
@@ -1,15 +0,0 @@
1
- import { requestRenderZoom, subscribeToEmitZoomFit } from '@asyra/reactive-events';
2
- import RenderStore from '../stores/render';
3
- const renderStore = new RenderStore();
4
- let hasInit = false;
5
- export const initRenderDataSubscribe = () => {
6
- if (hasInit) {
7
- return;
8
- }
9
- subscribeToEmitZoomFit(async () => {
10
- const zoom = await requestRenderZoom();
11
- renderStore.updateZoom(zoom);
12
- });
13
- hasInit = true;
14
- };
15
- //# sourceMappingURL=render.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render.js","sourceRoot":"","sources":["../../src/subscribes/render.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACvB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,WAAW,MAAM,kBAAkB,CAAA;AAE1C,MAAM,WAAW,GAAG,IAAI,WAAW,EAAE,CAAA;AAErC,IAAI,OAAO,GAAG,KAAK,CAAA;AAEnB,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAM;IACR,CAAC;IAED,sBAAsB,CAAC,KAAK,IAAI,EAAE;QAChC,MAAM,IAAI,GAAG,MAAM,iBAAiB,EAAE,CAAA;QACtC,WAAW,CAAC,UAAU,CAAC,IAAI,CAAC,CAAA;IAC9B,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,IAAI,CAAA;AAChB,CAAC,CAAA"}
@@ -1,5 +0,0 @@
1
- import SceneTreeStore from '../stores/scene-tree';
2
- export declare const sceneTreeStore: SceneTreeStore;
3
- export declare const collectSceneTreeChange: (event: any) => void;
4
- export declare const initSceneTreeDataSubscribe: () => void;
5
- //# sourceMappingURL=scene-tree.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scene-tree.d.ts","sourceRoot":"","sources":["../../src/subscribes/scene-tree.ts"],"names":[],"mappings":"AAcA,OAAO,cAAc,MAAM,sBAAsB,CAAA;AAGjD,eAAO,MAAM,cAAc,gBAAgC,CAAA;AAuB3D,eAAO,MAAM,sBAAsB,GAAI,UAAK,SAiC3C,CAAA;AAID,eAAO,MAAM,0BAA0B,YAkBtC,CAAA"}
@@ -1,71 +0,0 @@
1
- import { SCENE_TREE_ACTIONS } from '@asyra/utils';
2
- import factory from '@asyra/factory';
3
- import sceneTree from '@asyra/scene-tree';
4
- import { requestElementSelection, subscribeToEndTransaction, subscribeToSceneTreeLoadComplete } from '@asyra/reactive-events';
5
- import SceneTreeStore from '../stores/scene-tree';
6
- import uiContext from '../ui-context';
7
- export const sceneTreeStore = new SceneTreeStore(sceneTree);
8
- const updateUISceneTree = (change) => {
9
- switch (change.action) {
10
- case SCENE_TREE_ACTIONS.ADD_ELEMENT: {
11
- const { data } = change;
12
- sceneTreeStore.addElement(data);
13
- break;
14
- }
15
- case SCENE_TREE_ACTIONS.REMOVE_ELEMENT: {
16
- const { parentId, data } = change;
17
- sceneTreeStore.removeElement(data, parentId);
18
- break;
19
- }
20
- case SCENE_TREE_ACTIONS.UPDATE_ELEMENT_COMPUTED_DATA: {
21
- const { id, key, after } = change;
22
- sceneTreeStore.updateElement(id, key, after);
23
- break;
24
- }
25
- }
26
- };
27
- // @ts-expect-error: It's YJS event
28
- export const collectSceneTreeChange = (event) => {
29
- const updatedComputedDataKeys = new Set();
30
- const processChanges = (items) => {
31
- // @ts-expect-error: It's YJS event
32
- items.forEach((item) => {
33
- item.content
34
- .getContent()
35
- .forEach((change) => {
36
- if (change.action === SCENE_TREE_ACTIONS.UPDATE_ELEMENT_COMPUTED_DATA &&
37
- 'key' in change) {
38
- updatedComputedDataKeys.add(change.key);
39
- }
40
- updateUISceneTree(change);
41
- });
42
- });
43
- };
44
- processChanges(event.changes.added);
45
- processChanges(event.changes.deleted);
46
- updatedComputedDataKeys.forEach(async (key) => {
47
- const elementSelection = await requestElementSelection();
48
- const propertyData = [...elementSelection].map((elementId) => {
49
- const elementData = sceneTreeStore.getElementGeneralData(elementId);
50
- return elementData?.[key];
51
- });
52
- uiContext.updateComputedProperty(key, propertyData);
53
- });
54
- };
55
- let hasInit = false;
56
- export const initSceneTreeDataSubscribe = () => {
57
- if (hasInit) {
58
- return;
59
- }
60
- const sceneTreeArray = factory.sceneTreeMap;
61
- sceneTreeArray.observe(collectSceneTreeChange);
62
- subscribeToSceneTreeLoadComplete(() => {
63
- sceneTreeStore.reload();
64
- sceneTreeStore.fireChange();
65
- });
66
- subscribeToEndTransaction(() => {
67
- sceneTreeStore.fireChange();
68
- });
69
- hasInit = true;
70
- };
71
- //# sourceMappingURL=scene-tree.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scene-tree.js","sourceRoot":"","sources":["../../src/subscribes/scene-tree.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AACjD,OAAO,OAAO,MAAM,gBAAgB,CAAA;AACpC,OAAO,SAAS,MAAM,mBAAmB,CAAA;AACzC,OAAO,EACL,uBAAuB,EACvB,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,wBAAwB,CAAA;AAC/B,OAAO,cAAc,MAAM,sBAAsB,CAAA;AACjD,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,CAAC,SAAS,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../stores/selection';
2
- export declare const selectionStore: SelectionStore;
3
- export declare const collectElementSelectionChange: (event: any) => void;
4
- export declare const initSelectionDataSubscribe: () => void;
5
- //# sourceMappingURL=selection.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../src/subscribes/selection.ts"],"names":[],"mappings":"AAOA,OAAO,cAAc,MAAM,qBAAqB,CAAA;AAGhD,eAAO,MAAM,cAAc,gBAAuB,CAAA;AAgBlD,eAAO,MAAM,6BAA6B,GAAI,UAAK,SAYlD,CAAA;AAID,eAAO,MAAM,0BAA0B,YAatC,CAAA"}
@@ -1,42 +0,0 @@
1
- import { SELECTION_ACTIONS, SELECTION_TYPES } from '@asyra/utils';
2
- import factory from '@asyra/factory';
3
- import { finishRequestElementSelection, subscribeToRequestElementSelection } from '@asyra/reactive-events';
4
- import SelectionStore from '../stores/selection';
5
- import uiContext from '../ui-context';
6
- export const selectionStore = new SelectionStore();
7
- const updateUIElementSelection = (change) => {
8
- switch (change.action) {
9
- case SELECTION_ACTIONS.SELECT_ELEMENTS:
10
- case SELECTION_ACTIONS.DESELECT_ELEMENTS:
11
- selectionStore.updateSelection(SELECTION_TYPES.ELEMENT);
12
- break;
13
- case SELECTION_ACTIONS.SELECT_VERTICES:
14
- case SELECTION_ACTIONS.DESELECT_VERTICES:
15
- selectionStore.updateSelection(SELECTION_TYPES.VERTEX);
16
- break;
17
- }
18
- };
19
- // @ts-expect-error: It's YJS event
20
- export const collectElementSelectionChange = (event) => {
21
- const processChanges = (items) => {
22
- // @ts-expect-error: It's YJS event
23
- items.forEach((item) => {
24
- item.content.getContent().forEach(updateUIElementSelection);
25
- });
26
- };
27
- processChanges(event.changes.added);
28
- processChanges(event.changes.deleted);
29
- };
30
- let hasInit = false;
31
- export const initSelectionDataSubscribe = () => {
32
- if (hasInit) {
33
- return;
34
- }
35
- const elementSelectionArray = factory.elementSelectionMap;
36
- elementSelectionArray.observe(collectElementSelectionChange);
37
- subscribeToRequestElementSelection(() => {
38
- finishRequestElementSelection(uiContext.elementSelection.getValue());
39
- });
40
- hasInit = true;
41
- };
42
- //# sourceMappingURL=selection.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/subscribes/selection.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,iBAAiB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AACjE,OAAO,OAAO,MAAM,gBAAgB,CAAA;AACpC,OAAO,EACL,6BAA6B,EAC7B,kCAAkC,EACnC,MAAM,wBAAwB,CAAA;AAC/B,OAAO,cAAc,MAAM,qBAAqB,CAAA;AAChD,OAAO,SAAS,MAAM,eAAe,CAAA;AAErC,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAA;AAElD,MAAM,wBAAwB,GAAG,CAAC,MAAqC,EAAE,EAAE;IACzE,QAAQ,MAAM,CAAC,MAAM,EAAE,CAAC;QACtB,KAAK,iBAAiB,CAAC,eAAe,CAAC;QACvC,KAAK,iBAAiB,CAAC,iBAAiB;YACtC,cAAc,CAAC,eAAe,CAAC,eAAe,CAAC,OAAO,CAAC,CAAA;YACvD,MAAK;QACP,KAAK,iBAAiB,CAAC,eAAe,CAAC;QACvC,KAAK,iBAAiB,CAAC,iBAAiB;YACtC,cAAc,CAAC,eAAe,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;YACtD,MAAK;IACT,CAAC;AACH,CAAC,CAAA;AAED,mCAAmC;AACnC,MAAM,CAAC,MAAM,6BAA6B,GAAG,CAAC,KAAK,EAAE,EAAE;IACrD,MAAM,cAAc,GAAG,CACrB,KAAgE,EAChE,EAAE;QACF,mCAAmC;QACnC,KAAK,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;YACrB,IAAI,CAAC,OAAO,CAAC,UAAU,EAAE,CAAC,OAAO,CAAC,wBAAwB,CAAC,CAAA;QAC7D,CAAC,CAAC,CAAA;IACJ,CAAC,CAAA;IAED,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;IACnC,cAAc,CAAC,KAAK,CAAC,OAAO,CAAC,OAAO,CAAC,CAAA;AACvC,CAAC,CAAA;AAED,IAAI,OAAO,GAAG,KAAK,CAAA;AAEnB,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,EAAE;IAC7C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAM;IACR,CAAC;IAED,MAAM,qBAAqB,GAAG,OAAO,CAAC,mBAAmB,CAAA;IACzD,qBAAqB,CAAC,OAAO,CAAC,6BAA6B,CAAC,CAAA;IAE5D,kCAAkC,CAAC,GAAG,EAAE;QACtC,6BAA6B,CAAC,SAAS,CAAC,gBAAgB,CAAC,QAAQ,EAAE,CAAC,CAAA;IACtE,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,IAAI,CAAA;AAChB,CAAC,CAAA"}
@@ -1,2 +0,0 @@
1
- export declare const initSystemContextSubscribe: () => void;
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/subscribes/system-context/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,YAEtC,CAAA"}
@@ -1,5 +0,0 @@
1
- import { initPrimaryToolSubscribe } from './primary-tool';
2
- export const initSystemContextSubscribe = () => {
3
- initPrimaryToolSubscribe();
4
- };
5
- //# sourceMappingURL=index.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/subscribes/system-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,wBAAwB,EAAE,MAAM,gBAAgB,CAAA;AAEzD,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,EAAE;IAC7C,wBAAwB,EAAE,CAAA;AAC5B,CAAC,CAAA"}
@@ -1,4 +0,0 @@
1
- import { PrimaryToolStore } from '../../stores/system-context';
2
- export declare const primaryToolStore: PrimaryToolStore;
3
- export declare const initPrimaryToolSubscribe: () => void;
4
- //# sourceMappingURL=primary-tool.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primary-tool.d.ts","sourceRoot":"","sources":["../../../src/subscribes/system-context/primary-tool.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,eAAO,MAAM,gBAAgB,kBAAyB,CAAA;AAItD,eAAO,MAAM,wBAAwB,YAWpC,CAAA"}
@@ -1,15 +0,0 @@
1
- import { requestCurrentPrimaryTool, subscribeToEmitSwitchPrimaryTool } from '@asyra/reactive-events';
2
- import { PrimaryToolStore } from '../../stores/system-context';
3
- export const primaryToolStore = new PrimaryToolStore();
4
- let hasInit = false;
5
- export const initPrimaryToolSubscribe = () => {
6
- if (hasInit) {
7
- return;
8
- }
9
- subscribeToEmitSwitchPrimaryTool(async () => {
10
- const primaryTool = await requestCurrentPrimaryTool();
11
- primaryToolStore.updatePrimaryTool(primaryTool);
12
- });
13
- hasInit = true;
14
- };
15
- //# sourceMappingURL=primary-tool.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"primary-tool.js","sourceRoot":"","sources":["../../../src/subscribes/system-context/primary-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,gCAAgC,EACjC,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,6BAA6B,CAAA;AAE9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;AAEtD,IAAI,OAAO,GAAG,KAAK,CAAA;AAEnB,MAAM,CAAC,MAAM,wBAAwB,GAAG,GAAG,EAAE;IAC3C,IAAI,OAAO,EAAE,CAAC;QACZ,OAAM;IACR,CAAC;IAED,gCAAgC,CAAC,KAAK,IAAI,EAAE;QAC1C,MAAM,WAAW,GAAG,MAAM,yBAAyB,EAAE,CAAA;QACrD,gBAAgB,CAAC,iBAAiB,CAAC,WAAW,CAAC,CAAA;IACjD,CAAC,CAAC,CAAA;IAEF,OAAO,GAAG,IAAI,CAAA;AAChB,CAAC,CAAA"}
package/dist/types.d.ts DELETED
@@ -1,11 +0,0 @@
1
- import { MIXED_STRING } from '@asyra/utils';
2
- type MixedType = typeof MIXED_STRING;
3
- export interface ElementProperties {
4
- x: number | MixedType;
5
- y: number | MixedType;
6
- width: number | MixedType;
7
- height: number | MixedType;
8
- rotation: number | MixedType;
9
- }
10
- export {};
11
- //# sourceMappingURL=types.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAE3C,KAAK,SAAS,GAAG,OAAO,YAAY,CAAA;AAEpC,MAAM,WAAW,iBAAiB;IAChC,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrB,CAAC,EAAE,MAAM,GAAG,SAAS,CAAA;IACrB,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB,MAAM,EAAE,MAAM,GAAG,SAAS,CAAA;IAC1B,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;CAG7B"}
package/dist/types.js DELETED
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,220 +0,0 @@
1
- import { describe, it, expect, vi, beforeEach } from 'vitest'
2
- import { UIContext } from '../ui-context'
3
- import { BehaviorSubject } from 'rxjs'
4
- import {
5
- ComputedAttrs,
6
- MIXED_STRING,
7
- PrimaryToolType,
8
- EntityTypes
9
- } from '@asyra/utils'
10
-
11
- describe('UIContext', () => {
12
- let uiContext: UIContext
13
-
14
- beforeEach(() => {
15
- vi.clearAllMocks()
16
-
17
- uiContext = new UIContext()
18
- })
19
-
20
- // Test constructor
21
- it('should initialize all BehaviorSubjects with correct default values', () => {
22
- expect(uiContext.zoom).toBeInstanceOf(BehaviorSubject)
23
- expect(uiContext.zoom.getValue()).toBe(1)
24
- expect(uiContext.flattenedElementIds).toBeInstanceOf(BehaviorSubject)
25
- expect(uiContext.flattenedElementIds.getValue()).toEqual([])
26
- expect(uiContext.elementSelection).toBeInstanceOf(BehaviorSubject)
27
- expect(uiContext.elementSelection.getValue()).toEqual(new Set())
28
- expect(uiContext.vertexSelection).toBeInstanceOf(BehaviorSubject)
29
- expect(uiContext.vertexSelection.getValue()).toEqual(new Set())
30
- expect(uiContext.x).toBeInstanceOf(BehaviorSubject)
31
- expect(uiContext.x.getValue()).toBe(0)
32
- expect(uiContext.y).toBeInstanceOf(BehaviorSubject)
33
- expect(uiContext.y.getValue()).toBe(0)
34
- expect(uiContext.width).toBeInstanceOf(BehaviorSubject)
35
- expect(uiContext.width.getValue()).toBe(0)
36
- expect(uiContext.height).toBeInstanceOf(BehaviorSubject)
37
- expect(uiContext.height.getValue()).toBe(0)
38
- expect(uiContext.rotation).toBeInstanceOf(BehaviorSubject)
39
- expect(uiContext.rotation.getValue()).toBe(0)
40
- expect(uiContext.primaryTool).toBeInstanceOf(BehaviorSubject)
41
- expect(uiContext.primaryTool.getValue()).toBe(PrimaryToolType.SELECT)
42
- })
43
-
44
- // Test updateElementSelection
45
- it('should update elementSelection when selectedIds are different', () => {
46
- const newSelection = new Set(['id1', 'id2'])
47
- const nextSpy = vi.spyOn(uiContext.elementSelection, 'next')
48
-
49
- uiContext.updateElementSelection(newSelection)
50
-
51
- expect(nextSpy).toHaveBeenCalledWith(newSelection)
52
- })
53
-
54
- it('should not update elementSelection when selectedIds are the same', () => {
55
- const currentSelection = new Set(['id1'])
56
- uiContext.elementSelection.next(currentSelection)
57
- const nextSpy = vi.spyOn(uiContext.elementSelection, 'next')
58
-
59
- uiContext.updateElementSelection(currentSelection)
60
-
61
- expect(nextSpy).not.toHaveBeenCalled()
62
- })
63
-
64
- // Test updateVertexSelection
65
- it('should update vertexSelection when selectedIds are different', () => {
66
- const newSelection = new Set(['v1', 'v2'])
67
- const nextSpy = vi.spyOn(uiContext.vertexSelection, 'next')
68
-
69
- uiContext.updateVertexSelection(newSelection)
70
-
71
- expect(nextSpy).toHaveBeenCalledWith(newSelection)
72
- })
73
-
74
- it('should not update vertexSelection when selectedIds are the same', () => {
75
- const currentSelection = new Set(['v1'])
76
- uiContext.vertexSelection.next(currentSelection)
77
- const nextSpy = vi.spyOn(uiContext.vertexSelection, 'next')
78
-
79
- uiContext.updateVertexSelection(currentSelection)
80
-
81
- expect(nextSpy).not.toHaveBeenCalled()
82
- })
83
-
84
- // Test updateComputedProperty
85
- it('should update computed property with consistent value', () => {
86
- const nextSpy = vi.spyOn(uiContext.x, 'next')
87
-
88
- uiContext.updateComputedProperty('x', [10, 10])
89
-
90
- expect(nextSpy).toHaveBeenCalledWith(10)
91
- })
92
-
93
- it('should update computed property with MIXED_STRING for mixed values', () => {
94
- const nextSpy = vi.spyOn(uiContext.width, 'next')
95
-
96
- uiContext.updateComputedProperty('width', [100, 200])
97
-
98
- expect(nextSpy).toHaveBeenCalledWith(MIXED_STRING)
99
- })
100
-
101
- it('should not update computed property if value is the same', () => {
102
- uiContext.y.next(50)
103
- const nextSpy = vi.spyOn(uiContext.y, 'next')
104
-
105
- uiContext.updateComputedProperty('y', [50, 50])
106
-
107
- expect(nextSpy).not.toHaveBeenCalled()
108
- })
109
-
110
- it('should not update properties not in generalKeysToCompare', () => {
111
- const nextSpy = vi.spyOn(uiContext.flattenedElementIds, 'next')
112
-
113
- // Attempt to update a property not in generalKeysToCompare
114
- uiContext.updateComputedProperty(
115
- 'flattenedElementIds' as unknown as keyof ComputedAttrs,
116
- [
117
- ['id1'] as unknown as ComputedAttrs[keyof ComputedAttrs],
118
- ['id2'] as unknown as ComputedAttrs[keyof ComputedAttrs]
119
- ]
120
- )
121
-
122
- expect(nextSpy).not.toHaveBeenCalled()
123
- })
124
-
125
- // Test updateComputedProperties
126
- it('should update all general properties with consistent values', () => {
127
- const allElementData: ComputedAttrs[] = [
128
- {
129
- id: '1',
130
- type: EntityTypes.RECTANGLE,
131
- name: 'rect 1',
132
- x: 10,
133
- y: 20,
134
- width: 100,
135
- height: 50,
136
- rotation: 45
137
- },
138
- {
139
- id: '2',
140
- type: EntityTypes.RECTANGLE,
141
- name: 'rect 2',
142
- x: 10,
143
- y: 20,
144
- width: 100,
145
- height: 50,
146
- rotation: 45
147
- }
148
- ]
149
- const xSpy = vi.spyOn(uiContext.x, 'next')
150
- const ySpy = vi.spyOn(uiContext.y, 'next')
151
- const widthSpy = vi.spyOn(uiContext.width, 'next')
152
- const heightSpy = vi.spyOn(uiContext.height, 'next')
153
- const rotationSpy = vi.spyOn(uiContext.rotation, 'next')
154
-
155
- uiContext.updateComputedProperties(allElementData)
156
-
157
- expect(xSpy).toHaveBeenCalledWith(10)
158
- expect(ySpy).toHaveBeenCalledWith(20)
159
- expect(widthSpy).toHaveBeenCalledWith(100)
160
- expect(heightSpy).toHaveBeenCalledWith(50)
161
- expect(rotationSpy).toHaveBeenCalledWith(45)
162
- })
163
-
164
- it('should update all general properties with MIXED_STRING for mixed values', () => {
165
- const allElementData: ComputedAttrs[] = [
166
- {
167
- id: '1',
168
- type: EntityTypes.RECTANGLE,
169
- name: 'rect 1',
170
- x: 10,
171
- y: 20,
172
- width: 100,
173
- height: 50,
174
- rotation: 0
175
- },
176
- {
177
- id: '2',
178
- type: EntityTypes.RECTANGLE,
179
- name: 'rect 2',
180
- x: 15,
181
- y: 20,
182
- width: 100,
183
- height: 50,
184
- rotation: 0
185
- }
186
- ]
187
- const xSpy = vi.spyOn(uiContext.x, 'next')
188
-
189
- uiContext.updateComputedProperties(allElementData)
190
-
191
- expect(xSpy).toHaveBeenCalledWith(MIXED_STRING)
192
- })
193
-
194
- // Test updateZoom
195
- it('should update zoom value', () => {
196
- const nextSpy = vi.spyOn(uiContext.zoom, 'next')
197
-
198
- uiContext.updateZoom(2)
199
-
200
- expect(nextSpy).toHaveBeenCalledWith(2)
201
- })
202
-
203
- // Test updatePrimaryTool
204
- it('should update primaryTool when tool is different', () => {
205
- const nextSpy = vi.spyOn(uiContext.primaryTool, 'next')
206
-
207
- uiContext.updatePrimaryTool(PrimaryToolType.RECTANGLE)
208
-
209
- expect(nextSpy).toHaveBeenCalledWith(PrimaryToolType.RECTANGLE)
210
- })
211
-
212
- it('should not update primaryTool when tool is the same', () => {
213
- uiContext.primaryTool.next(PrimaryToolType.SELECT)
214
- const nextSpy = vi.spyOn(uiContext.primaryTool, 'next')
215
-
216
- uiContext.updatePrimaryTool(PrimaryToolType.SELECT)
217
-
218
- expect(nextSpy).not.toHaveBeenCalled()
219
- })
220
- })