@asyra/factory 0.2.5 → 0.5.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 (105) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -1
  3. package/dist/data-transact.d.ts +182 -6
  4. package/dist/data-transact.d.ts.map +1 -1
  5. package/dist/data-transact.js +3157 -57
  6. package/dist/data-transact.js.map +1 -1
  7. package/dist/factory.d.ts +58 -8
  8. package/dist/factory.d.ts.map +1 -1
  9. package/dist/factory.js +273 -13
  10. package/dist/factory.js.map +1 -1
  11. package/dist/index.d.ts +22 -1
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +21 -2
  14. package/dist/index.js.map +1 -1
  15. package/dist/mutation-batch.d.ts +28 -0
  16. package/dist/mutation-batch.d.ts.map +1 -0
  17. package/dist/mutation-batch.js +11 -0
  18. package/dist/mutation-batch.js.map +1 -0
  19. package/dist/shared-data-channel.d.ts +29 -0
  20. package/dist/shared-data-channel.d.ts.map +1 -0
  21. package/dist/shared-data-channel.js +147 -0
  22. package/dist/shared-data-channel.js.map +1 -0
  23. package/dist/shared-delivery.d.ts +76 -0
  24. package/dist/shared-delivery.d.ts.map +1 -0
  25. package/dist/shared-delivery.js +4 -0
  26. package/dist/shared-delivery.js.map +1 -0
  27. package/dist/subscribes.d.ts +1 -1
  28. package/dist/subscribes.d.ts.map +1 -1
  29. package/dist/subscribes.js +3 -19
  30. package/dist/subscribes.js.map +1 -1
  31. package/dist/transaction.d.ts +31 -0
  32. package/dist/transaction.d.ts.map +1 -0
  33. package/dist/transaction.js +17 -0
  34. package/dist/transaction.js.map +1 -0
  35. package/dist/value-clone.d.ts +7 -0
  36. package/dist/value-clone.d.ts.map +1 -0
  37. package/dist/value-clone.js +76 -0
  38. package/dist/value-clone.js.map +1 -0
  39. package/package.json +22 -5
  40. package/.turbo/turbo-test$colon$ci.log +0 -66
  41. package/.turbo/turbo-test$colon$local.log +0 -25
  42. package/.turbo/turbo-test.log +0 -357
  43. package/CHANGELOG.md +0 -46
  44. package/coverage/base.css +0 -224
  45. package/coverage/block-navigation.js +0 -87
  46. package/coverage/clover.xml +0 -228
  47. package/coverage/coverage-final.json +0 -3214
  48. package/coverage/favicon.png +0 -0
  49. package/coverage/index.html +0 -131
  50. package/coverage/prettify.css +0 -1
  51. package/coverage/prettify.js +0 -2
  52. package/coverage/sort-arrow-sprite.png +0 -0
  53. package/coverage/sorter.js +0 -196
  54. package/coverage/src/data-transact.ts.html +0 -589
  55. package/coverage/src/data.ts.html +0 -94
  56. package/coverage/src/factory.ts.html +0 -205
  57. package/coverage/src/index.html +0 -176
  58. package/coverage/src/index.ts.html +0 -106
  59. package/coverage/src/registry/constants.ts.html +0 -88
  60. package/coverage/src/registry/index.html +0 -176
  61. package/coverage/src/registry/index.ts.html +0 -94
  62. package/coverage/src/registry/props.ts.html +0 -112
  63. package/coverage/src/registry/scene-tree.ts.html +0 -115
  64. package/coverage/src/registry/selection.ts.html +0 -124
  65. package/coverage/src/subscribes.ts.html +0 -178
  66. package/dist/__tests__/factory.test.d.ts +0 -2
  67. package/dist/__tests__/factory.test.d.ts.map +0 -1
  68. package/dist/__tests__/factory.test.js +0 -44
  69. package/dist/__tests__/factory.test.js.map +0 -1
  70. package/dist/data.d.ts +0 -4
  71. package/dist/data.d.ts.map +0 -1
  72. package/dist/data.js +0 -4
  73. package/dist/data.js.map +0 -1
  74. package/dist/registry/constants.d.ts +0 -2
  75. package/dist/registry/constants.d.ts.map +0 -1
  76. package/dist/registry/constants.js +0 -2
  77. package/dist/registry/constants.js.map +0 -1
  78. package/dist/registry/index.d.ts +0 -4
  79. package/dist/registry/index.d.ts.map +0 -1
  80. package/dist/registry/index.js +0 -4
  81. package/dist/registry/index.js.map +0 -1
  82. package/dist/registry/props.d.ts +0 -5
  83. package/dist/registry/props.d.ts.map +0 -1
  84. package/dist/registry/props.js +0 -8
  85. package/dist/registry/props.js.map +0 -1
  86. package/dist/registry/scene-tree.d.ts +0 -5
  87. package/dist/registry/scene-tree.d.ts.map +0 -1
  88. package/dist/registry/scene-tree.js +0 -8
  89. package/dist/registry/scene-tree.js.map +0 -1
  90. package/dist/registry/selection.d.ts +0 -5
  91. package/dist/registry/selection.d.ts.map +0 -1
  92. package/dist/registry/selection.js +0 -8
  93. package/dist/registry/selection.js.map +0 -1
  94. package/src/__tests__/factory.test.ts +0 -54
  95. package/src/data-transact.ts +0 -168
  96. package/src/data.ts +0 -3
  97. package/src/factory.ts +0 -40
  98. package/src/index.ts +0 -7
  99. package/src/registry/constants.ts +0 -1
  100. package/src/registry/index.ts +0 -3
  101. package/src/registry/props.ts +0 -9
  102. package/src/registry/scene-tree.ts +0 -10
  103. package/src/registry/selection.ts +0 -13
  104. package/src/subscribes.ts +0 -31
  105. package/tsconfig.json +0 -17
@@ -1,168 +0,0 @@
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 DELETED
@@ -1,3 +0,0 @@
1
- import * as Y from 'yjs'
2
- const doc = new Y.Doc()
3
- export default doc
package/src/factory.ts DELETED
@@ -1,40 +0,0 @@
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 DELETED
@@ -1,7 +0,0 @@
1
- import factory, { Factory } from './factory'
2
- import { initFactorySubscribe } from './subscribes'
3
-
4
- initFactorySubscribe()
5
-
6
- export default factory
7
- export { Factory }
@@ -1 +0,0 @@
1
- export const UNDO_CAPTURE_TIMEOUT = 0
@@ -1,3 +0,0 @@
1
- export * from './props'
2
- export * from './scene-tree'
3
- export * from './selection'
@@ -1,9 +0,0 @@
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
- })
@@ -1,10 +0,0 @@
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
- })
@@ -1,13 +0,0 @@
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
- )
package/src/subscribes.ts DELETED
@@ -1,31 +0,0 @@
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 DELETED
@@ -1,17 +0,0 @@
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
- }