rhine-var 0.8.23 → 0.9.2
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/dist/core/connector/create-connector.d.ts.map +1 -1
- package/dist/core/connector/create-connector.js +5 -2
- package/dist/core/connector/hocuspocus/hocuspocus-connector.class.d.ts.map +1 -1
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -5
- package/dist/react/hooks/use-rhine.hook.d.ts.map +1 -1
- package/dist/react/hooks/use-rhine.hook.js +10 -3
- package/dist/react/hooks/use-synced.hook.d.ts.map +1 -1
- package/dist/react/hooks/use-synced.hook.js +7 -3
- package/dist/react/index.d.ts +4 -0
- package/dist/react/index.d.ts.map +1 -0
- package/dist/react/index.js +10 -0
- package/dist/react/load-react.d.ts +4 -0
- package/dist/react/load-react.d.ts.map +1 -0
- package/dist/react/load-react.js +70 -0
- package/package.json +74 -71
- package/playground/general/index.mjs +19 -0
- package/playground/general/package.json +12 -0
- package/dist/core/native/native.utils.d.ts +0 -9
- package/dist/core/native/native.utils.d.ts.map +0 -1
- package/dist/core/native/native.utils.js +0 -154
- package/dist/core/proxy/items/rhine-map.d.ts +0 -5
- package/dist/core/proxy/items/rhine-map.d.ts.map +0 -1
- package/dist/core/proxy/items/rhine-map.js +0 -12
- package/dist/core/proxy/items/rhine-text.d.ts +0 -3
- package/dist/core/proxy/items/rhine-text.d.ts.map +0 -1
- package/dist/core/proxy/items/rhine-text.js +0 -7
- package/dist/core/proxy/proxy-option.d.ts +0 -3
- package/dist/core/proxy/proxy-option.d.ts.map +0 -1
- package/dist/core/proxy/proxy-option.interface.d.ts +0 -4
- package/dist/core/proxy/proxy-option.interface.d.ts.map +0 -1
- package/dist/core/proxy/proxy-option.interface.js +0 -2
- package/dist/core/proxy/proxy-option.js +0 -5
- package/dist/core/utils/convert-property.utils.d.ts +0 -21
- package/dist/core/utils/convert-property.utils.d.ts.map +0 -1
- package/dist/core/utils/convert-property.utils.js +0 -349
- package/dist/core/utils/get-path-from-root.d.ts +0 -4
- package/dist/core/utils/get-path-from-root.d.ts.map +0 -1
- package/dist/core/utils/get-path-from-root.js +0 -38
- package/dist/core/utils/get-target-by-path-from-root.d.ts +0 -3
- package/dist/core/utils/get-target-by-path-from-root.d.ts.map +0 -1
- package/dist/core/utils/get-target-by-path-from-root.js +0 -13
- package/dist/core/var/support/array/array-support.class.d.ts +0 -1
- package/dist/core/var/support/array/array-support.class.d.ts.map +0 -1
- package/dist/core/var/support/array/array-support.class.js +0 -1
- package/dist/core/var/support/array/support.array.d.ts +0 -1
- package/dist/core/var/support/array/support.array.d.ts.map +0 -1
- package/dist/core/var/support/array/support.array.js +0 -1
- package/dist/core/var/support/input-item.d.ts +0 -1
- package/dist/core/var/support/input-item.d.ts.map +0 -1
- package/dist/core/var/support/input-item.js +0 -1
- package/dist/utils/get-path-from-root.d.ts +0 -4
- package/dist/utils/get-path-from-root.d.ts.map +0 -1
- package/dist/utils/get-path-from-root.js +0 -38
- package/dist/utils/get-target-by-path-from-root.d.ts +0 -3
- package/dist/utils/get-target-by-path-from-root.d.ts.map +0 -1
- package/dist/utils/get-target-by-path-from-root.js +0 -13
- /package/playground/{next-app → next}/next.config.mjs +0 -0
- /package/playground/{next-app → next}/package.json +0 -0
- /package/playground/{next-app → next}/public/favicon.ico +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-connector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/create-connector.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,gDAA+D;AAGzF,eAAO,MAAM,aAAa,UAAsB,CAAA;AAChD,eAAO,MAAM,kBAAkB,2BAA2B,CAAA;AAE1D,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,
|
|
1
|
+
{"version":3,"file":"create-connector.d.ts","sourceRoot":"","sources":["../../../src/core/connector/create-connector.ts"],"names":[],"mappings":"AAAA,OAAO,mBAAmB,gDAA+D;AAGzF,eAAO,MAAM,aAAa,UAAsB,CAAA;AAChD,eAAO,MAAM,kBAAkB,2BAA2B,CAAA;AAE1D,wBAAgB,eAAe,CAAC,aAAa,EAAE,MAAM,GAAG,MAAM,uBAsB7D"}
|
|
@@ -9,6 +9,7 @@ const hocuspocus_connector_class_1 = __importDefault(require("./hocuspocus/hocus
|
|
|
9
9
|
exports.PROTOCOL_LIST = ['ws://', "wss://"];
|
|
10
10
|
exports.DEFAULT_PUBLIC_URL = 'wss://rvp.rhineai.com/';
|
|
11
11
|
function createConnector(connectorText) {
|
|
12
|
+
var _a;
|
|
12
13
|
let text = String(connectorText);
|
|
13
14
|
// Connector is String but not start with protocol
|
|
14
15
|
if (exports.PROTOCOL_LIST.every(protocol => !text.startsWith(protocol))) {
|
|
@@ -18,8 +19,10 @@ function createConnector(connectorText) {
|
|
|
18
19
|
// Use HocuspocusConnector by default
|
|
19
20
|
const connector = new hocuspocus_connector_class_1.default(text);
|
|
20
21
|
// const connector = new WebsocketConnector(text)
|
|
21
|
-
//
|
|
22
|
-
|
|
22
|
+
// Environment check
|
|
23
|
+
const isBrowser = typeof window !== 'undefined';
|
|
24
|
+
const isNode = typeof process !== 'undefined' && ((_a = process.versions) === null || _a === void 0 ? void 0 : _a.node);
|
|
25
|
+
if (isBrowser || isNode) {
|
|
23
26
|
connector.connect(String(text));
|
|
24
27
|
}
|
|
25
28
|
return connector;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hocuspocus-connector.class.d.ts","sourceRoot":"","sources":["../../../../src/core/connector/hocuspocus/hocuspocus-connector.class.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"hocuspocus-connector.class.d.ts","sourceRoot":"","sources":["../../../../src/core/connector/hocuspocus/hocuspocus-connector.class.ts"],"names":[],"mappings":"AAKA,OAAO,SAAS,8BAA4C;AAC5D,OAAO,EAAC,kBAAkB,EAAC,MAAM,sBAAsB,CAAC;AAExD,MAAM,CAAC,OAAO,OAAO,mBAAoB,SAAQ,SAAS;IAExD,GAAG,EAAE,MAAM,CAAK;IAChB,IAAI,EAAE,MAAM,CAAK;IAEjB,QAAQ,EAAE,kBAAkB,GAAG,IAAI,CAAO;IAEpC,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAsDpC,UAAU;CAYjB"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { rhineProxy, rhineProxyGeneral } from "./core/proxy/rhine-proxy";
|
|
2
2
|
import { RhineVar, RecursiveCrossRhineVar, StoredRhineVar, RhineVarAny, RecursiveObject, RecursiveArray, RecursiveMap } from "./core/var/rhine-var.type";
|
|
3
3
|
import Connector from "./core/connector/connector.abstract";
|
|
4
|
-
import useRhine from "./react/hooks/use-rhine.hook";
|
|
5
|
-
import useSynced from "./react/hooks/use-synced.hook";
|
|
6
4
|
import { Native, RvKey, RvPath } from "./core/native/native.type";
|
|
7
5
|
import { getRhineVarConfig, enableRhineVarLog, enableRhineVarSyncHandshakeCheck } from "./config/config";
|
|
8
6
|
import RhineVarBase from "./core/var/rhine-var-base.class";
|
|
@@ -20,5 +18,5 @@ import { Doc as YDoc, Array as YArray, Map as YMap, Text as YText, XmlFragment a
|
|
|
20
18
|
import ProxyOptions from "./core/proxy/proxy-options.interface";
|
|
21
19
|
import { UndoManagerOptions } from "yjs/dist/src/utils/UndoManager";
|
|
22
20
|
export type { StoredRhineVar, RhineVarAny, RecursiveCrossRhineVar, RecursiveObject, RecursiveArray, RecursiveMap, Native, RvPath, RvKey, ProxyOptions, UndoManagerOptions, };
|
|
23
|
-
export { Connector, rhineProxy, rhineProxyGeneral, item, text, map, RhineVarBase, RhineVar, RhineVarMap, RhineVarArray, RhineVarText, RhineVarXmlText, RhineVarXmlElement, RhineVarXmlFragment, SupportManager, enableRhineVarLog, enableRhineVarSyncHandshakeCheck, getRhineVarConfig,
|
|
21
|
+
export { Connector, rhineProxy, rhineProxyGeneral, item, text, map, RhineVarBase, RhineVar, RhineVarMap, RhineVarArray, RhineVarText, RhineVarXmlText, RhineVarXmlElement, RhineVarXmlFragment, SupportManager, enableRhineVarLog, enableRhineVarSyncHandshakeCheck, getRhineVarConfig, YDoc, YMap, YArray, YText, YXmlFragment, YXmlElement, YXmlText, };
|
|
24
22
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,iBAAiB,EAAC,iCAAiC;AACvE,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,kCAAkC;AACzJ,OAAO,SAAS,4CAA4C;AAC5D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,UAAU,EAAE,iBAAiB,EAAC,iCAAiC;AACvE,OAAO,EAAE,QAAQ,EAAE,sBAAsB,EAAE,cAAc,EAAE,WAAW,EAAE,eAAe,EAAE,cAAc,EAAE,YAAY,EAAE,kCAAkC;AACzJ,OAAO,SAAS,4CAA4C;AAC5D,OAAO,EAAC,MAAM,EAAE,KAAK,EAAE,MAAM,EAAC,kCAAkC;AAChE,OAAO,EAAC,iBAAiB,EAAE,iBAAiB,EAAE,gCAAgC,EAAC,wBAAwB;AACvG,OAAO,YAAY,wCAAwC;AAC3D,OAAO,WAAW,6CAA6C;AAC/D,OAAO,aAAa,+CAA+C;AACnE,OAAO,YAAY,8CAA8C;AACjE,OAAO,eAAe,kDAAkD;AACxE,OAAO,kBAAkB,qDAAqD;AAC9E,OAAO,mBAAmB,sDAAsD;AAChF,OAAO,cAAc,2CAA2C;AAChE,OAAO,IAAI,gCAAgC;AAC3C,OAAO,GAAG,MAAM,wBAAwB,CAAC;AACzC,OAAO,IAAI,MAAM,yBAAyB,CAAC;AAC3C,OAAO,EACL,GAAG,IAAI,IAAI,EACX,KAAK,IAAI,MAAM,EACf,GAAG,IAAI,IAAI,EACX,IAAI,IAAI,KAAK,EACb,WAAW,IAAI,YAAY,EAC3B,UAAU,IAAI,WAAW,EACzB,OAAO,IAAI,QAAQ,EACpB,MAAM,KAAK,CAAC;AACb,OAAO,YAAY,MAAM,sCAAsC,CAAC;AAChE,OAAO,EAAE,kBAAkB,EAAE,MAAM,gCAAgC,CAAC;AAEpE,YAAY,EACV,cAAc,EACd,WAAW,EACX,sBAAsB,EACtB,eAAe,EACf,cAAc,EACd,YAAY,EACZ,MAAM,EACN,MAAM,EACN,KAAK,EACL,YAAY,EACZ,kBAAkB,GACnB,CAAA;AAED,OAAO,EACL,SAAS,EACT,UAAU,EACV,iBAAiB,EACjB,IAAI,EACJ,IAAI,EACJ,GAAG,EACH,YAAY,EACZ,QAAQ,EACR,WAAW,EACX,aAAa,EACb,YAAY,EACZ,eAAe,EACf,kBAAkB,EAClB,mBAAmB,EACnB,cAAc,EACd,iBAAiB,EACjB,gCAAgC,EAChC,iBAAiB,EACjB,IAAI,EACJ,IAAI,EACJ,MAAM,EACN,KAAK,EACL,YAAY,EACZ,WAAW,EACX,QAAQ,GACT,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -3,16 +3,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.YXmlText = exports.YXmlElement = exports.YXmlFragment = exports.YText = exports.YArray = exports.YMap = exports.YDoc = exports.
|
|
6
|
+
exports.YXmlText = exports.YXmlElement = exports.YXmlFragment = exports.YText = exports.YArray = exports.YMap = exports.YDoc = exports.getRhineVarConfig = exports.enableRhineVarSyncHandshakeCheck = exports.enableRhineVarLog = exports.SupportManager = exports.RhineVarXmlFragment = exports.RhineVarXmlElement = exports.RhineVarXmlText = exports.RhineVarText = exports.RhineVarArray = exports.RhineVarMap = exports.RhineVarBase = exports.map = exports.text = exports.item = exports.rhineProxyGeneral = exports.rhineProxy = exports.Connector = void 0;
|
|
7
7
|
const rhine_proxy_1 = require("./core/proxy/rhine-proxy");
|
|
8
8
|
Object.defineProperty(exports, "rhineProxy", { enumerable: true, get: function () { return rhine_proxy_1.rhineProxy; } });
|
|
9
9
|
Object.defineProperty(exports, "rhineProxyGeneral", { enumerable: true, get: function () { return rhine_proxy_1.rhineProxyGeneral; } });
|
|
10
10
|
const connector_abstract_1 = __importDefault(require("./core/connector/connector.abstract"));
|
|
11
11
|
exports.Connector = connector_abstract_1.default;
|
|
12
|
-
const use_rhine_hook_1 = __importDefault(require("./react/hooks/use-rhine.hook"));
|
|
13
|
-
exports.useRhine = use_rhine_hook_1.default;
|
|
14
|
-
const use_synced_hook_1 = __importDefault(require("./react/hooks/use-synced.hook"));
|
|
15
|
-
exports.useSynced = use_synced_hook_1.default;
|
|
16
12
|
const config_1 = require("./config/config");
|
|
17
13
|
Object.defineProperty(exports, "getRhineVarConfig", { enumerable: true, get: function () { return config_1.getRhineVarConfig; } });
|
|
18
14
|
Object.defineProperty(exports, "enableRhineVarLog", { enumerable: true, get: function () { return config_1.enableRhineVarLog; } });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-rhine.hook.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-rhine.hook.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-rhine.hook.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-rhine.hook.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,cAAc,EAAC,sCAAkC;AAGzD,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,KAAK,EAAE,cAAc,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAqBxF"}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
"use client";
|
|
3
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
4
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
5
|
+
};
|
|
3
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
7
|
exports.default = useRhine;
|
|
5
|
-
const
|
|
8
|
+
const load_react_1 = __importDefault(require("../load-react"));
|
|
6
9
|
function useRhine(proxy) {
|
|
10
|
+
const React = (0, load_react_1.default)();
|
|
11
|
+
if (!React) {
|
|
12
|
+
throw new Error('RhineVar: useRhine hook requires React');
|
|
13
|
+
}
|
|
7
14
|
const createSnapshot = () => proxy.json();
|
|
8
|
-
const [state, setState] =
|
|
9
|
-
|
|
15
|
+
const [state, setState] = React.useState(createSnapshot);
|
|
16
|
+
React.useEffect(() => {
|
|
10
17
|
const updateState = () => setState(createSnapshot);
|
|
11
18
|
const unsubscribeSynced = proxy.subscribeSynced(updateState);
|
|
12
19
|
const unsubscribeDeep = proxy.subscribeDeep(updateState);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-synced.hook.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-synced.hook.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,gDAA4C;
|
|
1
|
+
{"version":3,"file":"use-synced.hook.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/use-synced.hook.ts"],"names":[],"mappings":"AAAA,OAAO,SAAS,gDAA4C;AAC5D,OAAO,EAAC,cAAc,EAAC,sCAAkC;AAIzD,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,MAAM,CAAC,EAAE,SAAS,GAAG,cAAc,WA8BpE"}
|
|
@@ -5,9 +5,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.default = useSynced;
|
|
7
7
|
const connector_abstract_1 = __importDefault(require("../../core/connector/connector.abstract"));
|
|
8
|
-
const react_1 = require("react");
|
|
9
8
|
const rhine_var_base_class_1 = __importDefault(require("../../core/var/rhine-var-base.class"));
|
|
9
|
+
const load_react_1 = __importDefault(require("../load-react"));
|
|
10
10
|
function useSynced(target) {
|
|
11
|
+
const React = (0, load_react_1.default)();
|
|
12
|
+
if (!React) {
|
|
13
|
+
throw new Error('RhineVar: useRhine hook requires React');
|
|
14
|
+
}
|
|
11
15
|
const checkSynced = () => {
|
|
12
16
|
var _a;
|
|
13
17
|
let connector = null;
|
|
@@ -19,8 +23,8 @@ function useSynced(target) {
|
|
|
19
23
|
}
|
|
20
24
|
return (_a = connector === null || connector === void 0 ? void 0 : connector.synced) !== null && _a !== void 0 ? _a : false;
|
|
21
25
|
};
|
|
22
|
-
const [synced, setSynced] =
|
|
23
|
-
|
|
26
|
+
const [synced, setSynced] = React.useState(checkSynced);
|
|
27
|
+
React.useEffect(() => {
|
|
24
28
|
if (target instanceof connector_abstract_1.default) {
|
|
25
29
|
return target.subscribeSynced((value) => setSynced(value));
|
|
26
30
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,+BAAoC;AACnD,OAAO,SAAS,gCAAqC;AAErD,OAAO,EACL,QAAQ,EACR,SAAS,GACV,CAAA"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.useSynced = exports.useRhine = void 0;
|
|
7
|
+
const use_rhine_hook_1 = __importDefault(require("./hooks/use-rhine.hook"));
|
|
8
|
+
exports.useRhine = use_rhine_hook_1.default;
|
|
9
|
+
const use_synced_hook_1 = __importDefault(require("./hooks/use-synced.hook"));
|
|
10
|
+
exports.useSynced = use_synced_hook_1.default;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-react.d.ts","sourceRoot":"","sources":["../../src/react/load-react.ts"],"names":[],"mappings":"AAAA,KAAK,SAAS,GAAG,cAAc,OAAO,CAAC,GAAG,IAAI,CAAA;AAW9C,MAAM,CAAC,OAAO,UAAU,SAAS,IAAI,SAAS,CAoC7C"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.default = loadReact;
|
|
27
|
+
const supportsDynamicImport = (() => {
|
|
28
|
+
try {
|
|
29
|
+
new Function('return import("data:,")');
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
catch (_a) {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
})();
|
|
36
|
+
function loadReact() {
|
|
37
|
+
// 1. 全局变量检测(UMD)
|
|
38
|
+
const globalReact = (() => {
|
|
39
|
+
if (typeof window !== 'undefined' && window.React) {
|
|
40
|
+
return window.React;
|
|
41
|
+
}
|
|
42
|
+
if (typeof global !== 'undefined' && global.React) {
|
|
43
|
+
return global.React;
|
|
44
|
+
}
|
|
45
|
+
return null;
|
|
46
|
+
})();
|
|
47
|
+
if (globalReact)
|
|
48
|
+
return globalReact;
|
|
49
|
+
// 2. 模块系统检测
|
|
50
|
+
try {
|
|
51
|
+
// 2A. CommonJS
|
|
52
|
+
if (typeof require === 'function') {
|
|
53
|
+
return require('react');
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
catch (_a) { }
|
|
57
|
+
// 2B. ESM 动态导入
|
|
58
|
+
if (supportsDynamicImport) {
|
|
59
|
+
// TODO: Promise is not supported
|
|
60
|
+
return Promise.resolve().then(() => __importStar(require('react'))).then(m => m.default || m).catch(() => null);
|
|
61
|
+
}
|
|
62
|
+
// 3. React Native 特殊处理
|
|
63
|
+
if (typeof navigator !== 'undefined' && navigator.product === 'ReactNative') {
|
|
64
|
+
try {
|
|
65
|
+
return require('react-native').require('react');
|
|
66
|
+
}
|
|
67
|
+
catch (_b) { }
|
|
68
|
+
}
|
|
69
|
+
return null;
|
|
70
|
+
}
|
package/package.json
CHANGED
|
@@ -1,71 +1,74 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "rhine-var",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "Variables that support multi-user collaboration and persistence, making collaboration and variable operations as simple as possible, with strict and well-defined type hints.",
|
|
5
|
-
"
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
"@
|
|
51
|
-
"@
|
|
52
|
-
"@
|
|
53
|
-
"jest": "^29.
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "rhine-var",
|
|
3
|
+
"version": "0.9.2",
|
|
4
|
+
"description": "Variables that support multi-user collaboration and persistence, making collaboration and variable operations as simple as possible, with strict and well-defined type hints.",
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./dist/index.js",
|
|
7
|
+
"./react": "./dist/react/index.js"
|
|
8
|
+
},
|
|
9
|
+
"types": "dist/index.d.ts",
|
|
10
|
+
"scripts": {
|
|
11
|
+
"dev": "tsc --watch",
|
|
12
|
+
"playground": "npm run dev --prefix playground/next-app",
|
|
13
|
+
"prepare": "ts-patch install -s",
|
|
14
|
+
"install-next": "npm install --prefix playground/next-app",
|
|
15
|
+
"link-next": "npm link && npm link rhine-var --prefix playground/next-app",
|
|
16
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
17
|
+
"build": "tsc",
|
|
18
|
+
"commit": "node scripts/commit.js",
|
|
19
|
+
"publish": "npm publish"
|
|
20
|
+
},
|
|
21
|
+
"author": "RhineAI",
|
|
22
|
+
"license": "Apache-2.0",
|
|
23
|
+
"keywords": [
|
|
24
|
+
"CRDT",
|
|
25
|
+
"sync",
|
|
26
|
+
"state",
|
|
27
|
+
"data-persistence",
|
|
28
|
+
"offline-first",
|
|
29
|
+
"shared-editing",
|
|
30
|
+
"proxy",
|
|
31
|
+
"collaboration",
|
|
32
|
+
"websocket",
|
|
33
|
+
"strongly-typed",
|
|
34
|
+
"real-time",
|
|
35
|
+
"concise",
|
|
36
|
+
"concise",
|
|
37
|
+
"rigorous",
|
|
38
|
+
"concurrency",
|
|
39
|
+
"hocuspocus"
|
|
40
|
+
],
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://github.com/RhineAI-Lab/rhine-var.git"
|
|
44
|
+
},
|
|
45
|
+
"bugs": {
|
|
46
|
+
"url": "https://github.com/RhineAI-Lab/rhine-var/issues"
|
|
47
|
+
},
|
|
48
|
+
"homepage": "https://github.com/RhineAI-Lab/rhine-var#readme",
|
|
49
|
+
"devDependencies": {
|
|
50
|
+
"@testing-library/jest-dom": "^6.5.0",
|
|
51
|
+
"@testing-library/react": "^16.0.1",
|
|
52
|
+
"@testing-library/react-hooks": "^8.0.1",
|
|
53
|
+
"@types/jest": "^29.5.12",
|
|
54
|
+
"@types/puppeteer": "^7.0.4",
|
|
55
|
+
"@types/react": "^18.3.5",
|
|
56
|
+
"@types/react-dom": "^18.3.0",
|
|
57
|
+
"jest": "^29.7.0",
|
|
58
|
+
"jest-puppeteer": "^10.1.1",
|
|
59
|
+
"puppeteer": "^23.3.0",
|
|
60
|
+
"ts-jest": "^29.2.5",
|
|
61
|
+
"ts-patch": "^3.2.1",
|
|
62
|
+
"typescript": "5.5.4",
|
|
63
|
+
"typescript-transform-paths": "^3.5.0",
|
|
64
|
+
"react": "^18.0.0",
|
|
65
|
+
"react-dom": "^18.0.0"
|
|
66
|
+
},
|
|
67
|
+
"dependencies": {
|
|
68
|
+
"yjs": "^13.6.23",
|
|
69
|
+
"y-protocols": "^1.0.6",
|
|
70
|
+
"y-websocket": "^2.0.4",
|
|
71
|
+
"@hocuspocus/provider": "^2.15.0"
|
|
72
|
+
},
|
|
73
|
+
"peerDependencies": {}
|
|
74
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import {rhineProxy, enableRhineVarLog, WebsocketConnector} from "rhine-var";
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
console.log('\n\n=================== Rhine Var Playground ===================\n\n')
|
|
5
|
+
|
|
6
|
+
enableRhineVarLog(true)
|
|
7
|
+
|
|
8
|
+
const state = rhineProxy({
|
|
9
|
+
count: 0,
|
|
10
|
+
}, new WebsocketConnector('ws://localhost:8080'))
|
|
11
|
+
|
|
12
|
+
state.afterSynced(() => {
|
|
13
|
+
console.log(++state.count)
|
|
14
|
+
process.exit()
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
setInterval(() => {
|
|
18
|
+
console.log('Waiting for sync...')
|
|
19
|
+
}, 1000)
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Native } from "./native.type";
|
|
2
|
-
export declare function isNative(value: any): boolean;
|
|
3
|
-
export declare function nativeSet(target: Native, key: string | symbol, value: any): boolean;
|
|
4
|
-
export declare function nativeHas(target: Native, key: string | symbol | number): boolean;
|
|
5
|
-
export declare function nativeOwnKeys(target: Native): string[];
|
|
6
|
-
export declare function nativeDelete(target: Native, key: string | symbol): boolean;
|
|
7
|
-
export declare function nativeGet(target: Native, key: string | symbol): any | undefined;
|
|
8
|
-
export declare function jsonToNative(data: any): Native;
|
|
9
|
-
//# sourceMappingURL=native.utils.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"native.utils.d.ts","sourceRoot":"","sources":["../../../src/core/native/native.utils.ts"],"names":[],"mappings":"AACA,OAAO,EAAC,MAAM,EAAO,sBAAkC;AAOvD,wBAAgB,QAAQ,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAO5C;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,OAAO,CA4BnF;AAED,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,CAkBhF;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,CAmB9C"}
|
|
@@ -1,154 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.isNative = isNative;
|
|
7
|
-
exports.nativeSet = nativeSet;
|
|
8
|
-
exports.nativeHas = nativeHas;
|
|
9
|
-
exports.nativeOwnKeys = nativeOwnKeys;
|
|
10
|
-
exports.nativeDelete = nativeDelete;
|
|
11
|
-
exports.nativeGet = nativeGet;
|
|
12
|
-
exports.jsonToNative = jsonToNative;
|
|
13
|
-
const index_1 = require("../../index");
|
|
14
|
-
const data_utils_1 = require("../utils/data.utils");
|
|
15
|
-
const rhine_var_base_class_1 = __importDefault(require("../var/rhine-var-base.class"));
|
|
16
|
-
const logger_1 = require("../../utils/logger");
|
|
17
|
-
const y_object_1 = __importDefault(require("./y-object"));
|
|
18
|
-
function isNative(value) {
|
|
19
|
-
return value instanceof index_1.YMap
|
|
20
|
-
|| value instanceof index_1.YArray
|
|
21
|
-
|| value instanceof index_1.YText
|
|
22
|
-
|| value instanceof index_1.YXmlFragment
|
|
23
|
-
|| value instanceof index_1.YXmlElement
|
|
24
|
-
|| value instanceof index_1.YXmlText;
|
|
25
|
-
}
|
|
26
|
-
function nativeSet(target, key, value) {
|
|
27
|
-
if (typeof key !== 'string') {
|
|
28
|
-
return false;
|
|
29
|
-
}
|
|
30
|
-
if (value instanceof rhine_var_base_class_1.default) {
|
|
31
|
-
value = value.native;
|
|
32
|
-
}
|
|
33
|
-
try {
|
|
34
|
-
if (target instanceof index_1.YMap) {
|
|
35
|
-
target.set(key, value);
|
|
36
|
-
return true;
|
|
37
|
-
}
|
|
38
|
-
else if (target instanceof index_1.YArray) {
|
|
39
|
-
const index = parseInt(key);
|
|
40
|
-
if (!isNaN(index)) {
|
|
41
|
-
if (target.length - 1 >= index) {
|
|
42
|
-
target.delete(index, 1);
|
|
43
|
-
}
|
|
44
|
-
target.insert(index, [value]);
|
|
45
|
-
return true;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
else {
|
|
49
|
-
(0, logger_1.error)('Unsupported nativeSet for:', target);
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
catch (e) {
|
|
53
|
-
(0, logger_1.error)('RhineVar nativeSet.error:', e);
|
|
54
|
-
}
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
function nativeHas(target, key) {
|
|
58
|
-
if (typeof key !== 'string') {
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
try {
|
|
62
|
-
if (target instanceof index_1.YMap) {
|
|
63
|
-
return target.has(key);
|
|
64
|
-
}
|
|
65
|
-
else if (target instanceof index_1.YArray) {
|
|
66
|
-
const index = parseInt(key, 10);
|
|
67
|
-
if (!isNaN(index)) {
|
|
68
|
-
return index < target.length && index >= 0;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
catch (e) {
|
|
73
|
-
(0, logger_1.error)('RhineVar nativeHas.error:', e);
|
|
74
|
-
}
|
|
75
|
-
return false;
|
|
76
|
-
}
|
|
77
|
-
function nativeOwnKeys(target) {
|
|
78
|
-
let keys = [];
|
|
79
|
-
if (target instanceof index_1.YMap) {
|
|
80
|
-
target.forEach((value, key) => {
|
|
81
|
-
keys.push(key);
|
|
82
|
-
});
|
|
83
|
-
}
|
|
84
|
-
else if (target instanceof index_1.YArray) {
|
|
85
|
-
for (let i = 0; i < target.length; i++) {
|
|
86
|
-
keys.push(String(i));
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
return keys;
|
|
90
|
-
}
|
|
91
|
-
function nativeDelete(target, key) {
|
|
92
|
-
if (typeof key !== 'string') {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
try {
|
|
96
|
-
if (target instanceof index_1.YMap) {
|
|
97
|
-
if (target.has(key)) {
|
|
98
|
-
target.delete(key);
|
|
99
|
-
return true;
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
if (target instanceof index_1.YArray) {
|
|
103
|
-
const pn = parseInt(key);
|
|
104
|
-
if (!isNaN(pn)) {
|
|
105
|
-
if (target.length > pn && pn >= 0) {
|
|
106
|
-
target.delete(pn, 1);
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
catch (e) {
|
|
112
|
-
(0, logger_1.error)('RhineVar nativeDelete.error:', e);
|
|
113
|
-
}
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
function nativeGet(target, key) {
|
|
117
|
-
if (typeof key !== 'string') {
|
|
118
|
-
return undefined;
|
|
119
|
-
}
|
|
120
|
-
try {
|
|
121
|
-
if (target instanceof index_1.YMap) {
|
|
122
|
-
return target.get(key);
|
|
123
|
-
}
|
|
124
|
-
else if (target instanceof index_1.YArray) {
|
|
125
|
-
const pn = parseInt(key);
|
|
126
|
-
if (!isNaN(pn))
|
|
127
|
-
return target.get(pn);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
(0, logger_1.error)('nativeGet.error:', e);
|
|
132
|
-
}
|
|
133
|
-
return undefined;
|
|
134
|
-
}
|
|
135
|
-
function jsonToNative(data) {
|
|
136
|
-
if (isNative(data)) {
|
|
137
|
-
return data;
|
|
138
|
-
}
|
|
139
|
-
if ((0, data_utils_1.isObject)(data)) {
|
|
140
|
-
let map = new y_object_1.default();
|
|
141
|
-
Object.entries(data).forEach(([key, value]) => {
|
|
142
|
-
map.set(key, jsonToNative(value));
|
|
143
|
-
});
|
|
144
|
-
return map;
|
|
145
|
-
}
|
|
146
|
-
if ((0, data_utils_1.isArray)(data)) {
|
|
147
|
-
let array = new index_1.YArray();
|
|
148
|
-
data.forEach((value, index) => {
|
|
149
|
-
array.push([jsonToNative(value)]);
|
|
150
|
-
});
|
|
151
|
-
return array;
|
|
152
|
-
}
|
|
153
|
-
return data;
|
|
154
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rhine-map.d.ts","sourceRoot":"","sources":["../../../../src/core/proxy/items/rhine-map.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,IAAI,EAAC,uBAAgB;AAG7B,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,EAAE;IACxC,CAAC,GAAG,EAAE,MAAM,GAAG,CAAC,CAAA;CACjB,GAAG,IAAI,CAAC,CAAC,CAAC,CAMV"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.rhineMap = rhineMap;
|
|
4
|
-
const index_1 = require("../../../index");
|
|
5
|
-
const var_utils_1 = require("../../utils/var.utils");
|
|
6
|
-
function rhineMap(defaultValue) {
|
|
7
|
-
const map = new index_1.YMap();
|
|
8
|
-
for (const key in defaultValue) {
|
|
9
|
-
map.set(key, (0, var_utils_1.ensureNativeOrBasic)(defaultValue[key]));
|
|
10
|
-
}
|
|
11
|
-
return map;
|
|
12
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"rhine-text.d.ts","sourceRoot":"","sources":["../../../../src/core/proxy/items/rhine-text.ts"],"names":[],"mappings":"AAAA,OAAO,EAAM,IAAI,IAAI,KAAK,EAAC,MAAM,KAAK,CAAC;AAEvC,wBAAgB,SAAS,CAAC,YAAY,EAAE,MAAM,SAE7C"}
|