@loro-extended/change 0.8.1 → 0.9.1

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 (41) hide show
  1. package/README.md +78 -0
  2. package/dist/index.d.ts +199 -43
  3. package/dist/index.js +642 -429
  4. package/dist/index.js.map +1 -1
  5. package/package.json +1 -1
  6. package/src/change.test.ts +277 -1
  7. package/src/conversion.test.ts +72 -72
  8. package/src/conversion.ts +5 -5
  9. package/src/discriminated-union-assignability.test.ts +45 -0
  10. package/src/discriminated-union-tojson.test.ts +128 -0
  11. package/src/index.ts +7 -0
  12. package/src/overlay-recursion.test.ts +325 -0
  13. package/src/overlay.ts +45 -8
  14. package/src/placeholder-proxy.test.ts +52 -0
  15. package/src/placeholder-proxy.ts +37 -0
  16. package/src/presence-interface.ts +52 -0
  17. package/src/shape.ts +44 -50
  18. package/src/typed-doc.ts +4 -4
  19. package/src/typed-presence.ts +96 -0
  20. package/src/{draft-nodes → typed-refs}/base.ts +14 -4
  21. package/src/{draft-nodes → typed-refs}/counter.test.ts +1 -1
  22. package/src/{draft-nodes → typed-refs}/counter.ts +9 -3
  23. package/src/{draft-nodes → typed-refs}/doc.ts +32 -25
  24. package/src/typed-refs/json-compatibility.test.ts +255 -0
  25. package/src/{draft-nodes → typed-refs}/list-base.ts +115 -42
  26. package/src/{draft-nodes → typed-refs}/list.test.ts +1 -1
  27. package/src/{draft-nodes → typed-refs}/list.ts +4 -4
  28. package/src/{draft-nodes → typed-refs}/map.ts +50 -66
  29. package/src/{draft-nodes → typed-refs}/movable-list.test.ts +1 -1
  30. package/src/{draft-nodes → typed-refs}/movable-list.ts +6 -6
  31. package/src/{draft-nodes → typed-refs}/proxy-handlers.ts +25 -26
  32. package/src/{draft-nodes → typed-refs}/record.test.ts +78 -9
  33. package/src/typed-refs/record.ts +193 -0
  34. package/src/{draft-nodes → typed-refs}/text.ts +13 -3
  35. package/src/{draft-nodes → typed-refs}/tree.ts +6 -3
  36. package/src/typed-refs/utils.ts +177 -0
  37. package/src/types.test.ts +97 -2
  38. package/src/types.ts +62 -5
  39. package/src/draft-nodes/counter.md +0 -31
  40. package/src/draft-nodes/record.ts +0 -177
  41. package/src/draft-nodes/utils.ts +0 -96
@@ -1,96 +0,0 @@
1
- import type {
2
- ContainerShape,
3
- CounterContainerShape,
4
- ListContainerShape,
5
- MapContainerShape,
6
- MovableListContainerShape,
7
- RecordContainerShape,
8
- TextContainerShape,
9
- TreeContainerShape,
10
- } from "../shape.js"
11
- import type { DraftNode, DraftNodeParams } from "./base.js"
12
- import { CounterDraftNode } from "./counter.js"
13
- import { ListDraftNode } from "./list.js"
14
- import { MapDraftNode } from "./map.js"
15
- import { MovableListDraftNode } from "./movable-list.js"
16
- import {
17
- listProxyHandler,
18
- movableListProxyHandler,
19
- recordProxyHandler,
20
- } from "./proxy-handlers.js"
21
- import { RecordDraftNode } from "./record.js"
22
- import { TextDraftNode } from "./text.js"
23
- import { TreeDraftNode } from "./tree.js"
24
-
25
- // Generic catch-all overload
26
- export function createContainerDraftNode<T extends ContainerShape>(
27
- params: DraftNodeParams<T>,
28
- ): DraftNode<T>
29
-
30
- // Implementation
31
- export function createContainerDraftNode(
32
- params: DraftNodeParams<ContainerShape>,
33
- ): DraftNode<ContainerShape> {
34
- switch (params.shape._type) {
35
- case "counter":
36
- return new CounterDraftNode(
37
- params as DraftNodeParams<CounterContainerShape>,
38
- )
39
- case "list":
40
- return new Proxy(
41
- new ListDraftNode(params as DraftNodeParams<ListContainerShape>),
42
- listProxyHandler,
43
- )
44
- case "map":
45
- return new MapDraftNode(params as DraftNodeParams<MapContainerShape>)
46
- case "movableList":
47
- return new Proxy(
48
- new MovableListDraftNode(
49
- params as DraftNodeParams<MovableListContainerShape>,
50
- ),
51
- movableListProxyHandler,
52
- )
53
- case "record":
54
- return new Proxy(
55
- new RecordDraftNode(params as DraftNodeParams<RecordContainerShape>),
56
- recordProxyHandler,
57
- )
58
- case "text":
59
- return new TextDraftNode(params as DraftNodeParams<TextContainerShape>)
60
- case "tree":
61
- return new TreeDraftNode(params as DraftNodeParams<TreeContainerShape>)
62
- default:
63
- throw new Error(
64
- `Unknown container type: ${(params.shape as ContainerShape)._type}`,
65
- )
66
- }
67
- }
68
-
69
- export function assignPlainValueToDraftNode(
70
- node: DraftNode<any>,
71
- value: any,
72
- ): boolean {
73
- const shapeType = (node as any).shape._type
74
-
75
- if (shapeType === "map" || shapeType === "record") {
76
- for (const k in value) {
77
- ;(node as any)[k] = value[k]
78
- }
79
- return true
80
- }
81
-
82
- if (shapeType === "list" || shapeType === "movableList") {
83
- if (Array.isArray(value)) {
84
- const listNode = node as any
85
- if (listNode.length > 0) {
86
- listNode.delete(0, listNode.length)
87
- }
88
- for (const item of value) {
89
- listNode.push(item)
90
- }
91
- return true
92
- }
93
- }
94
-
95
- return false
96
- }