@asyra/ui-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.
Files changed (131) hide show
  1. package/.turbo/turbo-test$colon$ci.log +117 -0
  2. package/.turbo/turbo-test$colon$local.log +23 -0
  3. package/.turbo/turbo-test.log +0 -0
  4. package/README.md +1 -0
  5. package/coverage/base.css +224 -0
  6. package/coverage/block-navigation.js +87 -0
  7. package/coverage/clover.xml +538 -0
  8. package/coverage/coverage-final.json +7443 -0
  9. package/coverage/favicon.png +0 -0
  10. package/coverage/index.html +176 -0
  11. package/coverage/prettify.css +1 -0
  12. package/coverage/prettify.js +2 -0
  13. package/coverage/sort-arrow-sprite.png +0 -0
  14. package/coverage/sorter.js +196 -0
  15. package/coverage/src/index.html +146 -0
  16. package/coverage/src/index.ts.html +97 -0
  17. package/coverage/src/stores/index.html +146 -0
  18. package/coverage/src/stores/render.ts.html +106 -0
  19. package/coverage/src/stores/scene-tree.ts.html +790 -0
  20. package/coverage/src/stores/selection.ts.html +220 -0
  21. package/coverage/src/stores/system-context/index.html +146 -0
  22. package/coverage/src/stores/system-context/index.ts.html +88 -0
  23. package/coverage/src/stores/system-context/primary-tool.ts.html +109 -0
  24. package/coverage/src/stores/system-context/system-context.ts.html +85 -0
  25. package/coverage/src/subscribes/index.html +161 -0
  26. package/coverage/src/subscribes/index.ts.html +124 -0
  27. package/coverage/src/subscribes/render.ts.html +151 -0
  28. package/coverage/src/subscribes/scene-tree.ts.html +373 -0
  29. package/coverage/src/subscribes/selection.ts.html +253 -0
  30. package/coverage/src/subscribes/system-context/index.html +131 -0
  31. package/coverage/src/subscribes/system-context/index.ts.html +100 -0
  32. package/coverage/src/subscribes/system-context/primary-tool.ts.html +151 -0
  33. package/coverage/src/types.ts.html +124 -0
  34. package/coverage/src/ui-context.ts.html +568 -0
  35. package/dist/__tests__/ui-context.test.d.ts +2 -0
  36. package/dist/__tests__/ui-context.test.d.ts.map +1 -0
  37. package/dist/__tests__/ui-context.test.js +170 -0
  38. package/dist/__tests__/ui-context.test.js.map +1 -0
  39. package/dist/index.d.ts +4 -0
  40. package/dist/index.d.ts.map +1 -0
  41. package/dist/index.js +4 -0
  42. package/dist/index.js.map +1 -0
  43. package/dist/stores/__tests__/render.test.d.ts +2 -0
  44. package/dist/stores/__tests__/render.test.d.ts.map +1 -0
  45. package/dist/stores/__tests__/render.test.js +30 -0
  46. package/dist/stores/__tests__/render.test.js.map +1 -0
  47. package/dist/stores/__tests__/selection.test.d.ts +2 -0
  48. package/dist/stores/__tests__/selection.test.d.ts.map +1 -0
  49. package/dist/stores/__tests__/selection.test.js +128 -0
  50. package/dist/stores/__tests__/selection.test.js.map +1 -0
  51. package/dist/stores/render.d.ts +4 -0
  52. package/dist/stores/render.d.ts.map +1 -0
  53. package/dist/stores/render.js +7 -0
  54. package/dist/stores/render.js.map +1 -0
  55. package/dist/stores/scene-tree.d.ts +35 -0
  56. package/dist/stores/scene-tree.d.ts.map +1 -0
  57. package/dist/stores/scene-tree.js +158 -0
  58. package/dist/stores/scene-tree.js.map +1 -0
  59. package/dist/stores/selection.d.ts +8 -0
  60. package/dist/stores/selection.d.ts.map +1 -0
  61. package/dist/stores/selection.js +38 -0
  62. package/dist/stores/selection.js.map +1 -0
  63. package/dist/stores/system-context/__tests__/primary-tool.test.d.ts +2 -0
  64. package/dist/stores/system-context/__tests__/primary-tool.test.d.ts.map +1 -0
  65. package/dist/stores/system-context/__tests__/primary-tool.test.js +27 -0
  66. package/dist/stores/system-context/__tests__/primary-tool.test.js.map +1 -0
  67. package/dist/stores/system-context/index.d.ts +2 -0
  68. package/dist/stores/system-context/index.d.ts.map +1 -0
  69. package/dist/stores/system-context/index.js +2 -0
  70. package/dist/stores/system-context/index.js.map +1 -0
  71. package/dist/stores/system-context/primary-tool.d.ts +5 -0
  72. package/dist/stores/system-context/primary-tool.d.ts.map +1 -0
  73. package/dist/stores/system-context/primary-tool.js +7 -0
  74. package/dist/stores/system-context/primary-tool.js.map +1 -0
  75. package/dist/stores/system-context/system-context.d.ts +1 -0
  76. package/dist/stores/system-context/system-context.d.ts.map +1 -0
  77. package/dist/stores/system-context/system-context.js +2 -0
  78. package/dist/stores/system-context/system-context.js.map +1 -0
  79. package/dist/subscribes/index.d.ts +5 -0
  80. package/dist/subscribes/index.d.ts.map +1 -0
  81. package/dist/subscribes/index.js +12 -0
  82. package/dist/subscribes/index.js.map +1 -0
  83. package/dist/subscribes/render.d.ts +2 -0
  84. package/dist/subscribes/render.d.ts.map +1 -0
  85. package/dist/subscribes/render.js +15 -0
  86. package/dist/subscribes/render.js.map +1 -0
  87. package/dist/subscribes/scene-tree.d.ts +5 -0
  88. package/dist/subscribes/scene-tree.d.ts.map +1 -0
  89. package/dist/subscribes/scene-tree.js +71 -0
  90. package/dist/subscribes/scene-tree.js.map +1 -0
  91. package/dist/subscribes/selection.d.ts +5 -0
  92. package/dist/subscribes/selection.d.ts.map +1 -0
  93. package/dist/subscribes/selection.js +42 -0
  94. package/dist/subscribes/selection.js.map +1 -0
  95. package/dist/subscribes/system-context/index.d.ts +2 -0
  96. package/dist/subscribes/system-context/index.d.ts.map +1 -0
  97. package/dist/subscribes/system-context/index.js +5 -0
  98. package/dist/subscribes/system-context/index.js.map +1 -0
  99. package/dist/subscribes/system-context/primary-tool.d.ts +4 -0
  100. package/dist/subscribes/system-context/primary-tool.d.ts.map +1 -0
  101. package/dist/subscribes/system-context/primary-tool.js +15 -0
  102. package/dist/subscribes/system-context/primary-tool.js.map +1 -0
  103. package/dist/types.d.ts +11 -0
  104. package/dist/types.d.ts.map +1 -0
  105. package/dist/types.js +2 -0
  106. package/dist/types.js.map +1 -0
  107. package/dist/ui-context.d.ts +28 -0
  108. package/dist/ui-context.d.ts.map +1 -0
  109. package/dist/ui-context.js +101 -0
  110. package/dist/ui-context.js.map +1 -0
  111. package/package.json +36 -0
  112. package/src/__tests__/ui-context.test.ts +220 -0
  113. package/src/index.ts +4 -0
  114. package/src/stores/__tests__/render.test.ts +38 -0
  115. package/src/stores/__tests__/selection.test.ts +190 -0
  116. package/src/stores/render.ts +7 -0
  117. package/src/stores/scene-tree.ts +235 -0
  118. package/src/stores/selection.ts +45 -0
  119. package/src/stores/system-context/__tests__/primary-tool.test.ts +37 -0
  120. package/src/stores/system-context/index.ts +1 -0
  121. package/src/stores/system-context/primary-tool.ts +8 -0
  122. package/src/stores/system-context/system-context.ts +0 -0
  123. package/src/subscribes/index.ts +13 -0
  124. package/src/subscribes/render.ts +22 -0
  125. package/src/subscribes/scene-tree.ts +96 -0
  126. package/src/subscribes/selection.ts +56 -0
  127. package/src/subscribes/system-context/index.ts +5 -0
  128. package/src/subscribes/system-context/primary-tool.ts +22 -0
  129. package/src/types.ts +13 -0
  130. package/src/ui-context.ts +161 -0
  131. package/tsconfig.json +17 -0
@@ -0,0 +1,38 @@
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
@@ -0,0 +1 @@
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C;YACD,KAAK,eAAe,CAAC,MAAM;gBACzB,SAAS,CAAC,qBAAqB,CAAC,WAAW,CAAC,CAAA;gBAC5C,MAAK;QACT,CAAC;IACH,CAAC;CACF"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=primary-tool.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primary-tool.test.d.ts","sourceRoot":"","sources":["../../../../src/stores/system-context/__tests__/primary-tool.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,27 @@
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
@@ -0,0 +1 @@
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,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC7D,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,KAAK,eAAe,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAE9C,kBAAkB;AAClB,EAAE,CAAC,IAAI,CAAC,qBAAqB,EAAE,GAAG,EAAE,CAAC,CAAC;IACpC,OAAO,EAAE;QACP,iBAAiB,EAAE,EAAE,CAAC,EAAE,EAAE;KAC3B;CACF,CAAC,CAAC,CAAA;AAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,gBAAkC,CAAA;IAEtC,UAAU,CAAC,GAAG,EAAE;QACd,EAAE,CAAC,aAAa,EAAE,CAAA;QAClB,EAAE,CAAC,aAAa,EAAE,CAAA;QAClB,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;IAC3C,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,0CAA0C,EAAE,GAAG,EAAE;QAClD,gBAAgB,CAAC,iBAAiB,CAAC,eAAe,CAAC,SAAS,CAAC,CAAA;QAE7D,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,oBAAoB,CACpE,eAAe,CAAC,SAAS,CAC1B,CAAA;IACH,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,sCAAsC,EAAE,GAAG,EAAE;QAC9C,gBAAgB,CAAC,iBAAiB,CAAC,eAAe,CAAC,MAAM,CAAC,CAAA;QAE1D,MAAM,CAAC,eAAe,CAAC,OAAO,CAAC,iBAAiB,CAAC,CAAC,oBAAoB,CACpE,eAAe,CAAC,MAAM,CACvB,CAAA;IACH,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export { PrimaryToolStore } from './primary-tool';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export { PrimaryToolStore } from './primary-tool';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/stores/system-context/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { PrimaryToolType } from '@asyra/utils';
2
+ export declare class PrimaryToolStore {
3
+ updatePrimaryTool(tool: PrimaryToolType): void;
4
+ }
5
+ //# sourceMappingURL=primary-tool.d.ts.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,7 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1 @@
1
+ //# sourceMappingURL=system-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-context.d.ts","sourceRoot":"","sources":["../../../src/stores/system-context/system-context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ //# sourceMappingURL=system-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"system-context.js","sourceRoot":"","sources":["../../../src/stores/system-context/system-context.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,12 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export declare const initRenderDataSubscribe: () => void;
2
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/subscribes/render.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,uBAAuB,YAWnC,CAAA"}
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,5 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,71 @@
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
@@ -0,0 +1 @@
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;AACj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C,CAAA;IAEF,OAAO,GAAG,IAAI,CAAA;AAChB,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import SelectionStore from '../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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,42 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,2 @@
1
+ export declare const initSystemContextSubscribe: () => void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/subscribes/system-context/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,0BAA0B,YAEtC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { initPrimaryToolSubscribe } from './primary-tool';
2
+ export const initSystemContextSubscribe = () => {
3
+ initPrimaryToolSubscribe();
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,4 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,15 @@
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
@@ -0,0 +1 @@
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"}
@@ -0,0 +1,11 @@
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
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -0,0 +1,28 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ import { ComputedAttrs, PrimaryToolType } from '@asyra/utils';
3
+ import { ElementProperties } from './types';
4
+ declare class UIContext {
5
+ zoom: BehaviorSubject<number>;
6
+ flattenedElementIds: BehaviorSubject<string[]>;
7
+ elementSelection: BehaviorSubject<Set<string>>;
8
+ vertexSelection: BehaviorSubject<Set<string>>;
9
+ x: BehaviorSubject<ElementProperties['x']>;
10
+ y: BehaviorSubject<ElementProperties['y']>;
11
+ width: BehaviorSubject<ElementProperties['width']>;
12
+ height: BehaviorSubject<ElementProperties['height']>;
13
+ rotation: BehaviorSubject<ElementProperties['rotation']>;
14
+ primaryTool: BehaviorSubject<PrimaryToolType>;
15
+ constructor();
16
+ updateElementSelection(selectedIds: Set<string>): void;
17
+ updateVertexSelection(selectedIds: Set<string>): void;
18
+ updateComputedProperty<K extends keyof ComputedAttrs>(key: K, data: ComputedAttrs[K][]): void;
19
+ updateComputedProperties(allElementData: ComputedAttrs[]): void;
20
+ computedSharedProperty<K extends keyof ElementProperties>(data: ElementProperties[K][]): "MIX" | ElementProperties[K];
21
+ computeSharedProperties(allElementData: ComputedAttrs[]): ElementProperties;
22
+ updateZoom(newZoom: number): void;
23
+ updatePrimaryTool(tool: PrimaryToolType): void;
24
+ }
25
+ declare const uiContext: UIContext;
26
+ export default uiContext;
27
+ export { UIContext };
28
+ //# sourceMappingURL=ui-context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-context.d.ts","sourceRoot":"","sources":["../src/ui-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,EAAE,aAAa,EAAgB,eAAe,EAAE,MAAM,cAAc,CAAA;AAE3E,OAAO,EAAE,iBAAiB,EAAE,MAAM,SAAS,CAAA;AAU3C,cAAM,SAAS;IACb,IAAI,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IAC7B,mBAAmB,EAAE,eAAe,CAAC,MAAM,EAAE,CAAC,CAAA;IAC9C,gBAAgB,EAAE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IAC9C,eAAe,EAAE,eAAe,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,CAAA;IAC7C,CAAC,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1C,CAAC,EAAE,eAAe,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,CAAA;IAC1C,KAAK,EAAE,eAAe,CAAC,iBAAiB,CAAC,OAAO,CAAC,CAAC,CAAA;IAClD,MAAM,EAAE,eAAe,CAAC,iBAAiB,CAAC,QAAQ,CAAC,CAAC,CAAA;IACpD,QAAQ,EAAE,eAAe,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC,CAAA;IAIxD,WAAW,EAAE,eAAe,CAAC,eAAe,CAAC,CAAA;;IAmB7C,sBAAsB,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC;IAM/C,qBAAqB,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC;IAM9C,sBAAsB,CAAC,CAAC,SAAS,MAAM,aAAa,EAClD,GAAG,EAAE,CAAC,EACN,IAAI,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE;IAiB1B,wBAAwB,CAAC,cAAc,EAAE,aAAa,EAAE;IAUxD,sBAAsB,CAAC,CAAC,SAAS,MAAM,iBAAiB,EACtD,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC,EAAE;IAK9B,uBAAuB,CAAC,cAAc,EAAE,aAAa,EAAE,GAAG,iBAAiB;IAqB3E,UAAU,CAAC,OAAO,EAAE,MAAM;IAI1B,iBAAiB,CAAC,IAAI,EAAE,eAAe;CAKxC;AAED,QAAA,MAAM,SAAS,WAAkB,CAAA;AAEjC,eAAe,SAAS,CAAA;AACxB,OAAO,EAAE,SAAS,EAAE,CAAA"}
@@ -0,0 +1,101 @@
1
+ import { BehaviorSubject } from 'rxjs';
2
+ import { MIXED_STRING, PrimaryToolType } from '@asyra/utils';
3
+ import { isEqual } from 'lodash';
4
+ const generalKeysToCompare = [
5
+ 'x',
6
+ 'y',
7
+ 'width',
8
+ 'height',
9
+ 'rotation'
10
+ ];
11
+ class UIContext {
12
+ constructor() {
13
+ this.zoom = new BehaviorSubject(1);
14
+ this.flattenedElementIds = new BehaviorSubject([]);
15
+ this.elementSelection = new BehaviorSubject(new Set());
16
+ this.vertexSelection = new BehaviorSubject(new Set());
17
+ this.x = new BehaviorSubject(0);
18
+ this.y = new BehaviorSubject(0);
19
+ this.width = new BehaviorSubject(0);
20
+ this.height = new BehaviorSubject(0);
21
+ this.rotation = new BehaviorSubject(0);
22
+ // this.fills = new BehaviorSubject<ElementProperties['fills']>([])
23
+ this.primaryTool = new BehaviorSubject(PrimaryToolType.SELECT);
24
+ }
25
+ updateElementSelection(selectedIds) {
26
+ if (!isEqual(this.elementSelection.getValue(), selectedIds)) {
27
+ this.elementSelection.next(selectedIds);
28
+ }
29
+ }
30
+ updateVertexSelection(selectedIds) {
31
+ if (!isEqual(this.vertexSelection.getValue(), selectedIds)) {
32
+ this.vertexSelection.next(selectedIds);
33
+ }
34
+ }
35
+ updateComputedProperty(key, data) {
36
+ if (!data.length) {
37
+ return;
38
+ }
39
+ const compareKey = key;
40
+ if (generalKeysToCompare.includes(compareKey)) {
41
+ const result = this.computedSharedProperty(data);
42
+ if (result !== this[compareKey].getValue()) {
43
+ this[compareKey].next(result);
44
+ }
45
+ }
46
+ }
47
+ updateComputedProperties(allElementData) {
48
+ const result = this.computeSharedProperties(allElementData);
49
+ generalKeysToCompare.forEach((key) => {
50
+ if (result[key] !== this[key].getValue()) {
51
+ this[key].next(result[key]);
52
+ }
53
+ });
54
+ }
55
+ computedSharedProperty(data) {
56
+ return compareValue(data);
57
+ }
58
+ computeSharedProperties(allElementData) {
59
+ const result = {};
60
+ result.x = compareValues(allElementData, 'x');
61
+ result.y = compareValues(allElementData, 'y');
62
+ result.width = compareValues(allElementData, 'width');
63
+ result.height = compareValues(allElementData, 'height');
64
+ result.rotation = compareValues(allElementData, 'rotation');
65
+ return result;
66
+ }
67
+ updateZoom(newZoom) {
68
+ this.zoom.next(newZoom);
69
+ }
70
+ updatePrimaryTool(tool) {
71
+ if (tool !== this.primaryTool.getValue()) {
72
+ this.primaryTool.next(tool);
73
+ }
74
+ }
75
+ }
76
+ const uiContext = new UIContext();
77
+ export default uiContext;
78
+ export { UIContext };
79
+ const compareValue = (allElementData) => {
80
+ const firstValue = allElementData[0];
81
+ let isMixed = false;
82
+ for (let i = 1; i < allElementData.length; i++) {
83
+ if (allElementData[i] !== firstValue) {
84
+ isMixed = true;
85
+ break;
86
+ }
87
+ }
88
+ return isMixed ? MIXED_STRING : firstValue;
89
+ };
90
+ const compareValues = (allElementData, compareKey) => {
91
+ const firstValue = allElementData[0][compareKey];
92
+ let isMixed = false;
93
+ for (let i = 1; i < allElementData.length; i++) {
94
+ if (allElementData[i][compareKey] !== firstValue) {
95
+ isMixed = true;
96
+ break;
97
+ }
98
+ }
99
+ return isMixed ? MIXED_STRING : firstValue;
100
+ };
101
+ //# sourceMappingURL=ui-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ui-context.js","sourceRoot":"","sources":["../src/ui-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,MAAM,CAAA;AACtC,OAAO,EAAiB,YAAY,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC3E,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAGhC,MAAM,oBAAoB,GAAgC;IACxD,GAAG;IACH,GAAG;IACH,OAAO;IACP,QAAQ;IACR,UAAU;CACX,CAAA;AAED,MAAM,SAAS;IAeb;QACE,IAAI,CAAC,IAAI,GAAG,IAAI,eAAe,CAAS,CAAC,CAAC,CAAA;QAC1C,IAAI,CAAC,mBAAmB,GAAG,IAAI,eAAe,CAAW,EAAE,CAAC,CAAA;QAC5D,IAAI,CAAC,gBAAgB,GAAG,IAAI,eAAe,CAAc,IAAI,GAAG,EAAE,CAAC,CAAA;QACnE,IAAI,CAAC,eAAe,GAAG,IAAI,eAAe,CAAc,IAAI,GAAG,EAAE,CAAC,CAAA;QAClE,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+ "description": "Manages and optimizes data from data contexts for UI consumption, ensuring efficient rendering and framework flexibility.",
5
+ "author": "Asa Tsai",
6
+ "license": "MIT",
7
+ "packageManager": "yarn@4.3.1",
8
+ "keywords": [],
9
+ "main": "dist/index.js",
10
+ "types": "dist/index.d.ts",
11
+ "scripts": {
12
+ "dev": "tsc --watch --preserveWatchOutput",
13
+ "build:ui-context": "tsc",
14
+ "clean": "rm -rf dist",
15
+ "has:test": "find . -type f \\( -name \"*.test.ts\" -o -name \"*.test.tsx\" \\) | grep -q .",
16
+ "test": "yarn has:test && vitest || echo 'No test files found. Skipping test.'",
17
+ "test:local": "yarn has:test && vitest run || echo 'No test files found. Skipping test:local.'",
18
+ "test:ci": "yarn has:test && vitest run --coverage --reporter=default --reporter=junit || echo 'No test files found. Skipping test:ci.'"
19
+ },
20
+ "devDependencies": {
21
+ "@types/lodash": "^4",
22
+ "@vitest/coverage-v8": "^2.1.8",
23
+ "typescript": "^5.7.2",
24
+ "vitest": "^2.1.8"
25
+ },
26
+ "dependencies": {
27
+ "@asyra/factory": "workspace:*",
28
+ "@asyra/reactive-events": "workspace:*",
29
+ "@asyra/scene-tree": "workspace:*",
30
+ "@asyra/selection": "workspace:*",
31
+ "@asyra/utils": "workspace:*",
32
+ "lodash": "^4.17.21",
33
+ "rxjs": "^7.8.1",
34
+ "yjs": "13.6.20"
35
+ }
36
+ }