@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,58 @@
1
+ import { EventTypes } from '@asyra/reactive-events'
2
+ import { OWNER, SELECTION_ACTIONS } from '@asyra/utils'
3
+ import type { SelectionChange } from '@asyra/utils'
4
+
5
+ export default class BaseSelection {
6
+ protected selectedIds: Set<string> = new Set()
7
+ protected prevSelectedIds: Set<string> = new Set()
8
+ changes: SelectionChange[] = []
9
+
10
+ private _updatePrevSelectedIds(): void {
11
+ this.prevSelectedIds = new Set(this.selectedIds)
12
+ }
13
+
14
+ select(ids: string[]): void {
15
+ const before = [...this.getSelectedIds()]
16
+ this._updatePrevSelectedIds()
17
+ this.selectedIds = new Set(ids)
18
+ this.addChange(SELECTION_ACTIONS.SELECT_ELEMENTS, before, [...ids])
19
+ }
20
+
21
+ deselect(ids: string[]): void {
22
+ const before = [...this.getSelectedIds()]
23
+ this._updatePrevSelectedIds()
24
+ ids.forEach((id) => {
25
+ this.selectedIds.delete(id)
26
+ })
27
+ this.addChange(SELECTION_ACTIONS.SELECT_ELEMENTS, before, [...ids])
28
+ }
29
+
30
+ clear(): void {
31
+ const before = [...this.getSelectedIds()]
32
+ this._updatePrevSelectedIds()
33
+ this.selectedIds.clear()
34
+ this.addChange(SELECTION_ACTIONS.SELECT_ELEMENTS, before, [])
35
+ }
36
+
37
+ getSelectedIds(): Set<string> {
38
+ return this.selectedIds
39
+ }
40
+
41
+ getPrevSelectedIds(): Set<string> {
42
+ return this.prevSelectedIds
43
+ }
44
+
45
+ addChange(action: SELECTION_ACTIONS, before: string[], after: string[]) {
46
+ this.changes.push({
47
+ action,
48
+ owner: OWNER.ELEMENT_SELECTION,
49
+ eventName: EventTypes.SELECT_ELEMENTS,
50
+ before,
51
+ after
52
+ })
53
+ }
54
+
55
+ cleanChanges() {
56
+ this.changes = []
57
+ }
58
+ }
@@ -0,0 +1,5 @@
1
+ import BaseSelection from './base-selection'
2
+
3
+ export default class ElementSelection extends BaseSelection {}
4
+
5
+ export const elementSelection = new ElementSelection()
@@ -0,0 +1,5 @@
1
+ import BaseSelection from './base-selection'
2
+
3
+ export default class VertexSelection extends BaseSelection {}
4
+
5
+ export const vertexSelection = new VertexSelection()
@@ -0,0 +1,16 @@
1
+ import {
2
+ subscribeToSelectElements,
3
+ updateTransaction
4
+ } from '@asyra/reactive-events'
5
+ import { elementSelection } from '../selections/element-selection'
6
+
7
+ export const initElementSelectionSubscribes = () => {
8
+ subscribeToSelectElements(({ payload }) => {
9
+ elementSelection.select(payload.after)
10
+
11
+ elementSelection.changes.forEach((change) => {
12
+ updateTransaction(change.eventName, change)
13
+ })
14
+ elementSelection.cleanChanges()
15
+ })
16
+ }
@@ -0,0 +1,5 @@
1
+ import { initElementSelectionSubscribes } from './element-selection'
2
+
3
+ export const initSelectionSubscribes = () => {
4
+ initElementSelectionSubscribes()
5
+ }
package/tsconfig.json ADDED
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "ESNext",
5
+ "declaration": true,
6
+ "declarationMap": true,
7
+ "sourceMap": true,
8
+ "outDir": "./dist",
9
+ "strict": true,
10
+ "esModuleInterop": true,
11
+ "skipLibCheck": true,
12
+ "moduleResolution": "Node",
13
+ "resolveJsonModule": true
14
+ },
15
+ "include": ["src"],
16
+ "exclude": ["node_modules", "dist"]
17
+ }