@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.
- package/LICENSE +21 -0
- package/README.md +13 -1
- package/dist/data-transact.d.ts +182 -6
- package/dist/data-transact.d.ts.map +1 -1
- package/dist/data-transact.js +3157 -57
- package/dist/data-transact.js.map +1 -1
- package/dist/factory.d.ts +58 -8
- package/dist/factory.d.ts.map +1 -1
- package/dist/factory.js +273 -13
- package/dist/factory.js.map +1 -1
- package/dist/index.d.ts +22 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +21 -2
- package/dist/index.js.map +1 -1
- package/dist/mutation-batch.d.ts +28 -0
- package/dist/mutation-batch.d.ts.map +1 -0
- package/dist/mutation-batch.js +11 -0
- package/dist/mutation-batch.js.map +1 -0
- package/dist/shared-data-channel.d.ts +29 -0
- package/dist/shared-data-channel.d.ts.map +1 -0
- package/dist/shared-data-channel.js +147 -0
- package/dist/shared-data-channel.js.map +1 -0
- package/dist/shared-delivery.d.ts +76 -0
- package/dist/shared-delivery.d.ts.map +1 -0
- package/dist/shared-delivery.js +4 -0
- package/dist/shared-delivery.js.map +1 -0
- package/dist/subscribes.d.ts +1 -1
- package/dist/subscribes.d.ts.map +1 -1
- package/dist/subscribes.js +3 -19
- package/dist/subscribes.js.map +1 -1
- package/dist/transaction.d.ts +31 -0
- package/dist/transaction.d.ts.map +1 -0
- package/dist/transaction.js +17 -0
- package/dist/transaction.js.map +1 -0
- package/dist/value-clone.d.ts +7 -0
- package/dist/value-clone.d.ts.map +1 -0
- package/dist/value-clone.js +76 -0
- package/dist/value-clone.js.map +1 -0
- package/package.json +22 -5
- package/.turbo/turbo-test$colon$ci.log +0 -66
- package/.turbo/turbo-test$colon$local.log +0 -25
- package/.turbo/turbo-test.log +0 -357
- package/CHANGELOG.md +0 -46
- package/coverage/base.css +0 -224
- package/coverage/block-navigation.js +0 -87
- package/coverage/clover.xml +0 -228
- package/coverage/coverage-final.json +0 -3214
- package/coverage/favicon.png +0 -0
- package/coverage/index.html +0 -131
- package/coverage/prettify.css +0 -1
- package/coverage/prettify.js +0 -2
- package/coverage/sort-arrow-sprite.png +0 -0
- package/coverage/sorter.js +0 -196
- package/coverage/src/data-transact.ts.html +0 -589
- package/coverage/src/data.ts.html +0 -94
- package/coverage/src/factory.ts.html +0 -205
- package/coverage/src/index.html +0 -176
- package/coverage/src/index.ts.html +0 -106
- package/coverage/src/registry/constants.ts.html +0 -88
- package/coverage/src/registry/index.html +0 -176
- package/coverage/src/registry/index.ts.html +0 -94
- package/coverage/src/registry/props.ts.html +0 -112
- package/coverage/src/registry/scene-tree.ts.html +0 -115
- package/coverage/src/registry/selection.ts.html +0 -124
- package/coverage/src/subscribes.ts.html +0 -178
- package/dist/__tests__/factory.test.d.ts +0 -2
- package/dist/__tests__/factory.test.d.ts.map +0 -1
- package/dist/__tests__/factory.test.js +0 -44
- package/dist/__tests__/factory.test.js.map +0 -1
- package/dist/data.d.ts +0 -4
- package/dist/data.d.ts.map +0 -1
- package/dist/data.js +0 -4
- package/dist/data.js.map +0 -1
- package/dist/registry/constants.d.ts +0 -2
- package/dist/registry/constants.d.ts.map +0 -1
- package/dist/registry/constants.js +0 -2
- package/dist/registry/constants.js.map +0 -1
- package/dist/registry/index.d.ts +0 -4
- package/dist/registry/index.d.ts.map +0 -1
- package/dist/registry/index.js +0 -4
- package/dist/registry/index.js.map +0 -1
- package/dist/registry/props.d.ts +0 -5
- package/dist/registry/props.d.ts.map +0 -1
- package/dist/registry/props.js +0 -8
- package/dist/registry/props.js.map +0 -1
- package/dist/registry/scene-tree.d.ts +0 -5
- package/dist/registry/scene-tree.d.ts.map +0 -1
- package/dist/registry/scene-tree.js +0 -8
- package/dist/registry/scene-tree.js.map +0 -1
- package/dist/registry/selection.d.ts +0 -5
- package/dist/registry/selection.d.ts.map +0 -1
- package/dist/registry/selection.js +0 -8
- package/dist/registry/selection.js.map +0 -1
- package/src/__tests__/factory.test.ts +0 -54
- package/src/data-transact.ts +0 -168
- package/src/data.ts +0 -3
- package/src/factory.ts +0 -40
- package/src/index.ts +0 -7
- package/src/registry/constants.ts +0 -1
- package/src/registry/index.ts +0 -3
- package/src/registry/props.ts +0 -9
- package/src/registry/scene-tree.ts +0 -10
- package/src/registry/selection.ts +0 -13
- package/src/subscribes.ts +0 -31
- package/tsconfig.json +0 -17
package/src/data-transact.ts
DELETED
|
@@ -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
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 +0,0 @@
|
|
|
1
|
-
export const UNDO_CAPTURE_TIMEOUT = 0
|
package/src/registry/index.ts
DELETED
package/src/registry/props.ts
DELETED
|
@@ -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
|
-
}
|