rhine-var 0.1.7 → 0.3.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.
- package/README.md +106 -16
- package/README_zh.md +126 -0
- package/dist/core/class/array/RhineArray.d.ts +2 -1
- package/dist/core/class/array/RhineArray.d.ts.map +1 -1
- package/dist/core/class/array/RhineArray.js +1 -1
- package/dist/core/class/array/RhineVarArray.d.ts +4 -0
- package/dist/core/class/array/RhineVarArray.d.ts.map +1 -0
- package/dist/core/class/array/RhineVarArray.js +5 -0
- package/dist/core/connector/WebsocketRhineConnector.d.ts +1 -0
- package/dist/core/connector/WebsocketRhineConnector.d.ts.map +1 -1
- package/dist/core/connector/WebsocketRhineConnector.js +11 -5
- package/dist/core/event/Callback.d.ts +1 -1
- package/dist/core/event/Callback.d.ts.map +1 -1
- package/dist/core/event/ChangeType.d.ts +2 -1
- package/dist/core/event/ChangeType.d.ts.map +1 -1
- package/dist/core/event/ChangeType.js +1 -0
- package/dist/core/native/NativeUtils.d.ts +5 -4
- package/dist/core/native/NativeUtils.d.ts.map +1 -1
- package/dist/core/native/NativeUtils.js +38 -2
- package/dist/core/proxy/DirectKey.d.ts +5 -0
- package/dist/core/proxy/DirectKey.d.ts.map +1 -0
- package/dist/core/proxy/DirectKey.js +30 -0
- package/dist/core/proxy/DirectPackage.d.ts +3 -5
- package/dist/core/proxy/DirectPackage.d.ts.map +1 -1
- package/dist/core/proxy/DirectPackage.js +8 -8
- package/dist/core/proxy/KeyWithDirectFlag.d.ts +8 -0
- package/dist/core/proxy/KeyWithDirectFlag.d.ts.map +1 -0
- package/dist/core/proxy/KeyWithDirectFlag.js +12 -0
- package/dist/core/proxy/ProxiedRhineVar.d.ts +3 -2
- package/dist/core/proxy/ProxiedRhineVar.d.ts.map +1 -1
- package/dist/core/proxy/Proxy.d.ts +3 -1
- package/dist/core/proxy/Proxy.d.ts.map +1 -1
- package/dist/core/proxy/Proxy.js +41 -33
- package/dist/core/proxy/RhineVar.d.ts +16 -11
- package/dist/core/proxy/RhineVar.d.ts.map +1 -1
- package/dist/core/proxy/RhineVar.js +30 -4
- package/dist/core/utils/ConvertProperty.d.ts +18 -1
- package/dist/core/utils/ConvertProperty.d.ts.map +1 -1
- package/dist/core/utils/ConvertProperty.js +288 -28
- package/dist/core/utils/DataUtils.d.ts +5 -2
- package/dist/core/utils/DataUtils.d.ts.map +1 -1
- package/dist/core/utils/DataUtils.js +11 -1
- package/dist/index.d.ts +2 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -3
- package/package.json +2 -3
package/README.md
CHANGED
|
@@ -1,46 +1,136 @@
|
|
|
1
|
+
<div align="center">
|
|
1
2
|
|
|
2
|
-
#
|
|
3
|
+
# RHINE-VAR: Simplest and Most Powerful Collaborative Framework
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
Rhine Variable — A self-synchronizing variable for collaboration.
|
|
6
|
+
Developing collaborative applications has never been this easy.
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
[English](README.md) | [中文](README_zh.md)
|
|
10
|
+
|
|
11
|
+
<img src='./assets/images/example1.png' style="border-radius: 10px; max-width: 840px"/>
|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
## Why Choose RHINE-VAR ?
|
|
17
|
+
|
|
18
|
+
#### Concise and Efficient Syntax Design
|
|
19
|
+
RhineVar draws inspiration from the design philosophy of the Valtio state management library, significantly reducing the learning curve. Developers can easily manage collaborative data as if they were manipulating regular variables.
|
|
20
|
+
|
|
21
|
+
#### Comprehensive Type Support
|
|
22
|
+
RhineVar offers full type hints and checks, ensuring precise code completion and static analysis during development. This not only improves the development experience but also reduces potential errors, making it especially suitable for TypeScript projects, enhancing code safety and reliability.
|
|
23
|
+
|
|
24
|
+
#### Distributed Real-time Collaboration Algorithm
|
|
25
|
+
The underlying collaboration algorithm of RhineVar is powered by the robust Yjs library. Using the CRDT (Conflict-free Replicated Data Type) algorithm, it ensures eventual consistency even in multi-user and offline environments.
|
|
26
|
+
|
|
27
|
+
#### High Performance with Low Bandwidth Requirements
|
|
28
|
+
The data synchronization and conflict resolution mechanism is highly efficient. Leveraging Yjs's incremental update mechanism, only necessary data changes are transmitted rather than the entire document, making it ideal for bandwidth-constrained environments and reducing unnecessary data transfers.
|
|
29
|
+
|
|
30
|
+
#### Strong Offline Support
|
|
31
|
+
Users can continue to work even while offline. Once reconnected, all changes are automatically synchronized, ensuring no data is lost or conflicted. This is crucial for building offline-first applications.
|
|
32
|
+
|
|
33
|
+
#### Cross-platform and Framework Agnostic
|
|
34
|
+
RhineVar can be used in various environments, including browsers, Node.js, and other JavaScript platforms. It integrates with multiple frontend frameworks and libraries such as Next.js, React, Vue.js, ProseMirror, and more.
|
|
35
|
+
|
|
36
|
+
#### Lightweight and Extensible
|
|
37
|
+
RhineVar is a highly lightweight library, with its core package only a few KB in size, making it suitable for various frontend applications. Its modular architecture supports feature extensions, allowing developers to import or develop custom modules as needed.
|
|
38
|
+
|
|
39
|
+
#### Decentralized Architecture
|
|
40
|
+
With a decentralized architecture, collaborative editing becomes more scalable, efficient, and fault-tolerant. Peer-to-peer data transfer is supported without relying on a central server (currently under development).
|
|
41
|
+
|
|
42
|
+
#### Native Yjs Support
|
|
43
|
+
RhineVar offers full support for native Yjs object operations, providing lower-level, richer API support. Direct operations on Yjs objects automatically trigger updates in RhineVar.
|
|
44
|
+
|
|
45
|
+
#### More Friendly and Complete Event System
|
|
46
|
+
RhineVar offers an extensive event subscription and listening system with intuitive data change events. It also supports deep data change monitoring within objects, catering to a wide range of use cases.
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
## Contact Us
|
|
51
|
+
Welcome to join our WeChat group for communication. We look forward to having more community members participate in the creation of rhine-var.
|
|
52
|
+
|
|
53
|
+
WeChat: [FNA-04]()
|
|
54
|
+
|
|
55
|
+
Email: [RhineAILab@gmail.com](rhineailab@gmail.com) & [RhineAI@163.com](RhineAI@163.com)
|
|
56
|
+
|
|
57
|
+
<br/>
|
|
5
58
|
|
|
6
59
|
## Install
|
|
7
60
|
```bash
|
|
8
|
-
npm i rhine-var
|
|
9
|
-
```
|
|
10
|
-
Or with yarn:
|
|
11
|
-
```bash
|
|
12
61
|
yarn add rhine-var
|
|
13
62
|
```
|
|
63
|
+
If you don't have `yarn`, you can install it via `npm i rhine-var`, or install `yarn` first using `npm i -g yarn` and then use the command above to install.
|
|
14
64
|
|
|
15
65
|
## Usage
|
|
16
66
|
|
|
17
|
-
|
|
18
67
|
```typescript jsx
|
|
19
68
|
const defaultValue = {value: 0}
|
|
20
|
-
const count = rhineProxy(defaultValue, '
|
|
21
|
-
|
|
22
|
-
function EasyCounter() {
|
|
69
|
+
const count = rhineProxy(defaultValue, 'localhost:6600/room-0')
|
|
23
70
|
|
|
71
|
+
function Counter() {
|
|
72
|
+
|
|
24
73
|
const countSnap = useRhine(count)
|
|
25
|
-
|
|
26
|
-
return <div
|
|
74
|
+
|
|
75
|
+
return <div>
|
|
27
76
|
<button onClick={() => count.value-- }> - 1 </button>
|
|
28
77
|
<span>{countSnap.value}</span>
|
|
29
78
|
<button onClick={() => count.value++ }> + 1 </button>
|
|
30
79
|
</div>
|
|
31
80
|
}
|
|
32
81
|
```
|
|
82
|
+
#### Default Value
|
|
83
|
+
|
|
84
|
+
When the room does not exist on the server, a default value will be used to create the room. If not connected to the server, data from the default value will also be returned.
|
|
85
|
+
|
|
86
|
+
#### Room ID
|
|
87
|
+
|
|
88
|
+
The `Same Room ID` manages the `Same State Variables`, and users who join will experience real-time multi-user collaboration.
|
|
89
|
+
|
|
90
|
+
### rhineProxy
|
|
91
|
+
|
|
92
|
+
Create a `RhineVariable` that anyone in the room can directly modify, and the value will be synchronized to everyone almost simultaneously.
|
|
93
|
+
|
|
94
|
+
Its value is `at least an object` in javascript, `but` there is almost no upper limit. It can be an `extremely complex and large JSON structure` to accommodate all the data for a large project.
|
|
95
|
+
|
|
96
|
+
### useRhine
|
|
97
|
+
|
|
98
|
+
A hook for use with React. It creates a snapshot of a `RhineVariable`, and whenever someone modifies this value, the information will be `updated on everyone's screen` in real-time.
|
|
99
|
+
|
|
100
|
+
Use snapshot only when data needs to be displayed on the React page. For other operations, such as modifying values, please use RhineVariable itself.
|
|
33
101
|
|
|
34
102
|
<br/>
|
|
35
103
|
|
|
36
|
-
##
|
|
104
|
+
## Server
|
|
105
|
+
We provide a simple server as a reference, located at `/test/server` in this project. The server is fully compatible with all Yjs websocket servers.
|
|
106
|
+
```
|
|
107
|
+
git clone https://github.com/RhineAI-Lab/rhine-var.git
|
|
108
|
+
cd test/server
|
|
109
|
+
yarn install
|
|
110
|
+
yarn start
|
|
111
|
+
```
|
|
112
|
+
It will run on `Port 6600`, and you can connect to it via `ws://localhost:6600/<room-id>`. `<room-id>` can be any text, with each room ID corresponding to a `RhineVariable`.
|
|
37
113
|
|
|
38
|
-
|
|
114
|
+
More information about server develop: [https://docs.yjs.dev/ecosystem/connection-provider/y-websocket](https://docs.yjs.dev/ecosystem/connection-provider/y-websocket)
|
|
115
|
+
|
|
116
|
+
<br/>
|
|
117
|
+
|
|
118
|
+
## Develop
|
|
39
119
|
|
|
40
120
|
```bash
|
|
41
|
-
|
|
121
|
+
# start watch and build by typescript
|
|
122
|
+
yarn run watch
|
|
123
|
+
|
|
124
|
+
# start a easy websocket server
|
|
125
|
+
cd test/server
|
|
126
|
+
yarn install
|
|
127
|
+
yarn start
|
|
128
|
+
|
|
129
|
+
# start a nextjs playground for develop debug
|
|
42
130
|
cd test/debug/next-app
|
|
43
|
-
|
|
131
|
+
yarn install
|
|
132
|
+
yarn start
|
|
133
|
+
# Open http://localhost:3000 in browser
|
|
44
134
|
```
|
|
45
135
|
|
|
46
136
|
<br/>
|
package/README_zh.md
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 最简单且强大的多人协同框架 RHINE-VAR
|
|
4
|
+
|
|
5
|
+
莱茵变量 —— 会自己与他人协同的变量 多人协同应用开发从未如此简单
|
|
6
|
+
|
|
7
|
+
[English](README.md) | [中文](README_zh.md)
|
|
8
|
+
|
|
9
|
+
<img src='./assets/images/example1.png' style="border-radius: 10px; max-width: 840px"/>
|
|
10
|
+
|
|
11
|
+
</div>
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
## 为什么选择 RHINE-VAR ?
|
|
15
|
+
|
|
16
|
+
**简洁高效的语法设计:** RhineVar 借鉴了 Valtio 状态管理库的设计理念,极大地降低了学习成本。开发者可以像操作普通变量一样轻松操控协同数据。
|
|
17
|
+
|
|
18
|
+
**完备的类型支持:** RhineVar 提供全面的类型提示和类型检查,确保在开发过程中能够获得精确的代码补全和静态分析。这不仅改善了开发体验,还有效降低了潜在的错误风险,特别适用于 TypeScript 项目,提升了代码的安全性和可靠性。
|
|
19
|
+
|
|
20
|
+
**分布式实时协作算法:** RhineVar 的底层协同算法基于强大的 Yjs 库。通过 CRDT (Conflict-free Replicated Data Type,无冲突复制数据类型) 算法,确保多用户同时使用,甚至离线下使用的最终一致性。
|
|
21
|
+
|
|
22
|
+
**高性能和低带宽需求:** 数据同步和冲突解决机制非常高效,通过 Yjs 的增量更新机制,仅传输必要的数据更改,而非整个文档。这使得它在网络带宽受限的环境中表现良好,减少了不必要的数据传输。
|
|
23
|
+
|
|
24
|
+
**强大的离线支持:** 即使在离线状态下,用户仍然可以继续使用应用。当重新联机时,所有更改将自动同步,确保数据不会出现丢失或冲突。这对于构建离线优先的应用至关重要。
|
|
25
|
+
|
|
26
|
+
**跨平台和框架无关:** RhineVar 支持在多种环境中使用,包括浏览器、Node.js 和其他 JavaScript 环境。此外,它可以与多个前端框架和库 (如 NextJs、React、Vue.js、ProseMirror 等) 集成。
|
|
27
|
+
|
|
28
|
+
**轻量级且可扩展:** RhineVar 是一个非常轻量的库,核心包仅几 KB,适合各种前端应用。其模块化架构也支持扩展特性,开发者可以根据需要引入或开发自定义模块。
|
|
29
|
+
|
|
30
|
+
**去中心化架构:** 通过去中心化架构,使得协作编辑更具扩展性、更高效且更具容错能力。可通过 P2P 进行数据传输,无需依赖中央服务器(开发中)。
|
|
31
|
+
|
|
32
|
+
**原生Yjs支持:** RhineVar 提供完好的Yjs原生对象操作支持,更底层更丰富的API支持。直接对Yjs的对象进行操作,也将自动触发 RhineVar 的更新。
|
|
33
|
+
|
|
34
|
+
**更友好且完善的事件体系:** RhineVar 提供了丰富的事件订阅监听方式,直观的数据变更事件,更好的支持数据变更的监听和处理。以及提供了对内部深层数据变化的监听,以适用更多场景。
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
## Contact Us
|
|
38
|
+
|
|
39
|
+
欢迎加入我们的微信群一起讨论交流,我们期待更多的社区成员能加入到 RHINE-VAR 的创造中来!
|
|
40
|
+
|
|
41
|
+
微信: [FNA-04]() (请备注来源)
|
|
42
|
+
|
|
43
|
+
邮箱: [RhineAILab@gmail.com](rhineailab@gmail.com) & [RhineAI@163.com](RhineAI@163.com)
|
|
44
|
+
|
|
45
|
+
<br/>
|
|
46
|
+
|
|
47
|
+
## Install
|
|
48
|
+
```bash
|
|
49
|
+
yarn add rhine-var
|
|
50
|
+
```
|
|
51
|
+
如果你的电脑未安装`yarn`, 也可通过 `npm i rhine-var` 安装。或先用 `npm i -g yarn` 安装`yarn`,然后再用上方命令进行安装。
|
|
52
|
+
|
|
53
|
+
## Usage
|
|
54
|
+
|
|
55
|
+
```typescript jsx
|
|
56
|
+
const defaultValue = {value: 0}
|
|
57
|
+
const count = rhineProxy(defaultValue, 'localhost:6600/room-0')
|
|
58
|
+
|
|
59
|
+
function Counter() {
|
|
60
|
+
|
|
61
|
+
const countSnap = useRhine(count)
|
|
62
|
+
|
|
63
|
+
return <div>
|
|
64
|
+
<button onClick={() => count.value-- }> - 1 </button>
|
|
65
|
+
<span>{countSnap.value}</span>
|
|
66
|
+
<button onClick={() => count.value++ }> + 1 </button>
|
|
67
|
+
</div>
|
|
68
|
+
}
|
|
69
|
+
```
|
|
70
|
+
#### Default Value
|
|
71
|
+
|
|
72
|
+
当服务端无信息时,将使用 DefaultValue 作为默认内容。未连接到服务器时,也将根据默认值进行返回。
|
|
73
|
+
|
|
74
|
+
#### Room ID
|
|
75
|
+
|
|
76
|
+
一个房间号对应一个状态变量, 加入到一个房间中的用户会参与到多人协同中。
|
|
77
|
+
|
|
78
|
+
### rhineProxy
|
|
79
|
+
|
|
80
|
+
用于创建一个 `RhineVariable` 他的值会和房间中的其他人共享并同步。
|
|
81
|
+
|
|
82
|
+
你可以像操作 JavaScript 中的普通变量一样直接随意操作他。
|
|
83
|
+
|
|
84
|
+
值的类型至少是 JavaScript 中的 object,但没有上限。它可以是一个非常复杂和庞大的 JSON 结构,以容纳大型项目的所有数据。
|
|
85
|
+
|
|
86
|
+
### useRhine
|
|
87
|
+
|
|
88
|
+
一个 `React` 的 `Hook` 函数. 他将为 `RhineVariable` 创建一个快照, 用于自动热重载更新页面。当任何人对值做出修改时,他会把最新的值立刻更新到所有人的屏幕上。
|
|
89
|
+
|
|
90
|
+
只有页面需要数据的时候使用 `useRhine` 创造的快照。在其他操作,例如赋值时,请操作原来的 `RhineVariable`。
|
|
91
|
+
|
|
92
|
+
<br/>
|
|
93
|
+
|
|
94
|
+
## Server
|
|
95
|
+
我们提供了一个简单的服务器例子,位于本项目中的 `/test/server` 处。 服务端完全兼容所有的 Yjs 的 Websocket 服务器,将来会支持更多。
|
|
96
|
+
```
|
|
97
|
+
git clone https://github.com/RhineAI-Lab/rhine-var.git
|
|
98
|
+
cd test/server
|
|
99
|
+
yarn install
|
|
100
|
+
yarn start
|
|
101
|
+
```
|
|
102
|
+
默认运行在 `端口 6600`, 你可以通过连接 `ws://localhost:6600/<room-id>` 连接他,`<room-id>` 可以是任意文本,一个房间号对应一个 `RhineVariable`。
|
|
103
|
+
|
|
104
|
+
更多服务端开发信息请参考: [https://docs.yjs.dev/ecosystem/connection-provider/y-websocket](https://docs.yjs.dev/ecosystem/connection-provider/y-websocket)
|
|
105
|
+
|
|
106
|
+
<br/>
|
|
107
|
+
|
|
108
|
+
## Develop
|
|
109
|
+
|
|
110
|
+
```bash
|
|
111
|
+
# 开始 typescript 自动构建更新
|
|
112
|
+
yarn run watch
|
|
113
|
+
|
|
114
|
+
# 开启临时服务端
|
|
115
|
+
cd test/server
|
|
116
|
+
yarn install
|
|
117
|
+
yarn start
|
|
118
|
+
|
|
119
|
+
# 开始 NextJS 的热环境调试测试项目
|
|
120
|
+
cd test/debug/next-app
|
|
121
|
+
yarn install
|
|
122
|
+
yarn start
|
|
123
|
+
# 浏览器访问 http://localhost:3000
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
<br/>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RhineArray.d.ts","sourceRoot":"","sources":["../../../../src/core/class/array/RhineArray.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"RhineArray.d.ts","sourceRoot":"","sources":["../../../../src/core/class/array/RhineArray.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,6BAA8B;AAE7C,MAAM,CAAC,OAAO,OAAO,UAAU,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;CAElE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RhineVarArray.d.ts","sourceRoot":"","sources":["../../../../src/core/class/array/RhineVarArray.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,6BAA8B;AAE7C,MAAM,CAAC,OAAO,OAAO,aAAa,CAAC,CAAC,CAAE,SAAQ,KAAK,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC;CAErE"}
|
|
@@ -16,6 +16,7 @@ export default class WebsocketRhineConnector {
|
|
|
16
16
|
addSyncedListener(listener: SyncedListener): void;
|
|
17
17
|
removeSyncedListener(listener: SyncedListener): void;
|
|
18
18
|
emitSynced(synced: boolean): void;
|
|
19
|
+
afterSynced(callback: () => void): void;
|
|
19
20
|
waitSynced(): Promise<void>;
|
|
20
21
|
constructor(url?: string);
|
|
21
22
|
bind(defaultValue: Native, overwrite?: boolean): any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WebsocketRhineConnector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/WebsocketRhineConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,IAAI,IAAI,EAAmB,GAAG,IAAI,IAAI,EAAC,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,0BAAyC;AAEjE,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAE5C,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAEtD,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAE1C,MAAM,CAAC,SAAS,SAAU;IAE1B,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACnB,GAAG,EAAE,MAAM,CAAK;IAEhB,QAAQ,SAAK;IACb,MAAM,UAAQ;IAEd,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAO;IACzC,eAAe,EAAE,eAAe,CAA+B;IAG/D,eAAe,EAAE,cAAc,EAAE,CAAK;IACtC,iBAAiB,CAAC,QAAQ,EAAE,cAAc;IAG1C,oBAAoB,CAAC,QAAQ,EAAE,cAAc;IAG7C,UAAU,CAAC,MAAM,EAAE,OAAO;IAI1B,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"WebsocketRhineConnector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/WebsocketRhineConnector.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,GAAG,IAAI,IAAI,EAAmB,GAAG,IAAI,IAAI,EAAC,MAAM,KAAK,CAAC;AAC9D,OAAO,EAAC,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAC9C,OAAO,EAAC,eAAe,EAAC,0BAAyC;AAEjE,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAE5C,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,CAAA;AAEtD,MAAM,CAAC,OAAO,OAAO,uBAAuB;IAE1C,MAAM,CAAC,SAAS,SAAU;IAE1B,IAAI,EAAE,IAAI,CAAA;IACV,QAAQ,EAAE,IAAI,CAAC,GAAG,CAAC,CAAA;IACnB,GAAG,EAAE,MAAM,CAAK;IAEhB,QAAQ,SAAK;IACb,MAAM,UAAQ;IAEd,QAAQ,EAAE,iBAAiB,GAAG,IAAI,CAAO;IACzC,eAAe,EAAE,eAAe,CAA+B;IAG/D,eAAe,EAAE,cAAc,EAAE,CAAK;IACtC,iBAAiB,CAAC,QAAQ,EAAE,cAAc;IAG1C,oBAAoB,CAAC,QAAQ,EAAE,cAAc;IAG7C,UAAU,CAAC,MAAM,EAAE,OAAO;IAI1B,WAAW,CAAC,QAAQ,EAAE,MAAM,IAAI;IAahC,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;gBAOf,GAAG,SAAK;IAMpB,IAAI,CAAC,YAAY,EAAE,MAAM,EAAE,SAAS,GAAE,OAAe;IAc/C,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;CA4C1C;AAGD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,MAAM,2BAMhD"}
|
|
@@ -15,17 +15,23 @@ class WebsocketRhineConnector {
|
|
|
15
15
|
emitSynced(synced) {
|
|
16
16
|
this.syncedListeners.forEach(listener => listener(synced));
|
|
17
17
|
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
18
|
+
afterSynced(callback) {
|
|
19
|
+
if (this.synced) {
|
|
20
|
+
callback();
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
22
23
|
const listener = (synced) => {
|
|
23
24
|
if (synced) {
|
|
24
25
|
this.removeSyncedListener(listener);
|
|
25
|
-
|
|
26
|
+
callback();
|
|
26
27
|
}
|
|
27
28
|
};
|
|
28
29
|
this.addSyncedListener(listener);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
waitSynced() {
|
|
33
|
+
return new Promise((resolve) => {
|
|
34
|
+
this.afterSynced(resolve);
|
|
29
35
|
});
|
|
30
36
|
}
|
|
31
37
|
constructor(url = '') {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import { ChangeType } from "./ChangeType";
|
|
2
2
|
import { Transaction, YArrayEvent, YMapEvent } from "yjs";
|
|
3
|
-
export type Callback = (value:
|
|
3
|
+
export type Callback<T> = (value: T[keyof T], key: keyof T, oldValue: T[keyof T], type: ChangeType, nativeEvent: YMapEvent<any> | YArrayEvent<any>, nativeTransaction: Transaction) => void;
|
|
4
4
|
//# sourceMappingURL=Callback.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Callback.d.ts","sourceRoot":"","sources":["../../../src/core/event/Callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,qBAAgC;AACnD,OAAO,EAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,KAAK,CAAC;
|
|
1
|
+
{"version":3,"file":"Callback.d.ts","sourceRoot":"","sources":["../../../src/core/event/Callback.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAC,qBAAgC;AACnD,OAAO,EAAC,WAAW,EAAE,WAAW,EAAE,SAAS,EAAC,MAAM,KAAK,CAAC;AAGxD,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CACxB,KAAK,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EACjB,GAAG,EAAE,MAAM,CAAC,EACZ,QAAQ,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EACpB,IAAI,EAAE,UAAU,EAChB,WAAW,EAAE,SAAS,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAC9C,iBAAiB,EAAE,WAAW,KAC3B,IAAI,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChangeType.d.ts","sourceRoot":"","sources":["../../../src/core/event/ChangeType.ts"],"names":[],"mappings":"AACA,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;
|
|
1
|
+
{"version":3,"file":"ChangeType.d.ts","sourceRoot":"","sources":["../../../src/core/event/ChangeType.ts"],"names":[],"mappings":"AACA,oBAAY,UAAU;IACpB,GAAG,QAAQ;IACX,MAAM,WAAW;IACjB,MAAM,WAAW;IACjB,IAAI,SAAS;CACd"}
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { Map as YMap, Array as YArray } from "yjs";
|
|
2
1
|
import { Native } from "./Native";
|
|
3
|
-
export declare function
|
|
2
|
+
export declare function isNative(value: any): boolean;
|
|
4
3
|
export declare function nativeSet(target: Native, key: string | symbol, value: any): boolean;
|
|
4
|
+
export declare function nativeHas(target: Native, key: string | symbol): boolean;
|
|
5
|
+
export declare function nativeOwnKeys(target: Native): string[];
|
|
5
6
|
export declare function nativeDelete(target: Native, key: string | symbol): boolean;
|
|
6
|
-
export declare function nativeGet(target: Native, key: string | symbol): any;
|
|
7
|
-
export declare function jsonToNative(data: any): any;
|
|
7
|
+
export declare function nativeGet(target: Native, key: string | symbol): any | undefined;
|
|
8
|
+
export declare function jsonToNative(data: any): Native | any;
|
|
8
9
|
//# sourceMappingURL=NativeUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeUtils.d.ts","sourceRoot":"","sources":["../../../src/core/native/NativeUtils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"NativeUtils.d.ts","sourceRoot":"","sources":["../../../src/core/native/NativeUtils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAC,iBAA6B;AAI5C,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAE5C;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CAuBnF;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAkBvE;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAYtD;AAED,wBAAgB,YAAY,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,OAAO,CAwB1E;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,GAAG,GAAG,SAAS,CAgB/E;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,GAAG,GAAG,MAAM,GAAG,GAAG,CAgBpD"}
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.isNative = isNative;
|
|
4
4
|
exports.nativeSet = nativeSet;
|
|
5
|
+
exports.nativeHas = nativeHas;
|
|
6
|
+
exports.nativeOwnKeys = nativeOwnKeys;
|
|
5
7
|
exports.nativeDelete = nativeDelete;
|
|
6
8
|
exports.nativeGet = nativeGet;
|
|
7
9
|
exports.jsonToNative = jsonToNative;
|
|
8
10
|
const yjs_1 = require("yjs");
|
|
9
11
|
const DataUtils_1 = require("../utils/DataUtils");
|
|
10
|
-
function
|
|
12
|
+
function isNative(value) {
|
|
11
13
|
return (value instanceof yjs_1.Map) || (value instanceof yjs_1.Array);
|
|
12
14
|
}
|
|
13
15
|
function nativeSet(target, key, value) {
|
|
@@ -35,6 +37,40 @@ function nativeSet(target, key, value) {
|
|
|
35
37
|
}
|
|
36
38
|
return false;
|
|
37
39
|
}
|
|
40
|
+
function nativeHas(target, key) {
|
|
41
|
+
if (typeof key !== 'string') {
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
try {
|
|
45
|
+
if (target instanceof yjs_1.Map) {
|
|
46
|
+
return target.has(key);
|
|
47
|
+
}
|
|
48
|
+
else if (target instanceof yjs_1.Array) {
|
|
49
|
+
const index = parseInt(key);
|
|
50
|
+
if (!isNaN(index)) {
|
|
51
|
+
return index < target.length && index >= 0;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
catch (e) {
|
|
56
|
+
console.error('RhineVar nativeHas.error:', e);
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
}
|
|
60
|
+
function nativeOwnKeys(target) {
|
|
61
|
+
let keys = [];
|
|
62
|
+
if (target instanceof yjs_1.Map) {
|
|
63
|
+
target.forEach((value, key) => {
|
|
64
|
+
keys.push(key);
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else if (target instanceof yjs_1.Array) {
|
|
68
|
+
for (let i = 0; i < target.length; i++) {
|
|
69
|
+
keys.push(String(i));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return keys;
|
|
73
|
+
}
|
|
38
74
|
function nativeDelete(target, key) {
|
|
39
75
|
if (typeof key !== 'string') {
|
|
40
76
|
return false;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const DIRECT_KEY_PREVIOUS = "RHINE_VAR_DIRECT_PACKAGE_PREFIX_";
|
|
2
|
+
export declare function directKey(key: string | number): string;
|
|
3
|
+
export declare function isDirectKey(key: string | any): boolean;
|
|
4
|
+
export declare function originKey(key: string | symbol | number): string | symbol | number;
|
|
5
|
+
//# sourceMappingURL=DirectKey.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DirectKey.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/DirectKey.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,qCAAqC,CAAA;AAErE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,UAE7C;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,WAE5C;AAED,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAajF"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DIRECT_KEY_PREVIOUS = void 0;
|
|
4
|
+
exports.directKey = directKey;
|
|
5
|
+
exports.isDirectKey = isDirectKey;
|
|
6
|
+
exports.originKey = originKey;
|
|
7
|
+
exports.DIRECT_KEY_PREVIOUS = 'RHINE_VAR_DIRECT_PACKAGE_PREFIX_';
|
|
8
|
+
function directKey(key) {
|
|
9
|
+
return exports.DIRECT_KEY_PREVIOUS + key;
|
|
10
|
+
}
|
|
11
|
+
function isDirectKey(key) {
|
|
12
|
+
return typeof key === 'string' && key.startsWith(exports.DIRECT_KEY_PREVIOUS);
|
|
13
|
+
}
|
|
14
|
+
function originKey(key) {
|
|
15
|
+
if (typeof key === 'number')
|
|
16
|
+
key = String(key);
|
|
17
|
+
if (typeof key !== 'string')
|
|
18
|
+
return key;
|
|
19
|
+
if (key.startsWith(exports.DIRECT_KEY_PREVIOUS)) {
|
|
20
|
+
key = key.split(exports.DIRECT_KEY_PREVIOUS)[1];
|
|
21
|
+
let kn = parseInt(key);
|
|
22
|
+
if (isNaN(kn)) {
|
|
23
|
+
return key;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
return kn;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return key;
|
|
30
|
+
}
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
}
|
|
5
|
-
export declare function directPackage(data: any): DirectPackage;
|
|
1
|
+
export declare const DIRECT_KEY_PREVIOUS = "RHINE_VAR_DIRECT_PACKAGE_PREFIX - ";
|
|
2
|
+
export declare function directKey(key: string): string;
|
|
3
|
+
export declare function isDirectKey(key: string): boolean;
|
|
6
4
|
//# sourceMappingURL=DirectPackage.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DirectPackage.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/DirectPackage.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"DirectPackage.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/DirectPackage.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,mBAAmB,uCAAuC,CAAA;AAEvE,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,UAEpC;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,WAEtC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
3
|
+
exports.DIRECT_KEY_PREVIOUS = void 0;
|
|
4
|
+
exports.directKey = directKey;
|
|
5
|
+
exports.isDirectKey = isDirectKey;
|
|
6
|
+
exports.DIRECT_KEY_PREVIOUS = 'RHINE_VAR_DIRECT_PACKAGE_PREFIX - ';
|
|
7
|
+
function directKey(key) {
|
|
8
|
+
return exports.DIRECT_KEY_PREVIOUS + key;
|
|
8
9
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return new DirectPackage(data);
|
|
10
|
+
function isDirectKey(key) {
|
|
11
|
+
return key.startsWith(exports.DIRECT_KEY_PREVIOUS);
|
|
12
12
|
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
type keyType = string | symbol | number;
|
|
2
|
+
export default class KeyWithDirectFlag {
|
|
3
|
+
value: keyType;
|
|
4
|
+
constructor(value: keyType);
|
|
5
|
+
}
|
|
6
|
+
export declare function directKey(value: keyType): KeyWithDirectFlag;
|
|
7
|
+
export {};
|
|
8
|
+
//# sourceMappingURL=KeyWithDirectFlag.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KeyWithDirectFlag.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/KeyWithDirectFlag.ts"],"names":[],"mappings":"AACA,KAAK,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,CAAA;AAEvC,MAAM,CAAC,OAAO,OAAO,iBAAiB;IAE3B,KAAK,EAAE,OAAO;gBAAd,KAAK,EAAE,OAAO;CAExB;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,OAAO,qBAEvC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.directKey = directKey;
|
|
4
|
+
class KeyWithDirectFlag {
|
|
5
|
+
constructor(value) {
|
|
6
|
+
this.value = value;
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
exports.default = KeyWithDirectFlag;
|
|
10
|
+
function directKey(value) {
|
|
11
|
+
return new KeyWithDirectFlag(value);
|
|
12
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import RhineVar from "./RhineVar";
|
|
2
2
|
export type RecursiveCrossRhineVar<T> = {
|
|
3
|
-
[K in keyof T]: T[K] extends object ? RecursiveCrossRhineVar<T[K]> & RhineVar : T[K];
|
|
3
|
+
[K in keyof T]: T[K] extends object ? RecursiveCrossRhineVar<T[K]> & RhineVar<T[K]> : T[K];
|
|
4
4
|
};
|
|
5
|
-
export type
|
|
5
|
+
export type StoredRhineVar<T> = T & RecursiveCrossRhineVar<T> & RhineVar<T>;
|
|
6
|
+
export type ProxiedRhineVar<T> = StoredRhineVar<T>;
|
|
6
7
|
//# sourceMappingURL=ProxiedRhineVar.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ProxiedRhineVar.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/ProxiedRhineVar.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,mBAA8B;AAE7C,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;KACrC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,GAAG,CAAC,CAAC,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"ProxiedRhineVar.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/ProxiedRhineVar.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,mBAA8B;AAE7C,MAAM,MAAM,sBAAsB,CAAC,CAAC,IAAI;KACrC,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,SAAS,MAAM,GAAG,sBAAsB,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;CAC3F,CAAA;AAED,MAAM,MAAM,cAAc,CAAC,CAAC,IAAI,CAAC,GAAG,sBAAsB,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAA;AAE3E,MAAM,MAAM,eAAe,CAAC,CAAC,IAAI,cAAc,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import WebsocketRhineConnector from "../connector/WebsocketRhineConnector";
|
|
2
2
|
import { ProxiedRhineVar } from "./ProxiedRhineVar";
|
|
3
3
|
import { Native } from "../native/Native";
|
|
4
|
-
export declare
|
|
4
|
+
export declare const PROTOCOL_LIST: string[];
|
|
5
|
+
export declare const DEFAULT_PROTOCOL_LIST: string;
|
|
6
|
+
export declare function rhineProxy<T extends object>(data: T, connector?: WebsocketRhineConnector | string | null, overwrite?: boolean | number): ProxiedRhineVar<T>;
|
|
5
7
|
export declare function rhineProxyNative<T extends object>(target: Native): ProxiedRhineVar<T>;
|
|
6
8
|
//# sourceMappingURL=Proxy.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,uBAAgD,6CAAiD;AAKxG,OAAO,EAAC,eAAe,EAAC,0BAAqC;AAC7D,OAAO,EAAC,MAAM,EAAC,yBAA6B;
|
|
1
|
+
{"version":3,"file":"Proxy.d.ts","sourceRoot":"","sources":["../../../src/core/proxy/Proxy.ts"],"names":[],"mappings":"AACA,OAAO,uBAAgD,6CAAiD;AAKxG,OAAO,EAAC,eAAe,EAAC,0BAAqC;AAC7D,OAAO,EAAC,MAAM,EAAC,yBAA6B;AAY5C,eAAO,MAAM,aAAa,UAAsB,CAAA;AAChD,eAAO,MAAM,qBAAqB,QAAmB,CAAA;AAGrD,wBAAgB,UAAU,CAAC,CAAC,SAAS,MAAM,EACzC,IAAI,EAAE,CAAC,EACP,SAAS,GAAE,uBAAuB,GAAG,MAAM,GAAG,IAAW,EACzD,SAAS,GAAE,OAAO,GAAG,MAAc,GAClC,eAAe,CAAC,CAAC,CAAC,CA6CpB;AAGD,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,eAAe,CAAC,CAAC,CAAC,CAoErF"}
|