@asyra/factory 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 (83) hide show
  1. package/.turbo/turbo-test$colon$ci.log +66 -0
  2. package/.turbo/turbo-test$colon$local.log +18 -0
  3. package/.turbo/turbo-test.log +357 -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 +228 -0
  8. package/coverage/coverage-final.json +3214 -0
  9. package/coverage/favicon.png +0 -0
  10. package/coverage/index.html +131 -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/data-transact.ts.html +589 -0
  16. package/coverage/src/data.ts.html +94 -0
  17. package/coverage/src/factory.ts.html +205 -0
  18. package/coverage/src/index.html +176 -0
  19. package/coverage/src/index.ts.html +106 -0
  20. package/coverage/src/registry/constants.ts.html +88 -0
  21. package/coverage/src/registry/index.html +176 -0
  22. package/coverage/src/registry/index.ts.html +94 -0
  23. package/coverage/src/registry/props.ts.html +112 -0
  24. package/coverage/src/registry/scene-tree.ts.html +115 -0
  25. package/coverage/src/registry/selection.ts.html +124 -0
  26. package/coverage/src/subscribes.ts.html +178 -0
  27. package/dist/__tests__/factory.test.d.ts +2 -0
  28. package/dist/__tests__/factory.test.d.ts.map +1 -0
  29. package/dist/__tests__/factory.test.js +44 -0
  30. package/dist/__tests__/factory.test.js.map +1 -0
  31. package/dist/data-transact.d.ts +19 -0
  32. package/dist/data-transact.d.ts.map +1 -0
  33. package/dist/data-transact.js +116 -0
  34. package/dist/data-transact.js.map +1 -0
  35. package/dist/data.d.ts +4 -0
  36. package/dist/data.d.ts.map +1 -0
  37. package/dist/data.js +4 -0
  38. package/dist/data.js.map +1 -0
  39. package/dist/factory.d.ts +19 -0
  40. package/dist/factory.d.ts.map +1 -0
  41. package/dist/factory.js +31 -0
  42. package/dist/factory.js.map +1 -0
  43. package/dist/index.d.ts +4 -0
  44. package/dist/index.d.ts.map +1 -0
  45. package/dist/index.js +6 -0
  46. package/dist/index.js.map +1 -0
  47. package/dist/registry/constants.d.ts +2 -0
  48. package/dist/registry/constants.d.ts.map +1 -0
  49. package/dist/registry/constants.js +2 -0
  50. package/dist/registry/constants.js.map +1 -0
  51. package/dist/registry/index.d.ts +4 -0
  52. package/dist/registry/index.d.ts.map +1 -0
  53. package/dist/registry/index.js +4 -0
  54. package/dist/registry/index.js.map +1 -0
  55. package/dist/registry/props.d.ts +5 -0
  56. package/dist/registry/props.d.ts.map +1 -0
  57. package/dist/registry/props.js +8 -0
  58. package/dist/registry/props.js.map +1 -0
  59. package/dist/registry/scene-tree.d.ts +5 -0
  60. package/dist/registry/scene-tree.d.ts.map +1 -0
  61. package/dist/registry/scene-tree.js +8 -0
  62. package/dist/registry/scene-tree.js.map +1 -0
  63. package/dist/registry/selection.d.ts +5 -0
  64. package/dist/registry/selection.d.ts.map +1 -0
  65. package/dist/registry/selection.js +8 -0
  66. package/dist/registry/selection.js.map +1 -0
  67. package/dist/subscribes.d.ts +2 -0
  68. package/dist/subscribes.d.ts.map +1 -0
  69. package/dist/subscribes.js +20 -0
  70. package/dist/subscribes.js.map +1 -0
  71. package/package.json +30 -0
  72. package/src/__tests__/factory.test.ts +54 -0
  73. package/src/data-transact.ts +168 -0
  74. package/src/data.ts +3 -0
  75. package/src/factory.ts +40 -0
  76. package/src/index.ts +7 -0
  77. package/src/registry/constants.ts +1 -0
  78. package/src/registry/index.ts +3 -0
  79. package/src/registry/props.ts +9 -0
  80. package/src/registry/scene-tree.ts +10 -0
  81. package/src/registry/selection.ts +13 -0
  82. package/src/subscribes.ts +31 -0
  83. package/tsconfig.json +17 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/registry/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAA;AACvB,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA"}
@@ -0,0 +1,5 @@
1
+ import * as Y from 'yjs';
2
+ import { PropsYjsChange } from '@asyra/utils';
3
+ export declare const propsChanges: Y.Array<PropsYjsChange>;
4
+ export declare const propsChangesManager: Y.UndoManager;
5
+ //# sourceMappingURL=props.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.d.ts","sourceRoot":"","sources":["../../src/registry/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAA;AAI7C,eAAO,MAAM,YAAY,yBAA+C,CAAA;AACxE,eAAO,MAAM,mBAAmB,eAE9B,CAAA"}
@@ -0,0 +1,8 @@
1
+ import * as Y from 'yjs';
2
+ import doc from '../data';
3
+ import { UNDO_CAPTURE_TIMEOUT } from './constants';
4
+ export const propsChanges = doc.getArray('propsChanges');
5
+ export const propsChangesManager = new Y.UndoManager(propsChanges, {
6
+ captureTimeout: UNDO_CAPTURE_TIMEOUT
7
+ });
8
+ //# sourceMappingURL=props.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"props.js","sourceRoot":"","sources":["../../src/registry/props.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,GAAG,MAAM,SAAS,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,CAAC,MAAM,YAAY,GAAG,GAAG,CAAC,QAAQ,CAAiB,cAAc,CAAC,CAAA;AACxE,MAAM,CAAC,MAAM,mBAAmB,GAAG,IAAI,CAAC,CAAC,WAAW,CAAC,YAAY,EAAE;IACjE,cAAc,EAAE,oBAAoB;CACrC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import * as Y from 'yjs';
2
+ import { SceneTreeYjsChange } from '@asyra/utils';
3
+ export declare const sceneTreeChanges: Y.Array<SceneTreeYjsChange>;
4
+ export declare const sceneTreeChangesManager: Y.UndoManager;
5
+ //# sourceMappingURL=scene-tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-tree.d.ts","sourceRoot":"","sources":["../../src/registry/scene-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAIjD,eAAO,MAAM,gBAAgB,6BACyB,CAAA;AACtD,eAAO,MAAM,uBAAuB,eAElC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import * as Y from 'yjs';
2
+ import doc from '../data';
3
+ import { UNDO_CAPTURE_TIMEOUT } from './constants';
4
+ export const sceneTreeChanges = doc.getArray('sceneTreeChanges');
5
+ export const sceneTreeChangesManager = new Y.UndoManager(sceneTreeChanges, {
6
+ captureTimeout: UNDO_CAPTURE_TIMEOUT
7
+ });
8
+ //# sourceMappingURL=scene-tree.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scene-tree.js","sourceRoot":"","sources":["../../src/registry/scene-tree.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,GAAG,MAAM,SAAS,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,CAAC,MAAM,gBAAgB,GAC3B,GAAG,CAAC,QAAQ,CAAqB,kBAAkB,CAAC,CAAA;AACtD,MAAM,CAAC,MAAM,uBAAuB,GAAG,IAAI,CAAC,CAAC,WAAW,CAAC,gBAAgB,EAAE;IACzE,cAAc,EAAE,oBAAoB;CACrC,CAAC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import * as Y from 'yjs';
2
+ import { SelectionYjsChange } from '@asyra/utils';
3
+ export declare const elementSelectionChanges: Y.Array<SelectionYjsChange>;
4
+ export declare const elementSelectionChangeManager: Y.UndoManager;
5
+ //# sourceMappingURL=selection.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.d.ts","sourceRoot":"","sources":["../../src/registry/selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAIjD,eAAO,MAAM,uBAAuB,6BACkB,CAAA;AACtD,eAAO,MAAM,6BAA6B,eAKzC,CAAA"}
@@ -0,0 +1,8 @@
1
+ import * as Y from 'yjs';
2
+ import doc from '../data';
3
+ import { UNDO_CAPTURE_TIMEOUT } from './constants';
4
+ export const elementSelectionChanges = doc.getArray('selectionChanges');
5
+ export const elementSelectionChangeManager = new Y.UndoManager(elementSelectionChanges, {
6
+ captureTimeout: UNDO_CAPTURE_TIMEOUT
7
+ });
8
+ //# sourceMappingURL=selection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"selection.js","sourceRoot":"","sources":["../../src/registry/selection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AAExB,OAAO,GAAG,MAAM,SAAS,CAAA;AACzB,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAElD,MAAM,CAAC,MAAM,uBAAuB,GAClC,GAAG,CAAC,QAAQ,CAAqB,kBAAkB,CAAC,CAAA;AACtD,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,CAAC,CAAC,WAAW,CAC5D,uBAAuB,EACvB;IACE,cAAc,EAAE,oBAAoB;CACrC,CACF,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const initFactorySubscribe: () => void;
2
+ //# sourceMappingURL=subscribes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscribes.d.ts","sourceRoot":"","sources":["../src/subscribes.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,oBAAoB,YAoBhC,CAAA"}
@@ -0,0 +1,20 @@
1
+ import { subscribeToStartTransaction, subscribeToUpdateTransaction, subscribeToEndTransaction, subscribeToUndo, subscribeToRedo } from '@asyra/reactive-events';
2
+ import factory from './factory';
3
+ export const initFactorySubscribe = () => {
4
+ subscribeToStartTransaction(() => {
5
+ factory.startTransaction();
6
+ });
7
+ subscribeToUpdateTransaction((event) => {
8
+ factory.updateTransaction(event);
9
+ });
10
+ subscribeToEndTransaction(() => {
11
+ factory.endTransaction();
12
+ });
13
+ subscribeToUndo(() => {
14
+ factory.undo();
15
+ });
16
+ subscribeToRedo(() => {
17
+ factory.redo();
18
+ });
19
+ };
20
+ //# sourceMappingURL=subscribes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscribes.js","sourceRoot":"","sources":["../src/subscribes.ts"],"names":[],"mappings":"AACA,OAAO,EACL,2BAA2B,EAC3B,4BAA4B,EAC5B,yBAAyB,EACzB,eAAe,EACf,eAAe,EAChB,MAAM,wBAAwB,CAAA;AAC/B,OAAO,OAAO,MAAM,WAAW,CAAA;AAE/B,MAAM,CAAC,MAAM,oBAAoB,GAAG,GAAG,EAAE;IACvC,2BAA2B,CAAC,GAAG,EAAE;QAC/B,OAAO,CAAC,gBAAgB,EAAE,CAAA;IAC5B,CAAC,CAAC,CAAA;IAEF,4BAA4B,CAAC,CAAC,KAA6B,EAAE,EAAE;QAC7D,OAAO,CAAC,iBAAiB,CAAC,KAAK,CAAC,CAAA;IAClC,CAAC,CAAC,CAAA;IAEF,yBAAyB,CAAC,GAAG,EAAE;QAC7B,OAAO,CAAC,cAAc,EAAE,CAAA;IAC1B,CAAC,CAAC,CAAA;IAEF,eAAe,CAAC,GAAG,EAAE;QACnB,OAAO,CAAC,IAAI,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;IAEF,eAAe,CAAC,GAAG,EAAE;QACnB,OAAO,CAAC,IAAI,EAAE,CAAA;IAChB,CAAC,CAAC,CAAA;AACJ,CAAC,CAAA"}
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@asyra/factory",
3
+ "version": "0.2.0",
4
+ "description": "Manipulate with data changes",
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:factory": "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
+ "yjs": "13.6.20"
29
+ }
30
+ }
@@ -0,0 +1,54 @@
1
+ import { describe, it, expect, vi, beforeEach } from 'vitest'
2
+ import { Factory } from '../factory'
3
+ import type _DataTransact from '../data-transact' // Keep this import for type inference
4
+ import {
5
+ UpdateTransactionEvent,
6
+ TransactionEventTypes
7
+ } from '@asyra/reactive-events'
8
+
9
+ describe('Factory', () => {
10
+ let factory: Factory
11
+
12
+ beforeEach(() => {
13
+ vi.clearAllMocks()
14
+ vi.resetAllMocks()
15
+ factory = new Factory()
16
+ // Spy on the methods of the actual DataTransact instance
17
+ vi.spyOn(factory.transact, 'start')
18
+ vi.spyOn(factory.transact, 'update')
19
+ vi.spyOn(factory.transact, 'end')
20
+ vi.spyOn(factory.transact, 'undo')
21
+ vi.spyOn(factory.transact, 'redo')
22
+ })
23
+
24
+ it('should call DataTransact.start when startTransaction is called', () => {
25
+ factory.startTransaction()
26
+ expect(factory.transact.start).toHaveBeenCalledTimes(1)
27
+ })
28
+
29
+ it('should call DataTransact.update when updateTransaction is called', () => {
30
+ const mockEvent: UpdateTransactionEvent = {
31
+ type: TransactionEventTypes.UPDATE_TRANSACTION,
32
+ eventName: 'test-event',
33
+ payload: { changes: [] }
34
+ }
35
+ factory.updateTransaction(mockEvent)
36
+ expect(factory.transact.update).toHaveBeenCalledTimes(1)
37
+ expect(factory.transact.update).toHaveBeenCalledWith(mockEvent)
38
+ })
39
+
40
+ it('should call DataTransact.end when endTransaction is called', () => {
41
+ factory.endTransaction()
42
+ expect(factory.transact.end).toHaveBeenCalledTimes(1)
43
+ })
44
+
45
+ it('should call DataTransact.undo when undo is called', () => {
46
+ factory.undo()
47
+ expect(factory.transact.undo).toHaveBeenCalledTimes(1)
48
+ })
49
+
50
+ it('should call DataTransact.redo when redo is called', () => {
51
+ factory.redo()
52
+ expect(factory.transact.redo).toHaveBeenCalledTimes(1)
53
+ })
54
+ })
@@ -0,0 +1,168 @@
1
+ import * as Y from 'yjs'
2
+ import type {
3
+ PropsYjsChange,
4
+ SceneTreeYjsChange,
5
+ SelectionYjsChange
6
+ } from '@asyra/utils'
7
+ import { OWNER, UNDO } from '@asyra/utils'
8
+ import type { AllEvent, UpdateTransactionEvent } from '@asyra/reactive-events'
9
+ import {
10
+ endTransaction,
11
+ publishEvent,
12
+ startTransaction,
13
+ updateUndoRedoStatus
14
+ } from '@asyra/reactive-events'
15
+ import {
16
+ sceneTreeChanges,
17
+ elementSelectionChanges,
18
+ propsChanges
19
+ } from './registry'
20
+
21
+ type YMapOrArray<T = unknown> = Y.Array<T> | Y.Map<T>
22
+
23
+ interface ChangesTypeMap {
24
+ [OWNER.SCENE_TREE]: YMapOrArray<SceneTreeYjsChange>
25
+ [OWNER.ELEMENT_SELECTION]: YMapOrArray<SelectionYjsChange>
26
+ [OWNER.PROPS]: YMapOrArray<PropsYjsChange>
27
+ }
28
+
29
+ const ChangesMaps: ChangesTypeMap = {
30
+ [OWNER.SCENE_TREE]: sceneTreeChanges,
31
+ [OWNER.ELEMENT_SELECTION]: elementSelectionChanges,
32
+ [OWNER.PROPS]: propsChanges
33
+ }
34
+
35
+ class DataTransact {
36
+ private changes: AllEvent[] = []
37
+ private undoStack: AllEvent[][] = []
38
+ private redoStack: AllEvent[][] = []
39
+ private isTransacting = 0
40
+ private inUndo = false
41
+ private inRedo = false
42
+
43
+ start() {
44
+ this.isTransacting++
45
+ if (this.isTransacting > 1) {
46
+ return
47
+ }
48
+
49
+ this.changes = []
50
+ }
51
+
52
+ update(event: UpdateTransactionEvent) {
53
+ if (this.isTransacting <= 0) {
54
+ return
55
+ }
56
+
57
+ const newType = event.eventName as AllEvent['type']
58
+ const newPayload = JSON.parse(JSON.stringify(event.payload))
59
+ const newEvent: AllEvent = {
60
+ type: newType,
61
+ payload: newPayload
62
+ }
63
+
64
+ if (!(event.options && !event.options.undoable)) {
65
+ this.changes.push(newEvent)
66
+ }
67
+
68
+ const map = ChangesMaps[event.payload.owner as OWNER]
69
+ if (map instanceof Y.Array) {
70
+ map.push([event.payload])
71
+ }
72
+ }
73
+
74
+ end() {
75
+ if (this.isTransacting <= 0) {
76
+ return
77
+ }
78
+
79
+ this.isTransacting--
80
+
81
+ if (this.isTransacting === 0) {
82
+ this.commitUndo()
83
+ this.changes = []
84
+ }
85
+ }
86
+
87
+ commitUndo() {
88
+ // If changes are coming from Undo or Redo events, they should not push back to list again
89
+ if (!this.isInUndo() && !this.isInRedo() && this.changes.length > 0) {
90
+ this.undoStack.push(this.changes)
91
+ this.changes = []
92
+ this.redoStack = []
93
+ }
94
+ }
95
+
96
+ undo() {
97
+ if (!this.undoStack.length) {
98
+ return
99
+ }
100
+
101
+ startTransaction()
102
+
103
+ this.inUndo = true
104
+ updateUndoRedoStatus(UNDO.UNDO)
105
+
106
+ const lastChanges = this.undoStack.pop() as AllEvent[]
107
+ for (let i = lastChanges.length - 1; i >= 0; i--) {
108
+ const event = lastChanges[i]
109
+ const undoEvent = JSON.parse(JSON.stringify(event))
110
+
111
+ if (undoEvent.payload.undoType !== undefined) {
112
+ undoEvent.type = undoEvent.payload.undoType
113
+ }
114
+ if (undoEvent.payload.undoAction !== undefined) {
115
+ undoEvent.payload.action = undoEvent.payload.undoAction
116
+ }
117
+ if (undoEvent.payload.after !== undefined) {
118
+ undoEvent.payload.after = undoEvent.payload.before
119
+ }
120
+
121
+ publishEvent(undoEvent)
122
+ }
123
+
124
+ this.redoStack.push(lastChanges)
125
+
126
+ endTransaction()
127
+
128
+ updateUndoRedoStatus(UNDO.NONE)
129
+
130
+ this.changes = []
131
+ this.inUndo = false
132
+ }
133
+
134
+ redo() {
135
+ if (!this.redoStack.length) {
136
+ return
137
+ }
138
+
139
+ startTransaction()
140
+
141
+ this.inRedo = true
142
+ updateUndoRedoStatus(UNDO.REDO)
143
+
144
+ const lastChanges = this.redoStack.pop() as AllEvent[]
145
+ for (const event of lastChanges) {
146
+ const redoEvent = JSON.parse(JSON.stringify(event))
147
+ publishEvent(redoEvent)
148
+ }
149
+
150
+ this.undoStack.push(lastChanges)
151
+ endTransaction()
152
+
153
+ updateUndoRedoStatus(UNDO.NONE)
154
+
155
+ this.changes = []
156
+ this.inRedo = false
157
+ }
158
+
159
+ isInUndo() {
160
+ return this.inUndo
161
+ }
162
+
163
+ isInRedo() {
164
+ return this.inRedo
165
+ }
166
+ }
167
+
168
+ export default DataTransact
package/src/data.ts ADDED
@@ -0,0 +1,3 @@
1
+ import * as Y from 'yjs'
2
+ const doc = new Y.Doc()
3
+ export default doc
package/src/factory.ts ADDED
@@ -0,0 +1,40 @@
1
+ import * as Y from 'yjs'
2
+ import type { SceneTreeYjsChange, SelectionYjsChange } from '@asyra/utils'
3
+ import type { UpdateTransactionEvent } from '@asyra/reactive-events'
4
+ import DataTransact from './data-transact'
5
+ import { sceneTreeChanges, elementSelectionChanges } from './registry'
6
+
7
+ class Factory {
8
+ sceneTreeMap: Y.Array<SceneTreeYjsChange> = sceneTreeChanges
9
+ elementSelectionMap: Y.Array<SelectionYjsChange> = elementSelectionChanges
10
+ transact: DataTransact = new DataTransact()
11
+
12
+ startTransaction() {
13
+ this.transact.start()
14
+ }
15
+
16
+ updateTransaction(event: UpdateTransactionEvent) {
17
+ this.transact.update(event)
18
+ }
19
+
20
+ endTransaction() {
21
+ this.transact.end()
22
+ }
23
+
24
+ undo() {
25
+ this.transact.undo()
26
+ }
27
+
28
+ redo() {
29
+ this.transact.redo()
30
+ }
31
+
32
+ isInUndoRedo() {
33
+ return this.transact.isInUndo() || this.transact.isInRedo()
34
+ }
35
+ }
36
+
37
+ const factory = new Factory()
38
+ export default factory
39
+
40
+ export { Factory }
package/src/index.ts ADDED
@@ -0,0 +1,7 @@
1
+ import factory, { Factory } from './factory'
2
+ import { initFactorySubscribe } from './subscribes'
3
+
4
+ initFactorySubscribe()
5
+
6
+ export default factory
7
+ export { Factory }
@@ -0,0 +1 @@
1
+ export const UNDO_CAPTURE_TIMEOUT = 0
@@ -0,0 +1,3 @@
1
+ export * from './props'
2
+ export * from './scene-tree'
3
+ export * from './selection'
@@ -0,0 +1,9 @@
1
+ import * as Y from 'yjs'
2
+ import { PropsYjsChange } from '@asyra/utils'
3
+ import doc from '../data'
4
+ import { UNDO_CAPTURE_TIMEOUT } from './constants'
5
+
6
+ export const propsChanges = doc.getArray<PropsYjsChange>('propsChanges')
7
+ export const propsChangesManager = new Y.UndoManager(propsChanges, {
8
+ captureTimeout: UNDO_CAPTURE_TIMEOUT
9
+ })
@@ -0,0 +1,10 @@
1
+ import * as Y from 'yjs'
2
+ import { SceneTreeYjsChange } from '@asyra/utils'
3
+ import doc from '../data'
4
+ import { UNDO_CAPTURE_TIMEOUT } from './constants'
5
+
6
+ export const sceneTreeChanges =
7
+ doc.getArray<SceneTreeYjsChange>('sceneTreeChanges')
8
+ export const sceneTreeChangesManager = new Y.UndoManager(sceneTreeChanges, {
9
+ captureTimeout: UNDO_CAPTURE_TIMEOUT
10
+ })
@@ -0,0 +1,13 @@
1
+ import * as Y from 'yjs'
2
+ import { SelectionYjsChange } from '@asyra/utils'
3
+ import doc from '../data'
4
+ import { UNDO_CAPTURE_TIMEOUT } from './constants'
5
+
6
+ export const elementSelectionChanges =
7
+ doc.getArray<SelectionYjsChange>('selectionChanges')
8
+ export const elementSelectionChangeManager = new Y.UndoManager(
9
+ elementSelectionChanges,
10
+ {
11
+ captureTimeout: UNDO_CAPTURE_TIMEOUT
12
+ }
13
+ )
@@ -0,0 +1,31 @@
1
+ import type { UpdateTransactionEvent } from '@asyra/reactive-events'
2
+ import {
3
+ subscribeToStartTransaction,
4
+ subscribeToUpdateTransaction,
5
+ subscribeToEndTransaction,
6
+ subscribeToUndo,
7
+ subscribeToRedo
8
+ } from '@asyra/reactive-events'
9
+ import factory from './factory'
10
+
11
+ export const initFactorySubscribe = () => {
12
+ subscribeToStartTransaction(() => {
13
+ factory.startTransaction()
14
+ })
15
+
16
+ subscribeToUpdateTransaction((event: UpdateTransactionEvent) => {
17
+ factory.updateTransaction(event)
18
+ })
19
+
20
+ subscribeToEndTransaction(() => {
21
+ factory.endTransaction()
22
+ })
23
+
24
+ subscribeToUndo(() => {
25
+ factory.undo()
26
+ })
27
+
28
+ subscribeToRedo(() => {
29
+ factory.redo()
30
+ })
31
+ }
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
+ }