hubbe-sdk 1.2.0
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/bin/.token +1 -0
- package/bin/build.js +94 -0
- package/bin/defaultHtml.html +23 -0
- package/bin/defaultJs.js +49 -0
- package/bin/deploy.js +130 -0
- package/bin/deployTs.js +157 -0
- package/bin/fetch.js +118 -0
- package/bin/htmlu.js +116 -0
- package/bin/index.js +77 -0
- package/bin/react-template/html/eslint.config.js +28 -0
- package/bin/react-template/html/index.html +7 -0
- package/bin/react-template/html/package.json +34 -0
- package/bin/react-template/html/postcss.config.js +6 -0
- package/bin/react-template/html/src/App.tsx +33 -0
- package/bin/react-template/html/src/hooks/index.ts +3 -0
- package/bin/react-template/html/src/hooks/useDraggable.ts +69 -0
- package/bin/react-template/html/src/hooks/useMessageEvent.ts +120 -0
- package/bin/react-template/html/src/hooks/useUserContext.ts +24 -0
- package/bin/react-template/html/src/index.css +5 -0
- package/bin/react-template/html/src/main.tsx +10 -0
- package/bin/react-template/html/src/vite-env.d.ts +1 -0
- package/bin/react-template/html/tailwind.config.js +12 -0
- package/bin/react-template/html/tsconfig.app.json +24 -0
- package/bin/react-template/html/tsconfig.json +7 -0
- package/bin/react-template/html/tsconfig.node.json +22 -0
- package/bin/react-template/html/vite.config.ts +10 -0
- package/bin/react-template/room/global.d.ts +4222 -0
- package/bin/react-template/room/room.ts +36 -0
- package/bin/react-template/room/tsconfig.json +9 -0
- package/bin/react.js +60 -0
- package/bin/rollup.js +67 -0
- package/bin/rollupTs.js +72 -0
- package/bin/script.js +131 -0
- package/bin/tsconfig_template.json +9 -0
- package/bin/utils.js +35 -0
- package/package.json +57 -0
package/bin/index.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
#! /usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const { Command } = require('commander');
|
|
4
|
+
const { setToken, newScript, newReactScript } = require('./utils');
|
|
5
|
+
const HtmlUploader = require('./htmlu');
|
|
6
|
+
const Script = require('./script');
|
|
7
|
+
const Deploy = require('./deploy');
|
|
8
|
+
const Rollup = require('./rollup');
|
|
9
|
+
const DeployTs = require('./deployTs');
|
|
10
|
+
const RollupTs = require('./rollupTs');
|
|
11
|
+
const Build = require('./build');
|
|
12
|
+
const React = require('./react');
|
|
13
|
+
const { resolve } = require('path');
|
|
14
|
+
|
|
15
|
+
const program = new Command();
|
|
16
|
+
|
|
17
|
+
program
|
|
18
|
+
.option('-d, --deploy <script>', 'Deploy script (Web Files + Room)')
|
|
19
|
+
.option('-h, --html <script>', 'Deploy Web Files')
|
|
20
|
+
.option('-s, --script <script>', 'Deploy Room Script')
|
|
21
|
+
.option('-t, --token <token>', 'Set the token')
|
|
22
|
+
.option('-n, --new <script>', 'Create a new script')
|
|
23
|
+
.option('-r, --rollup <script>', 'Rollup a script')
|
|
24
|
+
.option('-rts, --rollupts <script>', 'Rollup a script with typescript')
|
|
25
|
+
.option('-dts, --deployts <script>', 'Deploy with typescript (Web files + room)')
|
|
26
|
+
.option('-nr, --newreact <script>', 'Create a new react script')
|
|
27
|
+
.option('-b, --build <script>', 'Build a script')
|
|
28
|
+
|
|
29
|
+
program.parse(process.argv);
|
|
30
|
+
|
|
31
|
+
const options = program.opts();
|
|
32
|
+
|
|
33
|
+
if (options.html) {
|
|
34
|
+
require('dotenv').config({ path: resolve(__dirname, '../.env') });
|
|
35
|
+
return new HtmlUploader(options.html);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (options.deploy) {
|
|
39
|
+
// require('dotenv').config({ path: resolve(__dirname, '../.env') });
|
|
40
|
+
// new HtmlUploader(options.deploy);
|
|
41
|
+
return new Deploy(options.deploy);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
if (options.script) {
|
|
45
|
+
return new Script(options.script);
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (options.token) {
|
|
49
|
+
return setToken(options.token);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (options.new) {
|
|
53
|
+
return newScript(options.new);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
if (options.rollup) {
|
|
57
|
+
return new Rollup(options.rollup);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (options.deployts) {
|
|
61
|
+
return new DeployTs(options.deployts);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
if (options.rollupts) {
|
|
65
|
+
return new RollupTs(options.rollupts);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (options.newreact) {
|
|
69
|
+
return new React(options.newreact);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (options.build) {
|
|
73
|
+
return new Build(options.build);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
program.help();
|
|
77
|
+
//new Script(options.production);
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import js from '@eslint/js'
|
|
2
|
+
import globals from 'globals'
|
|
3
|
+
import reactHooks from 'eslint-plugin-react-hooks'
|
|
4
|
+
import reactRefresh from 'eslint-plugin-react-refresh'
|
|
5
|
+
import tseslint from 'typescript-eslint'
|
|
6
|
+
|
|
7
|
+
export default tseslint.config(
|
|
8
|
+
{ ignores: ['dist'] },
|
|
9
|
+
{
|
|
10
|
+
extends: [js.configs.recommended, ...tseslint.configs.recommended],
|
|
11
|
+
files: ['**/*.{ts,tsx}'],
|
|
12
|
+
languageOptions: {
|
|
13
|
+
ecmaVersion: 2020,
|
|
14
|
+
globals: globals.browser,
|
|
15
|
+
},
|
|
16
|
+
plugins: {
|
|
17
|
+
'react-hooks': reactHooks,
|
|
18
|
+
'react-refresh': reactRefresh,
|
|
19
|
+
},
|
|
20
|
+
rules: {
|
|
21
|
+
...reactHooks.configs.recommended.rules,
|
|
22
|
+
'react-refresh/only-export-components': [
|
|
23
|
+
'warn',
|
|
24
|
+
{ allowConstantExport: true },
|
|
25
|
+
],
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
)
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "vite-react-typescript-starter",
|
|
3
|
+
"private": true,
|
|
4
|
+
"version": "0.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"dev": "vite",
|
|
8
|
+
"build": "vite build",
|
|
9
|
+
"lint": "eslint .",
|
|
10
|
+
"preview": "vite preview"
|
|
11
|
+
},
|
|
12
|
+
"dependencies": {
|
|
13
|
+
"lucide-react": "^0.344.0",
|
|
14
|
+
"react": "^18.3.1",
|
|
15
|
+
"react-dom": "^18.3.1",
|
|
16
|
+
"use-between": "^1.3.5"
|
|
17
|
+
},
|
|
18
|
+
"devDependencies": {
|
|
19
|
+
"@eslint/js": "^9.9.1",
|
|
20
|
+
"@types/react": "^18.3.5",
|
|
21
|
+
"@types/react-dom": "^18.3.0",
|
|
22
|
+
"@vitejs/plugin-react": "^4.3.1",
|
|
23
|
+
"autoprefixer": "^10.4.18",
|
|
24
|
+
"eslint": "^9.9.1",
|
|
25
|
+
"eslint-plugin-react-hooks": "^5.1.0-rc.0",
|
|
26
|
+
"eslint-plugin-react-refresh": "^0.4.11",
|
|
27
|
+
"globals": "^15.9.0",
|
|
28
|
+
"postcss": "^8.4.35",
|
|
29
|
+
"tailwindcss": "^3.4.1",
|
|
30
|
+
"typescript": "^5.5.3",
|
|
31
|
+
"typescript-eslint": "^8.3.0",
|
|
32
|
+
"vite": "^5.4.2"
|
|
33
|
+
}
|
|
34
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
import { useMessageEvent } from './hooks';
|
|
3
|
+
import { User, useUserContext } from './hooks';
|
|
4
|
+
|
|
5
|
+
export default function App() {
|
|
6
|
+
const { updateUser } = useUserContext();
|
|
7
|
+
const { on, off, send } = useMessageEvent();
|
|
8
|
+
|
|
9
|
+
useEffect(() => {
|
|
10
|
+
on('update-user', (data: unknown) => {
|
|
11
|
+
const { user } = data as { user: User };
|
|
12
|
+
if (user) updateUser(user);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
send('ready', {});
|
|
16
|
+
|
|
17
|
+
return () => {
|
|
18
|
+
off('update-user');
|
|
19
|
+
};
|
|
20
|
+
}, []);
|
|
21
|
+
|
|
22
|
+
/* Example
|
|
23
|
+
return (
|
|
24
|
+
<div className="%workspaceName%-flex %workspaceName%-flex-col %workspaceName%-items-center %workspaceName%-justify-center %workspaceName%-h-screen %workspaceName%-bg-gray-100">
|
|
25
|
+
<h1>React Template</h1>
|
|
26
|
+
<p>Esse é um template para começar a usar o React no %workspaceName%.</p>
|
|
27
|
+
<p>Para mais informações, veja a documentação do React.</p>
|
|
28
|
+
<p>Essa é uma aplicação simples, mas você pode expandi-la como quiser.</p>
|
|
29
|
+
</div>
|
|
30
|
+
) */
|
|
31
|
+
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { useState, useEffect, RefObject, useCallback } from 'react';
|
|
2
|
+
|
|
3
|
+
interface Position {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export function useDraggable(elementRef: RefObject<HTMLElement>, handler?: string) {
|
|
9
|
+
const [position, setPosition] = useState<Position>({
|
|
10
|
+
x: window.innerWidth * 0.8 / 2,
|
|
11
|
+
y: window.innerHeight * 0.5 / 2
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
15
|
+
const [dragOffset, setDragOffset] = useState<Position>({ x: 0, y: 0 });
|
|
16
|
+
|
|
17
|
+
const handleMouseDown = useCallback((e: React.MouseEvent) => {
|
|
18
|
+
if (!elementRef.current) return;
|
|
19
|
+
|
|
20
|
+
if (handler && e.target !== elementRef.current.querySelector(handler)) return;
|
|
21
|
+
|
|
22
|
+
const rect = elementRef.current.getBoundingClientRect();
|
|
23
|
+
setDragOffset({
|
|
24
|
+
x: e.clientX - rect.left,
|
|
25
|
+
y: e.clientY - rect.top
|
|
26
|
+
});
|
|
27
|
+
setIsDragging(true);
|
|
28
|
+
}, [elementRef, handler]);
|
|
29
|
+
|
|
30
|
+
const handleMouseMove = useCallback((e: MouseEvent) => {
|
|
31
|
+
if (!isDragging) return;
|
|
32
|
+
|
|
33
|
+
requestAnimationFrame(() => {
|
|
34
|
+
setPosition({
|
|
35
|
+
x: Math.max(0, Math.min(window.innerWidth - (elementRef.current?.offsetWidth || 0), e.clientX - dragOffset.x)),
|
|
36
|
+
y: Math.max(0, Math.min(window.innerHeight - (elementRef.current?.offsetHeight || 0), e.clientY - dragOffset.y))
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
}, [isDragging, dragOffset, elementRef]);
|
|
40
|
+
|
|
41
|
+
const handleMouseUp = useCallback(() => {
|
|
42
|
+
setIsDragging(false);
|
|
43
|
+
}, []);
|
|
44
|
+
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
if (isDragging) {
|
|
47
|
+
window.addEventListener('mousemove', handleMouseMove, { passive: true });
|
|
48
|
+
window.addEventListener('mouseup', handleMouseUp);
|
|
49
|
+
|
|
50
|
+
document.body.style.userSelect = 'none';
|
|
51
|
+
document.body.style.cursor = 'grabbing';
|
|
52
|
+
} else {
|
|
53
|
+
document.body.style.userSelect = '';
|
|
54
|
+
document.body.style.cursor = '';
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return () => {
|
|
58
|
+
window.removeEventListener('mousemove', handleMouseMove);
|
|
59
|
+
window.removeEventListener('mouseup', handleMouseUp);
|
|
60
|
+
document.body.style.userSelect = '';
|
|
61
|
+
document.body.style.cursor = '';
|
|
62
|
+
};
|
|
63
|
+
}, [isDragging, handleMouseMove, handleMouseUp]);
|
|
64
|
+
|
|
65
|
+
return {
|
|
66
|
+
position,
|
|
67
|
+
handleMouseDown
|
|
68
|
+
};
|
|
69
|
+
}
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { useEffect, useCallback, useMemo } from 'react';
|
|
2
|
+
|
|
3
|
+
interface MessageEvent {
|
|
4
|
+
detail: {
|
|
5
|
+
name: string;
|
|
6
|
+
data: string;
|
|
7
|
+
};
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface DisposeEvent {
|
|
11
|
+
detail: {
|
|
12
|
+
allScripts: boolean;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare global {
|
|
17
|
+
interface Window {
|
|
18
|
+
sendScriptMessage: (event: string, data: object) => void;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const workspaceName = "%workspaceName%"
|
|
23
|
+
const isDebbuging = true;
|
|
24
|
+
|
|
25
|
+
export function useMessageEvent() {
|
|
26
|
+
const events = useMemo(() => new Map<string, (data: unknown) => void>(), []);
|
|
27
|
+
|
|
28
|
+
const emit = useCallback((event: MessageEvent) => {
|
|
29
|
+
const { name, data } = event.detail;
|
|
30
|
+
const isMassUpdate = name === `${workspaceName}-mass-update`;
|
|
31
|
+
|
|
32
|
+
let parsedData: unknown = data;
|
|
33
|
+
|
|
34
|
+
if (data !== '' && (data.startsWith('{') && data.endsWith('}') || data.startsWith('[') && data.endsWith(']'))) {
|
|
35
|
+
try {
|
|
36
|
+
parsedData = JSON.parse(data);
|
|
37
|
+
} catch {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
if (isMassUpdate) {
|
|
43
|
+
const eventsData = parsedData as { events: { eventName: string, data?: unknown }[] };
|
|
44
|
+
|
|
45
|
+
if (!eventsData.events) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
eventsData.events.forEach(event => {
|
|
50
|
+
const callback = events.get(event.eventName);
|
|
51
|
+
|
|
52
|
+
if (callback) {
|
|
53
|
+
if (isDebbuging) {
|
|
54
|
+
console.log('Event:', event.eventName);
|
|
55
|
+
console.log('Data:', event.data);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
callback(event.data);
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const callback = events.get(name);
|
|
66
|
+
|
|
67
|
+
if (callback) {
|
|
68
|
+
if (isDebbuging) {
|
|
69
|
+
console.log('Event:', name);
|
|
70
|
+
console.log('Data:', data);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
callback(parsedData);
|
|
74
|
+
}
|
|
75
|
+
}, [events]);
|
|
76
|
+
|
|
77
|
+
const dispose = useCallback((event: DisposeEvent): void => {
|
|
78
|
+
if (!event?.detail?.allScripts) return;
|
|
79
|
+
events.clear();
|
|
80
|
+
}, [events]);
|
|
81
|
+
|
|
82
|
+
const on = useCallback((event: string, callback: (data: unknown) => void): void => {
|
|
83
|
+
events.set(`${workspaceName}-` + event, callback);
|
|
84
|
+
}, [events]);
|
|
85
|
+
|
|
86
|
+
const off = useCallback((event: string): void => {
|
|
87
|
+
events.delete(`${workspaceName}-` + event);
|
|
88
|
+
}, [events]);
|
|
89
|
+
|
|
90
|
+
const send = useCallback((event: string, data: object): void => {
|
|
91
|
+
try {
|
|
92
|
+
window.sendScriptMessage(`${workspaceName}-` + event, data);
|
|
93
|
+
}
|
|
94
|
+
catch {
|
|
95
|
+
// empty
|
|
96
|
+
}
|
|
97
|
+
}, []);
|
|
98
|
+
|
|
99
|
+
useEffect(() => {
|
|
100
|
+
const scriptEvents = document.getElementById('script-events');
|
|
101
|
+
if (scriptEvents) {
|
|
102
|
+
scriptEvents.addEventListener('uiMessage', emit as unknown as EventListener);
|
|
103
|
+
scriptEvents.addEventListener('dispose', dispose as unknown as EventListener);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
return () => {
|
|
107
|
+
if (scriptEvents) {
|
|
108
|
+
scriptEvents.removeEventListener('uiMessage', emit as unknown as EventListener);
|
|
109
|
+
scriptEvents.removeEventListener('dispose', dispose as unknown as EventListener);
|
|
110
|
+
events.clear();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
}, [emit, dispose, events]);
|
|
114
|
+
|
|
115
|
+
return {
|
|
116
|
+
on,
|
|
117
|
+
off,
|
|
118
|
+
send
|
|
119
|
+
};
|
|
120
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { useState } from 'react';
|
|
2
|
+
import { useBetween } from 'use-between';
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
export interface User {
|
|
6
|
+
name: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const useUserContextState = () => {
|
|
10
|
+
const [user, setUser] = useState<User>({
|
|
11
|
+
name: ''
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
const updateUser = (newUser: Partial<User>) => {
|
|
15
|
+
setUser((prevUser: User) => ({
|
|
16
|
+
...prevUser,
|
|
17
|
+
...newUser,
|
|
18
|
+
}));
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
return { user, updateUser };
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
export const useUserContext = () => useBetween(useUserContextState);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
/// <reference types="vite/client" />
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2020",
|
|
4
|
+
"useDefineForClassFields": true,
|
|
5
|
+
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
|
6
|
+
"module": "ESNext",
|
|
7
|
+
"skipLibCheck": true,
|
|
8
|
+
|
|
9
|
+
/* Bundler mode */
|
|
10
|
+
"moduleResolution": "bundler",
|
|
11
|
+
"allowImportingTsExtensions": true,
|
|
12
|
+
"isolatedModules": true,
|
|
13
|
+
"moduleDetection": "force",
|
|
14
|
+
"noEmit": true,
|
|
15
|
+
"jsx": "react-jsx",
|
|
16
|
+
|
|
17
|
+
/* Linting */
|
|
18
|
+
"strict": true,
|
|
19
|
+
"noUnusedLocals": true,
|
|
20
|
+
"noUnusedParameters": true,
|
|
21
|
+
"noFallthroughCasesInSwitch": true
|
|
22
|
+
},
|
|
23
|
+
"include": ["src"]
|
|
24
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"lib": ["ES2023"],
|
|
5
|
+
"module": "ESNext",
|
|
6
|
+
"skipLibCheck": true,
|
|
7
|
+
|
|
8
|
+
/* Bundler mode */
|
|
9
|
+
"moduleResolution": "bundler",
|
|
10
|
+
"allowImportingTsExtensions": true,
|
|
11
|
+
"isolatedModules": true,
|
|
12
|
+
"moduleDetection": "force",
|
|
13
|
+
"noEmit": true,
|
|
14
|
+
|
|
15
|
+
/* Linting */
|
|
16
|
+
"strict": true,
|
|
17
|
+
"noUnusedLocals": true,
|
|
18
|
+
"noUnusedParameters": true,
|
|
19
|
+
"noFallthroughCasesInSwitch": true
|
|
20
|
+
},
|
|
21
|
+
"include": ["vite.config.ts"]
|
|
22
|
+
}
|