@yorkie-js/react 0.6.6 → 0.6.7-rc
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.
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ClientOptions } from '@yorkie-js/sdk';
|
|
1
2
|
import { default as default_2 } from 'react';
|
|
2
3
|
import { Indexable } from '@yorkie-js/sdk';
|
|
3
4
|
import { JSONArray } from '@yorkie-js/sdk';
|
|
@@ -68,10 +69,9 @@ export declare const useRoot: () => {
|
|
|
68
69
|
* @param docKey
|
|
69
70
|
* @returns
|
|
70
71
|
*/
|
|
71
|
-
export declare function useYorkieDoc<R, P extends Indexable>(apiKey: string, docKey: string,
|
|
72
|
+
export declare function useYorkieDoc<R, P extends Indexable = Indexable>(apiKey: string, docKey: string, opts?: Omit<ClientOptions, 'apiKey'> & {
|
|
72
73
|
initialRoot?: R;
|
|
73
74
|
initialPresence?: P;
|
|
74
|
-
rpcAddr?: string;
|
|
75
75
|
}): {
|
|
76
76
|
root: R;
|
|
77
77
|
presences: Array<{
|
|
@@ -88,14 +88,6 @@ export declare function useYorkieDoc<R, P extends Indexable>(apiKey: string, doc
|
|
|
88
88
|
* `YorkieProvider` is a component that provides the Yorkie client to its children.
|
|
89
89
|
* It initializes the Yorkie client with the given API key and RPC address.
|
|
90
90
|
*/
|
|
91
|
-
export declare const YorkieProvider: React.FC<PropsWithChildren<
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* `YorkieProviderProps` is a set of properties for `YorkieProvider`.
|
|
95
|
-
*/
|
|
96
|
-
declare interface YorkieProviderProps {
|
|
97
|
-
apiKey: string;
|
|
98
|
-
rpcAddr?: string;
|
|
99
|
-
}
|
|
91
|
+
export declare const YorkieProvider: React.FC<PropsWithChildren<ClientOptions>>;
|
|
100
92
|
|
|
101
93
|
export { }
|
|
@@ -3,7 +3,7 @@ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { en
|
|
|
3
3
|
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
4
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
5
5
|
import { jsx } from "react/jsx-runtime";
|
|
6
|
-
import { createContext, useState, useEffect, useContext, useCallback } from "react";
|
|
6
|
+
import { createContext, useMemo, useState, useEffect, useContext, useCallback } from "react";
|
|
7
7
|
var Code$1;
|
|
8
8
|
(function(Code2) {
|
|
9
9
|
Code2[Code2["Canceled"] = 1] = "Canceled";
|
|
@@ -3699,9 +3699,6 @@ function createClient(service, transport) {
|
|
|
3699
3699
|
}
|
|
3700
3700
|
});
|
|
3701
3701
|
}
|
|
3702
|
-
function createPromiseClient(service, transport) {
|
|
3703
|
-
return createClient(service, transport);
|
|
3704
|
-
}
|
|
3705
3702
|
function createUnaryFn(transport, service, method) {
|
|
3706
3703
|
return async function(input, options) {
|
|
3707
3704
|
var _a2, _b2;
|
|
@@ -20267,6 +20264,7 @@ var SyncMode = /* @__PURE__ */ ((SyncMode2) => {
|
|
|
20267
20264
|
return SyncMode2;
|
|
20268
20265
|
})(SyncMode || {});
|
|
20269
20266
|
const DefaultClientOptions = {
|
|
20267
|
+
rpcAddr: "https://api.yorkie.dev",
|
|
20270
20268
|
syncLoopDuration: 50,
|
|
20271
20269
|
retrySyncLoopDelay: 1e3,
|
|
20272
20270
|
reconnectStreamDelay: 1e3
|
|
@@ -20281,7 +20279,7 @@ class Client {
|
|
|
20281
20279
|
* @param rpcAddr - the address of the RPC server.
|
|
20282
20280
|
* @param opts - the options of the client.
|
|
20283
20281
|
*/
|
|
20284
|
-
constructor(
|
|
20282
|
+
constructor(opts) {
|
|
20285
20283
|
__publicField(this, "id");
|
|
20286
20284
|
__publicField(this, "key");
|
|
20287
20285
|
__publicField(this, "metadata");
|
|
@@ -20299,7 +20297,8 @@ class Client {
|
|
|
20299
20297
|
__publicField(this, "processing", false);
|
|
20300
20298
|
__publicField(this, "keepalive", false);
|
|
20301
20299
|
opts = opts || DefaultClientOptions;
|
|
20302
|
-
|
|
20300
|
+
const rpcAddr = opts.rpcAddr || DefaultClientOptions.rpcAddr;
|
|
20301
|
+
this.key = opts.key || uuid();
|
|
20303
20302
|
this.metadata = opts.metadata || {};
|
|
20304
20303
|
this.status = "deactivated";
|
|
20305
20304
|
this.attachmentMap = /* @__PURE__ */ new Map();
|
|
@@ -20320,7 +20319,7 @@ class Client {
|
|
|
20320
20319
|
this.retrySyncLoopDelay = opts.retrySyncLoopDelay ?? DefaultClientOptions.retrySyncLoopDelay;
|
|
20321
20320
|
const { authInterceptor, setToken } = createAuthInterceptor(this.apiKey);
|
|
20322
20321
|
this.setAuthToken = setToken;
|
|
20323
|
-
this.rpcClient =
|
|
20322
|
+
this.rpcClient = createClient(
|
|
20324
20323
|
YorkieService,
|
|
20325
20324
|
createGrpcWebTransport({
|
|
20326
20325
|
baseUrl: rpcAddr,
|
|
@@ -21087,7 +21086,7 @@ const YorkieContext = createContext({
|
|
|
21087
21086
|
loading: true,
|
|
21088
21087
|
error: void 0
|
|
21089
21088
|
});
|
|
21090
|
-
function useYorkieClient(
|
|
21089
|
+
function useYorkieClient(opts) {
|
|
21091
21090
|
const [client, setClient] = useState(void 0);
|
|
21092
21091
|
const [loading, setLoading] = useState(true);
|
|
21093
21092
|
const [error, setError] = useState(void 0);
|
|
@@ -21103,9 +21102,7 @@ function useYorkieClient(apiKey, rpcAddr) {
|
|
|
21103
21102
|
return;
|
|
21104
21103
|
}
|
|
21105
21104
|
try {
|
|
21106
|
-
const newClient = new Client(
|
|
21107
|
-
apiKey
|
|
21108
|
-
});
|
|
21105
|
+
const newClient = new Client(opts);
|
|
21109
21106
|
await newClient.activate();
|
|
21110
21107
|
setClient(newClient);
|
|
21111
21108
|
} catch (e) {
|
|
@@ -21122,11 +21119,21 @@ function useYorkieClient(apiKey, rpcAddr) {
|
|
|
21122
21119
|
client.deactivate({ keepalive: true });
|
|
21123
21120
|
}
|
|
21124
21121
|
};
|
|
21125
|
-
}, [apiKey, rpcAddr, didMount]);
|
|
21122
|
+
}, [opts.apiKey, opts.rpcAddr, didMount]);
|
|
21126
21123
|
return { client, loading, error };
|
|
21127
21124
|
}
|
|
21128
|
-
const YorkieProvider = ({
|
|
21129
|
-
|
|
21125
|
+
const YorkieProvider = ({
|
|
21126
|
+
children,
|
|
21127
|
+
...rest
|
|
21128
|
+
}) => {
|
|
21129
|
+
const opts = useMemo(
|
|
21130
|
+
() => ({
|
|
21131
|
+
apiKey: rest.apiKey,
|
|
21132
|
+
rpcAddr: rest.rpcAddr
|
|
21133
|
+
}),
|
|
21134
|
+
[rest.apiKey, rest.rpcAddr]
|
|
21135
|
+
);
|
|
21136
|
+
const { client, loading, error } = useYorkieClient(opts);
|
|
21130
21137
|
return /* @__PURE__ */ jsx(YorkieContext.Provider, { value: { client, loading, error }, children });
|
|
21131
21138
|
};
|
|
21132
21139
|
const useYorkie = () => {
|
|
@@ -21289,22 +21296,25 @@ const useConnection = () => {
|
|
|
21289
21296
|
}
|
|
21290
21297
|
return context.connection;
|
|
21291
21298
|
};
|
|
21292
|
-
function useYorkieDoc(apiKey, docKey,
|
|
21293
|
-
const
|
|
21294
|
-
|
|
21295
|
-
|
|
21299
|
+
function useYorkieDoc(apiKey, docKey, opts) {
|
|
21300
|
+
const clientOpts = useMemo(() => {
|
|
21301
|
+
return {
|
|
21302
|
+
apiKey,
|
|
21303
|
+
...opts
|
|
21304
|
+
};
|
|
21305
|
+
}, [apiKey, docKey]);
|
|
21296
21306
|
const {
|
|
21297
21307
|
client,
|
|
21298
21308
|
loading: clientLoading,
|
|
21299
21309
|
error: clientError
|
|
21300
|
-
} = useYorkieClient(
|
|
21310
|
+
} = useYorkieClient(clientOpts);
|
|
21301
21311
|
const { root, presences, connection, update, loading, error } = useYorkieDocument(
|
|
21302
21312
|
client,
|
|
21303
21313
|
clientLoading,
|
|
21304
21314
|
clientError,
|
|
21305
21315
|
docKey,
|
|
21306
|
-
initialRoot,
|
|
21307
|
-
initialPresence
|
|
21316
|
+
opts == null ? void 0 : opts.initialRoot,
|
|
21317
|
+
opts == null ? void 0 : opts.initialPresence
|
|
21308
21318
|
);
|
|
21309
21319
|
return {
|
|
21310
21320
|
root,
|