@yorkie-js/react 0.6.0 → 0.6.1-rc1
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 +19 -0
- package/dist/yorkie-js-react.d.ts +84 -0
- package/dist/yorkie-js-react.es.js +23242 -0
- package/dist/yorkie-js-react.es.js.map +1 -0
- package/dist/yorkie-js-react.js +23246 -0
- package/dist/yorkie-js-react.js.map +1 -0
- package/package.json +8 -1
- package/lib/index.js +0 -17
- package/lib/useDocument.js +0 -88
- package/src/index.ts +0 -21
- package/src/useDocument.ts +0 -116
- package/tsconfig.json +0 -26
- package/vite.config.js +0 -31
package/package.json
CHANGED
|
@@ -1,15 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@yorkie-js/react",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1-rc1",
|
|
4
4
|
"description": "A set of hooks and providers for Yorkie JS SDK",
|
|
5
5
|
"main": "./dist/yorkie-js-react.js",
|
|
6
6
|
"publishConfig": {
|
|
7
7
|
"access": "public"
|
|
8
8
|
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md"
|
|
12
|
+
],
|
|
9
13
|
"dependencies": {
|
|
10
14
|
"react": "^19.0.0",
|
|
11
15
|
"@yorkie-js/sdk": "0.6.0"
|
|
12
16
|
},
|
|
17
|
+
"peerDependencies": {
|
|
18
|
+
"react": "^19"
|
|
19
|
+
},
|
|
13
20
|
"devDependencies": {
|
|
14
21
|
"@types/react": "^19.0.10",
|
|
15
22
|
"typescript": "^5.3.3",
|
package/lib/index.js
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 The Yorkie Authors. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { useDocument } from './useDocument';
|
|
17
|
-
export { useDocument };
|
package/lib/useDocument.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 The Yorkie Authors. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
17
|
-
import { Client, Document } from '@yorkie-js/sdk';
|
|
18
|
-
/**
|
|
19
|
-
* `useDocument` is a custom hook that returns the root object of the document.
|
|
20
|
-
*
|
|
21
|
-
* @param publicAPIKey
|
|
22
|
-
* @param docKey
|
|
23
|
-
* @param initialRoot
|
|
24
|
-
* @returns
|
|
25
|
-
*/
|
|
26
|
-
export function useDocument(publicAPIKey, docKey, initialRoot, options) {
|
|
27
|
-
const [client, setClient] = useState(undefined);
|
|
28
|
-
const [doc, setDoc] = useState(undefined);
|
|
29
|
-
const [root, setRoot] = useState(initialRoot);
|
|
30
|
-
const [loading, setLoading] = useState(true);
|
|
31
|
-
const [error, setError] = useState(undefined);
|
|
32
|
-
useEffect(() => {
|
|
33
|
-
setLoading(true);
|
|
34
|
-
setError(undefined);
|
|
35
|
-
/**
|
|
36
|
-
* `setupYorkie` initializes the Yorkie client and attaches the document.
|
|
37
|
-
*/
|
|
38
|
-
async function setupYorkie() {
|
|
39
|
-
try {
|
|
40
|
-
const client = new Client(options?.rpcAddr || 'https://api.yorkie.dev', { apiKey: publicAPIKey });
|
|
41
|
-
await client.activate();
|
|
42
|
-
const doc = new Document(docKey);
|
|
43
|
-
await client.attach(doc, {
|
|
44
|
-
initialPresence: {},
|
|
45
|
-
initialRoot,
|
|
46
|
-
});
|
|
47
|
-
doc.subscribe((event) => {
|
|
48
|
-
if (event.type === 'remote-change' || event.type === 'local-change') {
|
|
49
|
-
setRoot(doc.getRoot());
|
|
50
|
-
}
|
|
51
|
-
});
|
|
52
|
-
setClient(client);
|
|
53
|
-
setDoc(doc);
|
|
54
|
-
setRoot(doc.getRoot());
|
|
55
|
-
}
|
|
56
|
-
catch (err) {
|
|
57
|
-
setError(err instanceof Error ? err : new Error('Unknown error'));
|
|
58
|
-
}
|
|
59
|
-
finally {
|
|
60
|
-
setLoading(false);
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
setupYorkie();
|
|
64
|
-
return () => {
|
|
65
|
-
client?.deactivate({ keepalive: true });
|
|
66
|
-
};
|
|
67
|
-
}, [
|
|
68
|
-
publicAPIKey,
|
|
69
|
-
docKey,
|
|
70
|
-
JSON.stringify(initialRoot),
|
|
71
|
-
JSON.stringify(options),
|
|
72
|
-
]);
|
|
73
|
-
const update = useCallback((callback) => {
|
|
74
|
-
if (!doc) {
|
|
75
|
-
console.warn('Attempted to update document before it was initialized');
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
doc.update((root) => {
|
|
79
|
-
callback(root);
|
|
80
|
-
});
|
|
81
|
-
}, [doc]);
|
|
82
|
-
return {
|
|
83
|
-
root,
|
|
84
|
-
update,
|
|
85
|
-
loading,
|
|
86
|
-
error,
|
|
87
|
-
};
|
|
88
|
-
}
|
package/src/index.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 The Yorkie Authors. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import type { JSONArray, JSONObject } from '@yorkie-js/sdk';
|
|
18
|
-
import { useDocument } from './useDocument';
|
|
19
|
-
|
|
20
|
-
export { useDocument };
|
|
21
|
-
export type { JSONArray, JSONObject };
|
package/src/useDocument.ts
DELETED
|
@@ -1,116 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2025 The Yorkie Authors. All rights reserved.
|
|
3
|
-
*
|
|
4
|
-
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
-
* you may not use this file except in compliance with the License.
|
|
6
|
-
* You may obtain a copy of the License at
|
|
7
|
-
*
|
|
8
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
-
*
|
|
10
|
-
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
-
* See the License for the specific language governing permissions and
|
|
14
|
-
* limitations under the License.
|
|
15
|
-
*/
|
|
16
|
-
|
|
17
|
-
import { useCallback, useEffect, useState } from 'react';
|
|
18
|
-
import { Client, Document } from '@yorkie-js/sdk';
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* `useDocument` is a custom hook that returns the root object of the document.
|
|
22
|
-
*
|
|
23
|
-
* @param publicAPIKey
|
|
24
|
-
* @param docKey
|
|
25
|
-
* @param initialRoot
|
|
26
|
-
* @returns
|
|
27
|
-
*/
|
|
28
|
-
export function useDocument<T>(
|
|
29
|
-
publicAPIKey: string,
|
|
30
|
-
docKey: string,
|
|
31
|
-
initialRoot: T,
|
|
32
|
-
options?: {
|
|
33
|
-
rpcAddr?: string;
|
|
34
|
-
},
|
|
35
|
-
): {
|
|
36
|
-
root: T;
|
|
37
|
-
update: (callback: (root: T) => void) => void;
|
|
38
|
-
loading: boolean;
|
|
39
|
-
error: Error | undefined;
|
|
40
|
-
} {
|
|
41
|
-
const [client, setClient] = useState<Client | undefined>(undefined);
|
|
42
|
-
const [doc, setDoc] = useState<Document<T> | undefined>(undefined);
|
|
43
|
-
const [root, setRoot] = useState<T>(initialRoot);
|
|
44
|
-
const [loading, setLoading] = useState<boolean>(true);
|
|
45
|
-
const [error, setError] = useState<Error | undefined>(undefined);
|
|
46
|
-
|
|
47
|
-
useEffect(() => {
|
|
48
|
-
setLoading(true);
|
|
49
|
-
setError(undefined);
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* `setupYorkie` initializes the Yorkie client and attaches the document.
|
|
53
|
-
*/
|
|
54
|
-
async function setupYorkie() {
|
|
55
|
-
try {
|
|
56
|
-
const client = new Client(
|
|
57
|
-
options?.rpcAddr || 'https://api.yorkie.dev',
|
|
58
|
-
{ apiKey: publicAPIKey },
|
|
59
|
-
);
|
|
60
|
-
await client.activate();
|
|
61
|
-
|
|
62
|
-
const doc = new Document<T>(docKey);
|
|
63
|
-
await client.attach(doc, {
|
|
64
|
-
initialPresence: {},
|
|
65
|
-
initialRoot,
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
doc.subscribe((event) => {
|
|
69
|
-
if (event.type === 'remote-change' || event.type === 'local-change') {
|
|
70
|
-
setRoot(doc.getRoot());
|
|
71
|
-
}
|
|
72
|
-
});
|
|
73
|
-
|
|
74
|
-
setClient(client);
|
|
75
|
-
setDoc(doc);
|
|
76
|
-
setRoot(doc.getRoot());
|
|
77
|
-
} catch (err) {
|
|
78
|
-
setError(err instanceof Error ? err : new Error('Unknown error'));
|
|
79
|
-
} finally {
|
|
80
|
-
setLoading(false);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
setupYorkie();
|
|
85
|
-
|
|
86
|
-
return () => {
|
|
87
|
-
client?.deactivate({ keepalive: true });
|
|
88
|
-
};
|
|
89
|
-
}, [
|
|
90
|
-
publicAPIKey,
|
|
91
|
-
docKey,
|
|
92
|
-
JSON.stringify(initialRoot),
|
|
93
|
-
JSON.stringify(options),
|
|
94
|
-
]);
|
|
95
|
-
|
|
96
|
-
const update = useCallback(
|
|
97
|
-
(callback: (root: T) => void) => {
|
|
98
|
-
if (!doc) {
|
|
99
|
-
console.warn('Attempted to update document before it was initialized');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
doc.update((root) => {
|
|
104
|
-
callback(root);
|
|
105
|
-
});
|
|
106
|
-
},
|
|
107
|
-
[doc],
|
|
108
|
-
);
|
|
109
|
-
|
|
110
|
-
return {
|
|
111
|
-
root,
|
|
112
|
-
update,
|
|
113
|
-
loading,
|
|
114
|
-
error,
|
|
115
|
-
};
|
|
116
|
-
}
|
package/tsconfig.json
DELETED
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "ES2020",
|
|
4
|
-
"useDefineForClassFields": true,
|
|
5
|
-
"module": "ESNext",
|
|
6
|
-
"lib": ["ES2020", "DOM"],
|
|
7
|
-
"skipLibCheck": true,
|
|
8
|
-
"outDir": "./lib",
|
|
9
|
-
|
|
10
|
-
/* Bundler mode */
|
|
11
|
-
"moduleResolution": "node",
|
|
12
|
-
"allowSyntheticDefaultImports": true,
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"esModuleInterop": true,
|
|
15
|
-
|
|
16
|
-
/* Linting */
|
|
17
|
-
"strict": true,
|
|
18
|
-
|
|
19
|
-
/* Paths */
|
|
20
|
-
"baseUrl": ".",
|
|
21
|
-
"paths": {
|
|
22
|
-
"@yorkie-js-sdk/src/*": ["../../packages/sdk/src/*"]
|
|
23
|
-
}
|
|
24
|
-
},
|
|
25
|
-
"include": ["src"]
|
|
26
|
-
}
|
package/vite.config.js
DELETED
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import { defineConfig } from 'vite';
|
|
2
|
-
import dts from 'vite-plugin-dts';
|
|
3
|
-
import path from 'path';
|
|
4
|
-
|
|
5
|
-
// https://vitejs.dev/config/
|
|
6
|
-
export default defineConfig({
|
|
7
|
-
build: {
|
|
8
|
-
lib: {
|
|
9
|
-
entry: 'src/index.ts',
|
|
10
|
-
name: 'yorkie-js-react',
|
|
11
|
-
fileName: (format) =>
|
|
12
|
-
format === 'umd'
|
|
13
|
-
? 'yorkie-js-react.js'
|
|
14
|
-
: `yorkie-js-react.${format}.js`,
|
|
15
|
-
},
|
|
16
|
-
outDir: 'dist',
|
|
17
|
-
sourcemap: true,
|
|
18
|
-
minify: false,
|
|
19
|
-
emptyOutDir: true,
|
|
20
|
-
},
|
|
21
|
-
resolve: {
|
|
22
|
-
alias: {
|
|
23
|
-
'@yorkie-js-sdk/src': path.resolve(__dirname, '../sdk/src'),
|
|
24
|
-
},
|
|
25
|
-
},
|
|
26
|
-
plugins: [
|
|
27
|
-
dts({
|
|
28
|
-
rollupTypes: true,
|
|
29
|
-
}),
|
|
30
|
-
],
|
|
31
|
-
});
|