@connectycube/react-ui-kit 0.0.3 → 0.0.5
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 +1 -1
- package/cmd/add.js +17 -11
- package/gen/{templates/remote-stream.jsx → components/stream-view.jsx} +18 -4
- package/gen/index.js +1 -3
- package/package.json +7 -5
- package/src/{templates/remote-stream.tsx → components/stream-view.tsx} +21 -8
- package/src/index.ts +2 -6
- package/gen/lib/constants.js +0 -6
- package/gen/templates/local-stream.jsx +0 -52
- package/src/components/connectycube-ui/lib/constants.js +0 -6
- package/src/components/connectycube-ui/lib/utils.js +0 -10
- package/src/components/connectycube-ui/local-stream.jsx +0 -52
- package/src/lib/constants.ts +0 -4
- package/src/templates/local-stream.tsx +0 -69
- /package/gen/{lib → components}/utils.js +0 -0
- /package/src/{lib → components}/utils.ts +0 -0
package/README.md
CHANGED
|
@@ -67,7 +67,7 @@ Coming soon...
|
|
|
67
67
|
|
|
68
68
|
## 🧩 Contributing
|
|
69
69
|
|
|
70
|
-
See [CONTRIBUTING.md](https://github.com/connectycube/react-ui-kit/blob/main/.github/CONTRIBUTING.md) for guidelines on adding new components
|
|
70
|
+
See [CONTRIBUTING.md](https://github.com/connectycube/react-ui-kit/blob/main/.github/CONTRIBUTING.md) for guidelines on adding new components.
|
|
71
71
|
|
|
72
72
|
---
|
|
73
73
|
|
package/cmd/add.js
CHANGED
|
@@ -70,24 +70,30 @@ export async function add(component) {
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
const filename = `${component}${isTypeScript ? ".tsx" : ".jsx"}`;
|
|
73
|
-
const
|
|
74
|
-
const input = path.join(
|
|
75
|
-
const utils = path.join(base, "lib");
|
|
73
|
+
const sourceDir = path.join(__dirname, "..", isTypeScript ? "src" : "gen", "components");
|
|
74
|
+
const input = path.join(sourceDir, filename);
|
|
76
75
|
|
|
77
76
|
if (!(await fs.pathExists(input))) {
|
|
78
77
|
console.warn(`⚠️ Component "${component}" does not exist.`);
|
|
79
78
|
process.exit(1);
|
|
80
79
|
}
|
|
81
80
|
|
|
82
|
-
const
|
|
83
|
-
const
|
|
84
|
-
const
|
|
81
|
+
const dest = path.join(cwd, "src", "components", "connectycube-ui");
|
|
82
|
+
const output = path.join(dest, filename);
|
|
83
|
+
const utilsInput = path.join(sourceDir, "utils.ts");
|
|
84
|
+
const utilsOutput = path.join(dest, "utils.ts");
|
|
85
85
|
|
|
86
|
-
await fs.ensureDir(
|
|
86
|
+
await fs.ensureDir(dest);
|
|
87
87
|
await fs.copyFile(input, output);
|
|
88
|
-
console.log(
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
88
|
+
console.log("✅ Added:");
|
|
89
|
+
console.log(`- ${filename} (${output})`);
|
|
90
|
+
|
|
91
|
+
if (!(await fs.pathExists(utilsOutput))) {
|
|
92
|
+
await fs.copyFile(utilsInput, utilsOutput);
|
|
93
|
+
console.log(`- utils.ts (${utilsOutput}`);
|
|
94
|
+
} else {
|
|
95
|
+
console.log("- utils.ts (already exists)");
|
|
96
|
+
}
|
|
97
|
+
|
|
92
98
|
await installDependencies(component);
|
|
93
99
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
-
import { cn, getRandomString } from '
|
|
2
|
+
import { cn, getRandomString } from './utils';
|
|
3
3
|
|
|
4
|
-
export const
|
|
4
|
+
export const StreamView = forwardRef(({ id, stream, mirror, className, muted, ...props }, ref) => {
|
|
5
5
|
const videoRef = useRef(null);
|
|
6
|
-
const elementId = useMemo(() => id ?? `
|
|
6
|
+
const elementId = useMemo(() => id ?? `stream-${getRandomString()}`, [id]);
|
|
7
7
|
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
8
8
|
const defaultClassName = 'size-full object-contain';
|
|
9
9
|
const mirrorClassName = mirror ? 'scale-x-[-1]' : '';
|
|
@@ -25,7 +25,7 @@ export const RemoteStream = forwardRef(({ id, stream, mirror, className, muted,
|
|
|
25
25
|
try {
|
|
26
26
|
videoRef.current?.play();
|
|
27
27
|
} catch (error) {
|
|
28
|
-
console.error('<
|
|
28
|
+
console.error('<StreamView/> play():', error);
|
|
29
29
|
}
|
|
30
30
|
};
|
|
31
31
|
|
|
@@ -47,3 +47,17 @@ export const RemoteStream = forwardRef(({ id, stream, mirror, className, muted,
|
|
|
47
47
|
/>
|
|
48
48
|
) : null;
|
|
49
49
|
});
|
|
50
|
+
|
|
51
|
+
export const LocalStreamView = forwardRef(({ muted, mirror, ...props }, ref) => {
|
|
52
|
+
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
53
|
+
const isMirror = typeof mirror === 'boolean' ? mirror : true;
|
|
54
|
+
|
|
55
|
+
return <StreamView ref={ref} muted={isMuted} mirror={isMirror} {...props} />;
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
export const RemoteStreamView = forwardRef(({ muted, mirror, ...props }, ref) => {
|
|
59
|
+
const isMuted = typeof muted === 'boolean' ? muted : false;
|
|
60
|
+
const isMirror = typeof mirror === 'boolean' ? mirror : false;
|
|
61
|
+
|
|
62
|
+
return <StreamView ref={ref} muted={isMuted} mirror={isMirror} {...props} />;
|
|
63
|
+
});
|
package/gen/index.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@connectycube/react-ui-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.5",
|
|
4
4
|
"description": "Simple React UI Kit generator with TSX/JSX",
|
|
5
5
|
"homepage": "https://github.com/ConnectyCube/react-ui-kit#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"build": "rollup -c",
|
|
44
44
|
"format": "node ./scripts/format.js",
|
|
45
45
|
"transform": "node ./scripts/transform.js",
|
|
46
|
-
"version": "node ./scripts/bump-version.
|
|
46
|
+
"version": "node ./scripts/bump-version.js",
|
|
47
47
|
"version:patch": "npm run version patch",
|
|
48
48
|
"version:minor": "npm run version minor",
|
|
49
49
|
"version:major": "npm run version major",
|
|
@@ -58,6 +58,11 @@
|
|
|
58
58
|
"tsx",
|
|
59
59
|
"jsx"
|
|
60
60
|
],
|
|
61
|
+
"dependencies": {
|
|
62
|
+
"execa": "^9.6.0",
|
|
63
|
+
"fs-extra": "^11.3.2",
|
|
64
|
+
"prompts": "^2.4.2"
|
|
65
|
+
},
|
|
61
66
|
"peerDependencies": {
|
|
62
67
|
"clsx": "*",
|
|
63
68
|
"react": ">=18",
|
|
@@ -78,12 +83,9 @@
|
|
|
78
83
|
"eslint": "^9.38.0",
|
|
79
84
|
"eslint-plugin-react-hooks": "^7.0.0",
|
|
80
85
|
"eslint-plugin-react-refresh": "^0.4.24",
|
|
81
|
-
"execa": "^9.6.0",
|
|
82
86
|
"fast-glob": "^3.3.3",
|
|
83
|
-
"fs-extra": "^11.3.2",
|
|
84
87
|
"globals": "^16.4.0",
|
|
85
88
|
"prettier": "^3.6.2",
|
|
86
|
-
"prompts": "^2.4.2",
|
|
87
89
|
"rollup": "^4.52.5",
|
|
88
90
|
"rollup-plugin-peer-deps-external": "^2.2.4",
|
|
89
91
|
"tslib": "^2.8.1",
|
|
@@ -1,23 +1,22 @@
|
|
|
1
|
+
import type React from 'react';
|
|
1
2
|
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
-
import {
|
|
3
|
-
import { cn, getRandomString } from '../lib/utils';
|
|
3
|
+
import { cn, getRandomString } from './utils';
|
|
4
4
|
|
|
5
|
-
export type
|
|
5
|
+
export type StreamViewProps = {
|
|
6
6
|
id?: string;
|
|
7
7
|
stream?: MediaStream;
|
|
8
8
|
mirror?: boolean;
|
|
9
|
-
className?: ClassValue;
|
|
10
9
|
} & React.VideoHTMLAttributes<HTMLVideoElement>;
|
|
11
10
|
|
|
12
|
-
export type
|
|
11
|
+
export type StreamViewRef = {
|
|
13
12
|
id: string;
|
|
14
13
|
element: HTMLVideoElement | null;
|
|
15
14
|
};
|
|
16
15
|
|
|
17
|
-
export const
|
|
16
|
+
export const StreamView = forwardRef<StreamViewRef, StreamViewProps>(
|
|
18
17
|
({ id, stream, mirror, className, muted, ...props }, ref) => {
|
|
19
18
|
const videoRef = useRef<HTMLVideoElement>(null);
|
|
20
|
-
const elementId = useMemo(() => id ?? `
|
|
19
|
+
const elementId = useMemo(() => id ?? `stream-${getRandomString()}`, [id]);
|
|
21
20
|
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
22
21
|
const defaultClassName = 'size-full object-contain';
|
|
23
22
|
const mirrorClassName = mirror ? 'scale-x-[-1]' : '';
|
|
@@ -39,7 +38,7 @@ export const RemoteStream = forwardRef<RemoteStreamRef, RemoteStreamProps>(
|
|
|
39
38
|
try {
|
|
40
39
|
videoRef.current?.play();
|
|
41
40
|
} catch (error) {
|
|
42
|
-
console.error('<
|
|
41
|
+
console.error('<StreamView/> play():', error);
|
|
43
42
|
}
|
|
44
43
|
};
|
|
45
44
|
|
|
@@ -62,3 +61,17 @@ export const RemoteStream = forwardRef<RemoteStreamRef, RemoteStreamProps>(
|
|
|
62
61
|
) : null;
|
|
63
62
|
}
|
|
64
63
|
);
|
|
64
|
+
|
|
65
|
+
export const LocalStreamView = forwardRef<StreamViewRef, StreamViewProps>(({ muted, mirror, ...props }, ref) => {
|
|
66
|
+
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
67
|
+
const isMirror = typeof mirror === 'boolean' ? mirror : true;
|
|
68
|
+
|
|
69
|
+
return <StreamView ref={ref} muted={isMuted} mirror={isMirror} {...props} />;
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
export const RemoteStreamView = forwardRef<StreamViewRef, StreamViewProps>(({ muted, mirror, ...props }, ref) => {
|
|
73
|
+
const isMuted = typeof muted === 'boolean' ? muted : false;
|
|
74
|
+
const isMirror = typeof mirror === 'boolean' ? mirror : false;
|
|
75
|
+
|
|
76
|
+
return <StreamView ref={ref} muted={isMuted} mirror={isMirror} {...props} />;
|
|
77
|
+
});
|
package/src/index.ts
CHANGED
|
@@ -1,7 +1,3 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { StreamView, LocalStreamView, RemoteStreamView } from './components/stream-view';
|
|
2
2
|
|
|
3
|
-
export type {
|
|
4
|
-
|
|
5
|
-
export { RemoteStream } from './templates/remote-stream';
|
|
6
|
-
|
|
7
|
-
export type { RemoteStreamProps } from './templates/remote-stream';
|
|
3
|
+
export type { StreamViewProps, StreamViewRef } from './components/stream-view';
|
package/gen/lib/constants.js
DELETED
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
-
import { cn, getRandomString } from '../lib/utils';
|
|
3
|
-
import { ActiveMedia } from '../lib/constants';
|
|
4
|
-
|
|
5
|
-
export const LocalStream = forwardRef(({ id, stream, activeMedia, mirror, className, muted, ...props }, ref) => {
|
|
6
|
-
const videoRef = useRef(null);
|
|
7
|
-
const elementId = useMemo(() => id ?? `local-stream-${getRandomString()}`, [id]);
|
|
8
|
-
const isCamera = activeMedia === ActiveMedia.USER || activeMedia === 'user';
|
|
9
|
-
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
10
|
-
const isMirror = typeof mirror === 'boolean' ? mirror : isCamera;
|
|
11
|
-
const defaultClassName = 'size-full object-contain';
|
|
12
|
-
const mirrorClassName = isMirror ? 'scale-x-[-1]' : '';
|
|
13
|
-
|
|
14
|
-
useImperativeHandle(
|
|
15
|
-
ref,
|
|
16
|
-
() => ({
|
|
17
|
-
id: elementId,
|
|
18
|
-
element: videoRef.current,
|
|
19
|
-
}),
|
|
20
|
-
[elementId]
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (videoRef.current && stream) {
|
|
25
|
-
videoRef.current.srcObject = stream;
|
|
26
|
-
|
|
27
|
-
const playVideo = () => {
|
|
28
|
-
try {
|
|
29
|
-
videoRef.current?.play();
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error('<LocalStream/> play():', error);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
videoRef.current.onloadedmetadata = () => {
|
|
36
|
-
setTimeout(playVideo, 100);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}, [stream]);
|
|
40
|
-
|
|
41
|
-
return stream ? (
|
|
42
|
-
<video
|
|
43
|
-
ref={videoRef}
|
|
44
|
-
id={elementId}
|
|
45
|
-
className={cn(defaultClassName, mirrorClassName, className)}
|
|
46
|
-
muted={isMuted}
|
|
47
|
-
autoPlay
|
|
48
|
-
playsInline
|
|
49
|
-
{...props}
|
|
50
|
-
/>
|
|
51
|
-
) : null;
|
|
52
|
-
});
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import { clsx } from 'clsx';
|
|
2
|
-
import { twMerge } from 'tailwind-merge';
|
|
3
|
-
|
|
4
|
-
export function cn(...inputs) {
|
|
5
|
-
return twMerge(clsx(inputs));
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export function getRandomString(length = 8) {
|
|
9
|
-
return (Date.now() / Math.random()).toString(36).replace('.', '').slice(0, length);
|
|
10
|
-
}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
2
|
-
import { cn, getRandomString } from '../lib/utils';
|
|
3
|
-
import { ActiveMedia } from '../lib/constants';
|
|
4
|
-
|
|
5
|
-
export const LocalStream = forwardRef(({ id, stream, activeMedia, mirror, className, muted, ...props }, ref) => {
|
|
6
|
-
const videoRef = useRef(null);
|
|
7
|
-
const elementId = useMemo(() => id ?? `local-stream-${getRandomString()}`, [id]);
|
|
8
|
-
const isCamera = activeMedia === ActiveMedia.USER || activeMedia === 'user';
|
|
9
|
-
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
10
|
-
const isMirror = typeof mirror === 'boolean' ? mirror : isCamera;
|
|
11
|
-
const defaultClassName = 'size-full object-contain';
|
|
12
|
-
const mirrorClassName = isMirror ? 'scale-x-[-1]' : '';
|
|
13
|
-
|
|
14
|
-
useImperativeHandle(
|
|
15
|
-
ref,
|
|
16
|
-
() => ({
|
|
17
|
-
id: elementId,
|
|
18
|
-
element: videoRef.current,
|
|
19
|
-
}),
|
|
20
|
-
[elementId]
|
|
21
|
-
);
|
|
22
|
-
|
|
23
|
-
useEffect(() => {
|
|
24
|
-
if (videoRef.current && stream) {
|
|
25
|
-
videoRef.current.srcObject = stream;
|
|
26
|
-
|
|
27
|
-
const playVideo = () => {
|
|
28
|
-
try {
|
|
29
|
-
videoRef.current?.play();
|
|
30
|
-
} catch (error) {
|
|
31
|
-
console.error('<LocalStream/> play():', error);
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
videoRef.current.onloadedmetadata = () => {
|
|
36
|
-
setTimeout(playVideo, 100);
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
}, [stream]);
|
|
40
|
-
|
|
41
|
-
return stream ? (
|
|
42
|
-
<video
|
|
43
|
-
ref={videoRef}
|
|
44
|
-
id={elementId}
|
|
45
|
-
className={cn(defaultClassName, mirrorClassName, className)}
|
|
46
|
-
muted={isMuted}
|
|
47
|
-
autoPlay
|
|
48
|
-
playsInline
|
|
49
|
-
{...props}
|
|
50
|
-
/>
|
|
51
|
-
) : null;
|
|
52
|
-
});
|
package/src/lib/constants.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
import type React from 'react';
|
|
2
|
-
import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
3
|
-
import { type ClassValue } from 'clsx';
|
|
4
|
-
import { cn, getRandomString } from '../lib/utils';
|
|
5
|
-
import { ActiveMedia } from '../lib/constants';
|
|
6
|
-
|
|
7
|
-
export type LocalStreamProps = {
|
|
8
|
-
id?: string;
|
|
9
|
-
stream?: MediaStream;
|
|
10
|
-
activeMedia?: ActiveMedia | 'user' | 'display';
|
|
11
|
-
mirror?: boolean;
|
|
12
|
-
className?: ClassValue;
|
|
13
|
-
} & React.VideoHTMLAttributes<HTMLVideoElement>;
|
|
14
|
-
|
|
15
|
-
export type LocalStreamRef = {
|
|
16
|
-
id: string;
|
|
17
|
-
element: HTMLVideoElement | null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export const LocalStream = forwardRef<LocalStreamRef, LocalStreamProps>(
|
|
21
|
-
({ id, stream, activeMedia, mirror, className, muted, ...props }, ref) => {
|
|
22
|
-
const videoRef = useRef<HTMLVideoElement>(null);
|
|
23
|
-
const elementId = useMemo(() => id ?? `local-stream-${getRandomString()}`, [id]);
|
|
24
|
-
const isCamera = activeMedia === ActiveMedia.USER || activeMedia === 'user';
|
|
25
|
-
const isMuted = typeof muted === 'boolean' ? muted : true;
|
|
26
|
-
const isMirror = typeof mirror === 'boolean' ? mirror : isCamera;
|
|
27
|
-
const defaultClassName = 'size-full object-contain';
|
|
28
|
-
const mirrorClassName = isMirror ? 'scale-x-[-1]' : '';
|
|
29
|
-
|
|
30
|
-
useImperativeHandle(
|
|
31
|
-
ref,
|
|
32
|
-
() => ({
|
|
33
|
-
id: elementId,
|
|
34
|
-
element: videoRef.current,
|
|
35
|
-
}),
|
|
36
|
-
[elementId]
|
|
37
|
-
);
|
|
38
|
-
|
|
39
|
-
useEffect(() => {
|
|
40
|
-
if (videoRef.current && stream) {
|
|
41
|
-
videoRef.current.srcObject = stream;
|
|
42
|
-
|
|
43
|
-
const playVideo = () => {
|
|
44
|
-
try {
|
|
45
|
-
videoRef.current?.play();
|
|
46
|
-
} catch (error) {
|
|
47
|
-
console.error('<LocalStream/> play():', error);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
videoRef.current.onloadedmetadata = () => {
|
|
52
|
-
setTimeout(playVideo, 100);
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
}, [stream]);
|
|
56
|
-
|
|
57
|
-
return stream ? (
|
|
58
|
-
<video
|
|
59
|
-
ref={videoRef}
|
|
60
|
-
id={elementId}
|
|
61
|
-
className={cn(defaultClassName, mirrorClassName, className)}
|
|
62
|
-
muted={isMuted}
|
|
63
|
-
autoPlay
|
|
64
|
-
playsInline
|
|
65
|
-
{...props}
|
|
66
|
-
/>
|
|
67
|
-
) : null;
|
|
68
|
-
}
|
|
69
|
-
);
|
|
File without changes
|
|
File without changes
|