@asyra/selection 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 (75) hide show
  1. package/.turbo/turbo-test$colon$ci.log +62 -0
  2. package/.turbo/turbo-test$colon$local.log +16 -0
  3. package/.turbo/turbo-test.log +592 -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 +128 -0
  8. package/coverage/coverage-final.json +2152 -0
  9. package/coverage/favicon.png +0 -0
  10. package/coverage/index.html +146 -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 +131 -0
  16. package/coverage/src/index.ts.html +127 -0
  17. package/coverage/src/selection-manager.ts.html +163 -0
  18. package/coverage/src/selections/base-selection.ts.html +259 -0
  19. package/coverage/src/selections/element-selection.ts.html +100 -0
  20. package/coverage/src/selections/index.html +146 -0
  21. package/coverage/src/selections/vertex-selection.ts.html +100 -0
  22. package/coverage/src/subscribes/element-selection.ts.html +133 -0
  23. package/coverage/src/subscribes/index.html +131 -0
  24. package/coverage/src/subscribes/index.ts.html +100 -0
  25. package/dist/__tests__/selection-manager.test.d.ts +2 -0
  26. package/dist/__tests__/selection-manager.test.d.ts.map +1 -0
  27. package/dist/__tests__/selection-manager.test.js +39 -0
  28. package/dist/__tests__/selection-manager.test.js.map +1 -0
  29. package/dist/__tests__/selection.test.d.ts +2 -0
  30. package/dist/__tests__/selection.test.d.ts.map +1 -0
  31. package/dist/__tests__/selection.test.js +44 -0
  32. package/dist/__tests__/selection.test.js.map +1 -0
  33. package/dist/__tests__/seletion.test.d.ts +2 -0
  34. package/dist/__tests__/seletion.test.d.ts.map +1 -0
  35. package/dist/__tests__/seletion.test.js +44 -0
  36. package/dist/__tests__/seletion.test.js.map +1 -0
  37. package/dist/index.d.ts +5 -0
  38. package/dist/index.d.ts.map +1 -0
  39. package/dist/index.js +12 -0
  40. package/dist/index.js.map +1 -0
  41. package/dist/selection-manager.d.ts +11 -0
  42. package/dist/selection-manager.d.ts.map +1 -0
  43. package/dist/selection-manager.js +20 -0
  44. package/dist/selection-manager.js.map +1 -0
  45. package/dist/selections/base-selection.d.ts +16 -0
  46. package/dist/selections/base-selection.d.ts.map +1 -0
  47. package/dist/selections/base-selection.js +51 -0
  48. package/dist/selections/base-selection.js.map +1 -0
  49. package/dist/selections/element-selection.d.ts +5 -0
  50. package/dist/selections/element-selection.d.ts.map +1 -0
  51. package/dist/selections/element-selection.js +5 -0
  52. package/dist/selections/element-selection.js.map +1 -0
  53. package/dist/selections/vertex-selection.d.ts +5 -0
  54. package/dist/selections/vertex-selection.d.ts.map +1 -0
  55. package/dist/selections/vertex-selection.js +5 -0
  56. package/dist/selections/vertex-selection.js.map +1 -0
  57. package/dist/subscribes/element-selection.d.ts +2 -0
  58. package/dist/subscribes/element-selection.d.ts.map +1 -0
  59. package/dist/subscribes/element-selection.js +12 -0
  60. package/dist/subscribes/element-selection.js.map +1 -0
  61. package/dist/subscribes/index.d.ts +2 -0
  62. package/dist/subscribes/index.d.ts.map +1 -0
  63. package/dist/subscribes/index.js +5 -0
  64. package/dist/subscribes/index.js.map +1 -0
  65. package/package.json +29 -0
  66. package/src/__tests__/selection-manager.test.ts +60 -0
  67. package/src/__tests__/selection.test.ts +59 -0
  68. package/src/index.ts +14 -0
  69. package/src/selection-manager.ts +26 -0
  70. package/src/selections/base-selection.ts +58 -0
  71. package/src/selections/element-selection.ts +5 -0
  72. package/src/selections/vertex-selection.ts +5 -0
  73. package/src/subscribes/element-selection.ts +16 -0
  74. package/src/subscribes/index.ts +5 -0
  75. package/tsconfig.json +17 -0
@@ -0,0 +1,39 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest';
2
+ import { SELECTION_TYPES } from '@asyra/utils';
3
+ import SelectionManager from '../selection-manager';
4
+ // Mock BaseSelection
5
+ const mockBaseSelection = {
6
+ clear: vi.fn(),
7
+ select: vi.fn(),
8
+ deselect: vi.fn(),
9
+ getSelectedIds: vi.fn(() => new Set()),
10
+ getPrevSelectedIds: vi.fn(() => new Set()),
11
+ addChange: vi.fn(),
12
+ cleanChanges: vi.fn()
13
+ };
14
+ describe('SelectionManager', () => {
15
+ let manager;
16
+ beforeEach(() => {
17
+ vi.clearAllMocks();
18
+ manager = new SelectionManager();
19
+ });
20
+ it('should register and retrieve selections correctly', () => {
21
+ manager.register(SELECTION_TYPES.ELEMENT, mockBaseSelection);
22
+ const selection = manager.get(SELECTION_TYPES.ELEMENT);
23
+ expect(selection).toBe(mockBaseSelection);
24
+ });
25
+ it('should return undefined for an unregistered selection type', () => {
26
+ const selection = manager.get(SELECTION_TYPES.VERTEX);
27
+ expect(selection).toBeUndefined();
28
+ });
29
+ it('should call clear() on all registered selections when clearAllSelections is called', () => {
30
+ const mockSelection1 = { ...mockBaseSelection, clear: vi.fn() };
31
+ const mockSelection2 = { ...mockBaseSelection, clear: vi.fn() };
32
+ manager.register(SELECTION_TYPES.ELEMENT, mockSelection1);
33
+ manager.register(SELECTION_TYPES.VERTEX, mockSelection2);
34
+ manager.clearAllSelections();
35
+ expect(mockSelection1.clear).toHaveBeenCalledTimes(1);
36
+ expect(mockSelection2.clear).toHaveBeenCalledTimes(1);
37
+ });
38
+ });
39
+ //# sourceMappingURL=selection-manager.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-manager.test.js","sourceRoot":"","sources":["../../src/__tests__/selection-manager.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,EAAE,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,gBAAgB,MAAM,sBAAsB,CAAA;AAGnD,qBAAqB;AACrB,MAAM,iBAAiB,GAAG;IACxB,KAA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D,MAAM,cAAc,GAAG,EAAE,GAAG,iBAAiB,EAAE,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE,EAAE,CAAA;QAC/D,OAAO,CAAC,QAAQ,CACd,eAAe,CAAC,OAAO,EACvB,cAA0C,CAC3C,CAAA;QACD,OAAO,CAAC,QAAQ,CACd,eAAe,CAAC,MAAM,EACtB,cAA0C,CAC3C,CAAA;QAED,OAAO,CAAC,kBAAkB,EAAE,CAAA;QAE5B,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;QACrD,MAAM,CAAC,cAAc,CAAC,KAAK,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAA;IACvD,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=selection.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/selection.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import Selection from '../selections/base-selection';
3
+ describe('Selection', () => {
4
+ let selection;
5
+ beforeEach(() => {
6
+ selection = new Selection();
7
+ });
8
+ it('should initialize with no selected ids', () => {
9
+ expect(selection.getSelectedIds()).toEqual(new Set([]));
10
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]));
11
+ });
12
+ it('should select ids correctly', () => {
13
+ selection.select(['id1', 'id2']);
14
+ expect(selection.getSelectedIds()).toEqual(new Set(['id1', 'id2']));
15
+ });
16
+ it('should deselect id correctly', () => {
17
+ selection.select(['id1', 'id2']);
18
+ selection.deselect(['id1']);
19
+ expect(selection.getSelectedIds()).toEqual(new Set(['id2']));
20
+ });
21
+ it('should clear selection correctly', () => {
22
+ selection.select(['id1', 'id2']);
23
+ selection.clear();
24
+ expect(selection.getSelectedIds()).toEqual(new Set([]));
25
+ });
26
+ it('should store previous selected ids when selecting', () => {
27
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]));
28
+ selection.select(['id1', 'id2']);
29
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]));
30
+ selection.select(['id3']);
31
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']));
32
+ });
33
+ it('should store previous selected ids when deselecting', () => {
34
+ selection.select(['id1', 'id2']);
35
+ selection.deselect(['id1']);
36
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']));
37
+ });
38
+ it('should store previous selected ids when clearing', () => {
39
+ selection.select(['id1', 'id2']);
40
+ selection.clear();
41
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']));
42
+ });
43
+ });
44
+ //# sourceMappingURL=selection.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.test.js","sourceRoot":"","sources":["../../src/__tests__/selection.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACzD,OAAO,SAAS,MAAM,8BAA8B,CAAA;AAEpD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,SAAoB,CAAA;IAExB,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IAC7B,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,wCAAwC,EAAE,GAAG,EAAE;QAChD,MAAM,CAAC,SAAS,CAAC,cAAc,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;QACvD,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,EAAE,CAAC,CAAC,CAAA;IAC7D,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,6BAA6B,EAAE,GAAG,EAAE;QACrC,SAAS,CAAC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,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,qDAAqD,EAAE,GAAG,EAAE;QAC7D,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QAChC,SAAS,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA;QAE3B,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;IAEF,EAAE,CAAC,kDAAkD,EAAE,GAAG,EAAE;QAC1D,SAAS,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAA;QAChC,SAAS,CAAC,KAAK,EAAE,CAAA;QAEjB,MAAM,CAAC,SAAS,CAAC,kBAAkB,EAAE,CAAC,CAAC,OAAO,CAAC,IAAI,GAAG,CAAC,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC,CAAC,CAAA;IACzE,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=seletion.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seletion.test.d.ts","sourceRoot":"","sources":["../../src/__tests__/seletion.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest';
2
+ import Selection from '../selections/base-selection';
3
+ describe('Selection', () => {
4
+ let selection;
5
+ beforeEach(() => {
6
+ selection = new Selection();
7
+ });
8
+ it('should initialize with no selected ids', () => {
9
+ expect(selection.getSelectedIds()).toEqual(new Set([]));
10
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]));
11
+ });
12
+ it('should select ids correctly', () => {
13
+ selection.select(['id1', 'id2']);
14
+ expect(selection.getSelectedIds()).toEqual(new Set(['id1', 'id2']));
15
+ });
16
+ it('should deselect id correctly', () => {
17
+ selection.select(['id1', 'id2']);
18
+ selection.deselect(['id1']);
19
+ expect(selection.getSelectedIds()).toEqual(new Set(['id2']));
20
+ });
21
+ it('should clear selection correctly', () => {
22
+ selection.select(['id1', 'id2']);
23
+ selection.clear();
24
+ expect(selection.getSelectedIds()).toEqual(new Set([]));
25
+ });
26
+ it('should store previous selected ids when selecting', () => {
27
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]));
28
+ selection.select(['id1', 'id2']);
29
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]));
30
+ selection.select(['id3']);
31
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']));
32
+ });
33
+ it('should store previous selected ids when deselecting', () => {
34
+ selection.select(['id1', 'id2']);
35
+ selection.deselect(['id1']);
36
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']));
37
+ });
38
+ it('should store previous selected ids when clearing', () => {
39
+ selection.select(['id1', 'id2']);
40
+ selection.clear();
41
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']));
42
+ });
43
+ });
44
+ //# sourceMappingURL=seletion.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"seletion.test.js","sourceRoot":"","sources":["../../src/__tests__/seletion.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,QAAQ,CAAA;AACzD,OAAO,SAAS,MAAM,8BAA8B,CAAA;AAEpD,QAAQ,CAAC,WAAW,EAAE,GAAG,EAAE;IACzB,IAAI,SAAoB,CAAA;IAExB,UAAU,CAAC,GAAG,EAAE;QACd,SAAS,GAAG,IAAI,SAAS,EAAE,CAAA;IAC7B,CAAC,CAAC,CAAA;IAE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selectionManager: SelectionManager;
3
+ export { SelectionManager };
4
+ export default selectionManager;
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,gBAAgB,MAAM,qBAAqB,CAAA;AAOlD,QAAA,MAAM,gBAAgB,kBAAyB,CAAA;AAI/C,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC3B,eAAe,gBAAgB,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { SELECTION_TYPES } from '@asyra/utils';
2
+ import SelectionManager from './selection-manager';
3
+ import { elementSelection } from './selections/element-selection';
4
+ import { vertexSelection } from './selections/vertex-selection';
5
+ import { initSelectionSubscribes } from './subscribes';
6
+ initSelectionSubscribes();
7
+ const selectionManager = new SelectionManager();
8
+ selectionManager.register(SELECTION_TYPES.ELEMENT, elementSelection);
9
+ selectionManager.register(SELECTION_TYPES.VERTEX, vertexSelection);
10
+ export { SelectionManager };
11
+ export default selectionManager;
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,gBAAgB,MAAM,qBAAqB,CAAA;AAClD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAA;AACjE,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAA;AAC/D,OAAO,EAAE,uBAAuB,EAAE,MAAM,cAAc,CAAA;AAEtD,uBAAuB,EAAE,CAAA;AAEzB,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA;AAC/C,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,OAAO,EAAE,gBAAgB,CAAC,CAAA;AACpE,gBAAgB,CAAC,QAAQ,CAAC,eAAe,CAAC,MAAM,EAAE,eAAe,CAAC,CAAA;AAElE,OAAO,EAAE,gBAAgB,EAAE,CAAA;AAC3B,eAAe,gBAAgB,CAAA"}
@@ -0,0 +1,11 @@
1
+ import { SELECTION_TYPES } from '@asyra/utils';
2
+ import Selection from './selections/base-selection';
3
+ declare class SelectionManager {
4
+ private selections;
5
+ register(type: SELECTION_TYPES, selection: Selection): void;
6
+ get(type: SELECTION_TYPES): Selection | undefined;
7
+ clearAllSelections(): void;
8
+ getElementSelectionIds(): string[];
9
+ }
10
+ export default SelectionManager;
11
+ //# sourceMappingURL=selection-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-manager.d.ts","sourceRoot":"","sources":["../src/selection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,OAAO,SAAS,MAAM,6BAA6B,CAAA;AAEnD,cAAM,gBAAgB;IACpB,OAAO,CAAC,UAAU,CAAoC;IAEtD,QAAQ,CAAC,IAAI,EAAE,eAAe,EAAE,SAAS,EAAE,SAAS,GAAG,IAAI;IAI3D,GAAG,CAAC,IAAI,EAAE,eAAe,GAAG,SAAS,GAAG,SAAS;IAIjD,kBAAkB,IAAI,IAAI;IAI1B,sBAAsB,IAAI,MAAM,EAAE;CAKnC;AAED,eAAe,gBAAgB,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { SELECTION_TYPES } from '@asyra/utils';
2
+ class SelectionManager {
3
+ constructor() {
4
+ this.selections = new Map();
5
+ }
6
+ register(type, selection) {
7
+ this.selections.set(type, selection);
8
+ }
9
+ get(type) {
10
+ return this.selections.get(type);
11
+ }
12
+ clearAllSelections() {
13
+ this.selections.forEach((selection) => selection.clear());
14
+ }
15
+ getElementSelectionIds() {
16
+ return Array.from(this.selections.get(SELECTION_TYPES.ELEMENT)?.getSelectedIds() || []);
17
+ }
18
+ }
19
+ export default SelectionManager;
20
+ //# sourceMappingURL=selection-manager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection-manager.js","sourceRoot":"","sources":["../src/selection-manager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAG9C,MAAM,gBAAgB;IAAtB;QACU,eAAU,GAA2B,IAAI,GAAG,EAAE,CAAA;IAmBxD,CAAC;IAjBC,QAAQ,CAAC,IAAqB,EAAE,SAAoB;QAClD,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,SAAS,CAAC,CAAA;IACtC,CAAC;IAED,GAAG,CAAC,IAAqB;QACvB,OAAO,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAA;IAClC,CAAC;IAED,kBAAkB;QAChB,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC,SAAS,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC,CAAA;IAC3D,CAAC;IAED,sBAAsB;QACpB,OAAO,KAAK,CAAC,IAAI,CACf,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,eAAe,CAAC,OAAO,CAAC,EAAE,cAAc,EAAE,IAAI,EAAE,CACrE,CAAA;IACH,CAAC;CACF;AAED,eAAe,gBAAgB,CAAA"}
@@ -0,0 +1,16 @@
1
+ import { SELECTION_ACTIONS } from '@asyra/utils';
2
+ import type { SelectionChange } from '@asyra/utils';
3
+ export default class BaseSelection {
4
+ protected selectedIds: Set<string>;
5
+ protected prevSelectedIds: Set<string>;
6
+ changes: SelectionChange[];
7
+ private _updatePrevSelectedIds;
8
+ select(ids: string[]): void;
9
+ deselect(ids: string[]): void;
10
+ clear(): void;
11
+ getSelectedIds(): Set<string>;
12
+ getPrevSelectedIds(): Set<string>;
13
+ addChange(action: SELECTION_ACTIONS, before: string[], after: string[]): void;
14
+ cleanChanges(): void;
15
+ }
16
+ //# sourceMappingURL=base-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-selection.d.ts","sourceRoot":"","sources":["../../src/selections/base-selection.ts"],"names":[],"mappings":"AACA,OAAO,EAAS,iBAAiB,EAAE,MAAM,cAAc,CAAA;AACvD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAEnD,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,SAAS,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAC9C,SAAS,CAAC,eAAe,EAAE,GAAG,CAAC,MAAM,CAAC,CAAY;IAClD,OAAO,EAAE,eAAe,EAAE,CAAK;IAE/B,OAAO,CAAC,sBAAsB;IAI9B,MAAM,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI;IAO3B,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,IAAI;IAS7B,KAAK,IAAI,IAAI;IAOb,cAAc,IAAI,GAAG,CAAC,MAAM,CAAC;IAI7B,kBAAkB,IAAI,GAAG,CAAC,MAAM,CAAC;IAIjC,SAAS,CAAC,MAAM,EAAE,iBAAiB,EAAE,MAAM,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE;IAUtE,YAAY;CAGb"}
@@ -0,0 +1,51 @@
1
+ import { EventTypes } from '@asyra/reactive-events';
2
+ import { OWNER, SELECTION_ACTIONS } from '@asyra/utils';
3
+ export default class BaseSelection {
4
+ constructor() {
5
+ this.selectedIds = new Set();
6
+ this.prevSelectedIds = new Set();
7
+ this.changes = [];
8
+ }
9
+ _updatePrevSelectedIds() {
10
+ this.prevSelectedIds = new Set(this.selectedIds);
11
+ }
12
+ select(ids) {
13
+ const before = [...this.getSelectedIds()];
14
+ this._updatePrevSelectedIds();
15
+ this.selectedIds = new Set(ids);
16
+ this.addChange(SELECTION_ACTIONS.SELECT_ELEMENTS, before, [...ids]);
17
+ }
18
+ deselect(ids) {
19
+ const before = [...this.getSelectedIds()];
20
+ this._updatePrevSelectedIds();
21
+ ids.forEach((id) => {
22
+ this.selectedIds.delete(id);
23
+ });
24
+ this.addChange(SELECTION_ACTIONS.SELECT_ELEMENTS, before, [...ids]);
25
+ }
26
+ clear() {
27
+ const before = [...this.getSelectedIds()];
28
+ this._updatePrevSelectedIds();
29
+ this.selectedIds.clear();
30
+ this.addChange(SELECTION_ACTIONS.SELECT_ELEMENTS, before, []);
31
+ }
32
+ getSelectedIds() {
33
+ return this.selectedIds;
34
+ }
35
+ getPrevSelectedIds() {
36
+ return this.prevSelectedIds;
37
+ }
38
+ addChange(action, before, after) {
39
+ this.changes.push({
40
+ action,
41
+ owner: OWNER.ELEMENT_SELECTION,
42
+ eventName: EventTypes.SELECT_ELEMENTS,
43
+ before,
44
+ after
45
+ });
46
+ }
47
+ cleanChanges() {
48
+ this.changes = [];
49
+ }
50
+ }
51
+ //# sourceMappingURL=base-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"base-selection.js","sourceRoot":"","sources":["../../src/selections/base-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAA;AACnD,OAAO,EAAE,KAAK,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAA;AAGvD,MAAM,CAAC,OAAO,OAAO,aAAa;IAAlC;QACY,gBAAW,GAAgB,IAAI,GAAG,EAAE,CAAA;QACpC,oBAAe,GAAgB,IAAI,GAAG,EAAE,CAAA;QAClD,YAAO,GAAsB,EAAE,CAAA;IAkDjC,CAAC;IAhDS,sBAAsB;QAC5B,IAAI,CAAC,eAAe,GAAG,IAAI,GAAG,CAAC,IAAI,CAAC,WAAW,CAAC,CAAA;IAClD,CAAC;IAED,MAAM,CAAC,GAAa;QAClB,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,CAAA;QACzC,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAC7B,IAAI,CAAC,WAAW,GAAG,IAAI,GAAG,CAAC,GAAG,CAAC,CAAA;QAC/B,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrE,CAAC;IAED,QAAQ,CAAC,GAAa;QACpB,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,CAAA;QACzC,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAC7B,GAAG,CAAC,OAAO,CAAC,CAAC,EAAE,EAAE,EAAE;YACjB,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,CAAC,CAAA;QAC7B,CAAC,CAAC,CAAA;QACF,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC,CAAC,CAAA;IACrE,CAAC;IAED,KAAK;QACH,MAAM,MAAM,GAAG,CAAC,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC,CAAA;QACzC,IAAI,CAAC,sBAAsB,EAAE,CAAA;QAC7B,IAAI,CAAC,WAAW,CAAC,KAAK,EAAE,CAAA;QACxB,IAAI,CAAC,SAAS,CAAC,iBAAiB,CAAC,eAAe,EAAE,MAAM,EAAE,EAAE,CAAC,CAAA;IAC/D,CAAC;IAED,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAA;IACzB,CAAC;IAED,kBAAkB;QAChB,OAAO,IAAI,CAAC,eAAe,CAAA;IAC7B,CAAC;IAED,SAAS,CAAC,MAAyB,EAAE,MAAgB,EAAE,KAAe;QACpE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC;YAChB,MAAM;YACN,KAAK,EAAE,KAAK,CAAC,iBAAiB;YAC9B,SAAS,EAAE,UAAU,CAAC,eAAe;YACrC,MAAM;YACN,KAAK;SACN,CAAC,CAAA;IACJ,CAAC;IAED,YAAY;QACV,IAAI,CAAC,OAAO,GAAG,EAAE,CAAA;IACnB,CAAC;CACF"}
@@ -0,0 +1,5 @@
1
+ import BaseSelection from './base-selection';
2
+ export default class ElementSelection extends BaseSelection {
3
+ }
4
+ export declare const elementSelection: ElementSelection;
5
+ //# sourceMappingURL=element-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-selection.d.ts","sourceRoot":"","sources":["../../src/selections/element-selection.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,aAAa;CAAG;AAE9D,eAAO,MAAM,gBAAgB,kBAAyB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import BaseSelection from './base-selection';
2
+ export default class ElementSelection extends BaseSelection {
3
+ }
4
+ export const elementSelection = new ElementSelection();
5
+ //# sourceMappingURL=element-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-selection.js","sourceRoot":"","sources":["../../src/selections/element-selection.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C,MAAM,CAAC,OAAO,OAAO,gBAAiB,SAAQ,aAAa;CAAG;AAE9D,MAAM,CAAC,MAAM,gBAAgB,GAAG,IAAI,gBAAgB,EAAE,CAAA"}
@@ -0,0 +1,5 @@
1
+ import BaseSelection from './base-selection';
2
+ export default class VertexSelection extends BaseSelection {
3
+ }
4
+ export declare const vertexSelection: VertexSelection;
5
+ //# sourceMappingURL=vertex-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vertex-selection.d.ts","sourceRoot":"","sources":["../../src/selections/vertex-selection.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,aAAa;CAAG;AAE7D,eAAO,MAAM,eAAe,iBAAwB,CAAA"}
@@ -0,0 +1,5 @@
1
+ import BaseSelection from './base-selection';
2
+ export default class VertexSelection extends BaseSelection {
3
+ }
4
+ export const vertexSelection = new VertexSelection();
5
+ //# sourceMappingURL=vertex-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"vertex-selection.js","sourceRoot":"","sources":["../../src/selections/vertex-selection.ts"],"names":[],"mappings":"AAAA,OAAO,aAAa,MAAM,kBAAkB,CAAA;AAE5C,MAAM,CAAC,OAAO,OAAO,eAAgB,SAAQ,aAAa;CAAG;AAE7D,MAAM,CAAC,MAAM,eAAe,GAAG,IAAI,eAAe,EAAE,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const initElementSelectionSubscribes: () => void;
2
+ //# sourceMappingURL=element-selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-selection.d.ts","sourceRoot":"","sources":["../../src/subscribes/element-selection.ts"],"names":[],"mappings":"AAMA,eAAO,MAAM,8BAA8B,YAS1C,CAAA"}
@@ -0,0 +1,12 @@
1
+ import { subscribeToSelectElements, updateTransaction } from '@asyra/reactive-events';
2
+ import { elementSelection } from '../selections/element-selection';
3
+ export const initElementSelectionSubscribes = () => {
4
+ subscribeToSelectElements(({ payload }) => {
5
+ elementSelection.select(payload.after);
6
+ elementSelection.changes.forEach((change) => {
7
+ updateTransaction(change.eventName, change);
8
+ });
9
+ elementSelection.cleanChanges();
10
+ });
11
+ };
12
+ //# sourceMappingURL=element-selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"element-selection.js","sourceRoot":"","sources":["../../src/subscribes/element-selection.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,yBAAyB,EACzB,iBAAiB,EAClB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EAAE,gBAAgB,EAAE,MAAM,iCAAiC,CAAA;AAElE,MAAM,CAAC,MAAM,8BAA8B,GAAG,GAAG,EAAE;IACjD,yBAAyB,CAAC,CAAC,EAAE,OAAO,EAAE,EAAE,EAAE;QACxC,gBAAgB,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAA;QAEtC,gBAAgB,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,MAAM,EAAE,EAAE;YAC1C,iBAAiB,CAAC,MAAM,CAAC,SAAS,EAAE,MAAM,CAAC,CAAA;QAC7C,CAAC,CAAC,CAAA;QACF,gBAAgB,CAAC,YAAY,EAAE,CAAA;IACjC,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const initSelectionSubscribes: () => void;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/subscribes/index.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,uBAAuB,YAEnC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { initElementSelectionSubscribes } from './element-selection';
2
+ export const initSelectionSubscribes = () => {
3
+ initElementSelectionSubscribes();
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/subscribes/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,8BAA8B,EAAE,MAAM,qBAAqB,CAAA;AAEpE,MAAM,CAAC,MAAM,uBAAuB,GAAG,GAAG,EAAE;IAC1C,8BAA8B,EAAE,CAAA;AAClC,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@asyra/selection",
3
+ "version": "0.2.0",
4
+ "description": "A selection management library for handling element, vertex, edge, or any other selectable entities in a scene graph.",
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:selection": "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
+ "@vitest/coverage-v8": "^2.1.8",
22
+ "typescript": "^5.7.2",
23
+ "vitest": "^2.1.8"
24
+ },
25
+ "dependencies": {
26
+ "@asyra/reactive-events": "workspace:*",
27
+ "@asyra/utils": "workspace:*"
28
+ }
29
+ }
@@ -0,0 +1,60 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest'
2
+ import { SELECTION_TYPES } from '@asyra/utils'
3
+ import SelectionManager from '../selection-manager'
4
+ import BaseSelection from '../selections/base-selection'
5
+
6
+ // Mock BaseSelection
7
+ const mockBaseSelection = {
8
+ clear: vi.fn(),
9
+ select: vi.fn(),
10
+ deselect: vi.fn(),
11
+ getSelectedIds: vi.fn(() => new Set()),
12
+ getPrevSelectedIds: vi.fn(() => new Set()),
13
+ addChange: vi.fn(),
14
+ cleanChanges: vi.fn()
15
+ }
16
+
17
+ describe('SelectionManager', () => {
18
+ let manager: SelectionManager
19
+
20
+ beforeEach(() => {
21
+ vi.clearAllMocks()
22
+
23
+ manager = new SelectionManager()
24
+ })
25
+
26
+ it('should register and retrieve selections correctly', () => {
27
+ manager.register(
28
+ SELECTION_TYPES.ELEMENT,
29
+ mockBaseSelection as unknown as BaseSelection
30
+ )
31
+
32
+ const selection = manager.get(SELECTION_TYPES.ELEMENT)
33
+
34
+ expect(selection).toBe(mockBaseSelection)
35
+ })
36
+
37
+ it('should return undefined for an unregistered selection type', () => {
38
+ const selection = manager.get(SELECTION_TYPES.VERTEX)
39
+
40
+ expect(selection).toBeUndefined()
41
+ })
42
+
43
+ it('should call clear() on all registered selections when clearAllSelections is called', () => {
44
+ const mockSelection1 = { ...mockBaseSelection, clear: vi.fn() }
45
+ const mockSelection2 = { ...mockBaseSelection, clear: vi.fn() }
46
+ manager.register(
47
+ SELECTION_TYPES.ELEMENT,
48
+ mockSelection1 as unknown as BaseSelection
49
+ )
50
+ manager.register(
51
+ SELECTION_TYPES.VERTEX,
52
+ mockSelection2 as unknown as BaseSelection
53
+ )
54
+
55
+ manager.clearAllSelections()
56
+
57
+ expect(mockSelection1.clear).toHaveBeenCalledTimes(1)
58
+ expect(mockSelection2.clear).toHaveBeenCalledTimes(1)
59
+ })
60
+ })
@@ -0,0 +1,59 @@
1
+ import { describe, it, expect, beforeEach } from 'vitest'
2
+ import Selection from '../selections/base-selection'
3
+
4
+ describe('Selection', () => {
5
+ let selection: Selection
6
+
7
+ beforeEach(() => {
8
+ selection = new Selection()
9
+ })
10
+
11
+ it('should initialize with no selected ids', () => {
12
+ expect(selection.getSelectedIds()).toEqual(new Set([]))
13
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]))
14
+ })
15
+
16
+ it('should select ids correctly', () => {
17
+ selection.select(['id1', 'id2'])
18
+
19
+ expect(selection.getSelectedIds()).toEqual(new Set(['id1', 'id2']))
20
+ })
21
+
22
+ it('should deselect id correctly', () => {
23
+ selection.select(['id1', 'id2'])
24
+ selection.deselect(['id1'])
25
+
26
+ expect(selection.getSelectedIds()).toEqual(new Set(['id2']))
27
+ })
28
+
29
+ it('should clear selection correctly', () => {
30
+ selection.select(['id1', 'id2'])
31
+ selection.clear()
32
+
33
+ expect(selection.getSelectedIds()).toEqual(new Set([]))
34
+ })
35
+
36
+ it('should store previous selected ids when selecting', () => {
37
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]))
38
+
39
+ selection.select(['id1', 'id2'])
40
+ expect(selection.getPrevSelectedIds()).toEqual(new Set([]))
41
+
42
+ selection.select(['id3'])
43
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']))
44
+ })
45
+
46
+ it('should store previous selected ids when deselecting', () => {
47
+ selection.select(['id1', 'id2'])
48
+ selection.deselect(['id1'])
49
+
50
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']))
51
+ })
52
+
53
+ it('should store previous selected ids when clearing', () => {
54
+ selection.select(['id1', 'id2'])
55
+ selection.clear()
56
+
57
+ expect(selection.getPrevSelectedIds()).toEqual(new Set(['id1', 'id2']))
58
+ })
59
+ })
package/src/index.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { SELECTION_TYPES } from '@asyra/utils'
2
+ import SelectionManager from './selection-manager'
3
+ import { elementSelection } from './selections/element-selection'
4
+ import { vertexSelection } from './selections/vertex-selection'
5
+ import { initSelectionSubscribes } from './subscribes'
6
+
7
+ initSelectionSubscribes()
8
+
9
+ const selectionManager = new SelectionManager()
10
+ selectionManager.register(SELECTION_TYPES.ELEMENT, elementSelection)
11
+ selectionManager.register(SELECTION_TYPES.VERTEX, vertexSelection)
12
+
13
+ export { SelectionManager }
14
+ export default selectionManager
@@ -0,0 +1,26 @@
1
+ import { SELECTION_TYPES } from '@asyra/utils'
2
+ import Selection from './selections/base-selection'
3
+
4
+ class SelectionManager {
5
+ private selections: Map<string, Selection> = new Map()
6
+
7
+ register(type: SELECTION_TYPES, selection: Selection): void {
8
+ this.selections.set(type, selection)
9
+ }
10
+
11
+ get(type: SELECTION_TYPES): Selection | undefined {
12
+ return this.selections.get(type)
13
+ }
14
+
15
+ clearAllSelections(): void {
16
+ this.selections.forEach((selection) => selection.clear())
17
+ }
18
+
19
+ getElementSelectionIds(): string[] {
20
+ return Array.from(
21
+ this.selections.get(SELECTION_TYPES.ELEMENT)?.getSelectedIds() || []
22
+ )
23
+ }
24
+ }
25
+
26
+ export default SelectionManager