Skip to content

Commit

Permalink
vite typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
DileSoft committed Dec 12, 2024
1 parent a489f6a commit fbd69fc
Show file tree
Hide file tree
Showing 14 changed files with 70 additions and 58 deletions.
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,7 @@
"dependencies": {
"@iobroker/adapter-core": "^3.2.3",
"@iobroker/types": "^6.0.11",
"@module-federation/runtime": "^0.8.2",
"@module-federation/vite": "^1.1.9",

"@types/node": "^22.10.1",
"@types/request": "^2.48.12",
"axios": "^1.7.9",
Expand Down
3 changes: 3 additions & 0 deletions src-editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
"@esbuild-plugins/node-globals-polyfill": "^0.2.3",
"@iobroker/adapter-react-v5": "^7.4.4",
"@iobroker/type-detector": "^4.1.0",
"@module-federation/runtime": "^0.8.2",
"@module-federation/vite": "^1.1.9",
"@mui/icons-material": "^6.2.0",
"@mui/material": "^6.2.0",
"@mui/x-date-pickers": "^7.23.1",
Expand Down Expand Up @@ -57,6 +59,7 @@
"start": "vite",
"lint": "eslint -c eslint.config.mjs",
"build": "tsc && vite build",
"preview": "vite preview --port 3000",
"tsc": "tsc -p tsconfig.json",
"npm": "npm i -f"
},
Expand Down
48 changes: 24 additions & 24 deletions src-editor/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,17 @@ import { ContextWrapper } from './Components/RulesEditor/components/ContextWrapp
import { Box } from '@mui/material';
import type { GenericAppProps, GenericAppState } from '@iobroker/adapter-react-v5/build/types';

import enLang from './i18n/en.json';
import deLang from './i18n/de.json';
import esLang from './i18n/es.json';
import frLang from './i18n/fr.json';
import itLang from './i18n/it.json';
import nlLang from './i18n/nl.json';
import plLang from './i18n/pl.json';
import ptLang from './i18n/pt.json';
import ruLang from './i18n/ru.json';
import ukLang from './i18n/uk.json';
import zhCnLang from './i18n/zh-cn.json';
// import enLang from './i18n/en.json';
// import deLang from './i18n/de.json';
// import esLang from './i18n/es.json';
// import frLang from './i18n/fr.json';
// import itLang from './i18n/it.json';
// import nlLang from './i18n/nl.json';
// import plLang from './i18n/pl.json';
// import ptLang from './i18n/pt.json';
// import ruLang from './i18n/ru.json';
// import ukLang from './i18n/uk.json';
// import zhCnLang from './i18n/zh-cn.json';
import type { ScriptType } from '@/types';

const styles: Record<string, any> = {
Expand Down Expand Up @@ -173,17 +173,17 @@ class App extends GenericApp<AppProps, AppState> {
// @ts-expect-error fix later
Connection: AdminConnection,
translations: {
en: enLang,
de: deLang,
es: esLang,
fr: frLang,
it: itLang,
nl: nlLang,
pl: plLang,
pt: ptLang,
ru: ruLang,
uk: ukLang,
'zh-cn': zhCnLang,
// en: enLang,
// de: deLang,
// es: esLang,
// fr: frLang,
// it: itLang,
// nl: nlLang,
// pl: plLang,
// pt: ptLang,
// ru: ruLang,
// uk: ukLang,
// 'zh-cn': zhCnLang,
},
bottomButtons: false,
socket: {
Expand Down Expand Up @@ -549,7 +549,7 @@ class App extends GenericApp<AppProps, AppState> {
}
nId = newId + nId.substring(id.length);
obj._id = nId;
obj.common = obj.common || {};
obj.common = obj.common || {} as ioBroker.StateCommon;
obj.common.expert = true;
await this.socket.setObject(nId, obj);
await this.renameGroup(id, newId, newName, _list);
Expand Down Expand Up @@ -687,7 +687,7 @@ class App extends GenericApp<AppProps, AppState> {
if (oldId === newId && _obj?.common && newCommon.name === _obj.common.name) {
if (!newCommon.engineType || newCommon.engineType !== _obj.common.engineType) {
if (newCommon.engineType !== undefined) {
obj.common.engineType = newCommon.engineType || 'Javascript/js';
obj.common.engineType = newCommon.engineType || 'JavaScript/js';
}
}
obj.type = 'script';
Expand Down
2 changes: 1 addition & 1 deletion src-editor/src/Components/BlocklyEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class BlocklyEditor extends React.Component<BlocklyEditorProps, BlocklyEditorSta
return xmlDoc;
};
} else {
parseXml = () => null;
parseXml = ():null => null;
}
return parseXml(text);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ import { GenericBlock, type GenericBlockProps } from '../GenericBlock';
import type { RuleBlockConfigActionSayText, RuleBlockDescription, RuleContext } from '@/Components/RulesEditor/types';

// copied from https://github.com/ioBroker/ioBroker.sayit/blob/master/admin/blockly.js#L37
const sayitEngines = {
const sayitEngines: Record<string,
{ name: string; engine: string; params: string[];
voice?: string[]; emotion?: string[]; language?: string; ename?: string; ssml?: boolean;
gender?: string;
}>
= {
en: { name: 'Google - English', engine: 'google', params: [] },
de: { name: 'Google - Deutsch', engine: 'google', params: [] },
ru: { name: 'Google - Русский', engine: 'google', params: [] },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ class TriggerScheduleBlock extends GenericBlock<RuleBlockConfigTriggerSchedule,
onChange={(schedule, description) => {
wizardText = description || '';
const wizardObj: ScheduleConfig = JSON.parse(schedule) as ScheduleConfig;
wizardObj.valid = wizardObj.valid || {};
wizardObj.valid = wizardObj.valid || {} as any;
wizardObj.valid.from = wizardObj.valid.from || Schedule.now2string();
wizard = JSON.stringify(wizardObj);
}}
Expand Down Expand Up @@ -436,7 +436,7 @@ class TriggerScheduleBlock extends GenericBlock<RuleBlockConfigTriggerSchedule,

case 'wizard': {
const wizard: ScheduleConfig = JSON.parse(DEFAULT_WIZARD);
wizard.valid = wizard.valid || {};
wizard.valid = wizard.valid || {} as any;
wizard.valid.from = wizard.valid.from || Schedule.now2string();

this.setState(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,23 +155,23 @@ export const ContextWrapper = ({ children, socket }: { socket: AdminConnection;

let url;
if (
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
obj.common.javascriptRules.url.startsWith('http:') ||
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
obj.common.javascriptRules.url.startsWith('https:')
) {
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
url = obj.common.javascriptRules.url;
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
} else if (obj.common.javascriptRules.url.startsWith('./')) {
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
url = `${window.location.protocol}//${window.location.host}${obj.common.javascriptRules.url.replace(/^\./, '')}`;
} else {
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
url = `${window.location.protocol}//${window.location.host}/adapter/${obj.common.name}/${obj.common.javascriptRules.url}`;
}

// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
if (obj.common.javascriptRules.i18n === true) {
// load i18n from files
const pos: number = url.lastIndexOf('/');
Expand All @@ -197,24 +197,24 @@ export const ContextWrapper = ({ children, socket }: { socket: AdminConnection;
}
console.log(`Cannot load i18n "${file}": ${error}`);
});
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
} else if (obj.common.javascriptRules.i18n && typeof obj.common.javascriptRules.i18n === 'object') {
try {
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
I18n.extendTranslations(obj.common.javascriptRules.i18n);
} catch (error) {
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
console.error(`Cannot import i18n for "${obj.common.javascriptRules.name}": ${error}`);
}
}

try {
const Component = (
await loadComponent(
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
obj.common.javascriptRules.name,
'default',
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
`./${obj.common.javascriptRules.name}`,
url,
)()
Expand All @@ -226,7 +226,7 @@ export const ContextWrapper = ({ children, socket }: { socket: AdminConnection;
ADAPTERS[obj.common.name] = null;
}
} catch (e) {
// @ts-expect-error javascriptRules in js-controller
// @#ts-expect-error javascriptRules in js-controller
console.error(`Cannot load component "${obj.common.javascriptRules.name}": ${e}`);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ export abstract class GenericBlock<

protected constructor(props: GenericBlockProps<Settings>, item: RuleBlockDescription) {
super(props);
item = item || {};
item = item || {} as any;
const settings: Settings =
props.settings ||
({
Expand Down Expand Up @@ -502,7 +502,7 @@ export abstract class GenericBlock<
return this.props.socket
.getObject(newId)
.then(o => this.findIcon(o))
.catch(() => null);
.catch((): any => null);
}
return Promise.resolve(null);
}
Expand Down
2 changes: 1 addition & 1 deletion src-editor/src/Components/RulesEditor/helpers/utils.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export function getName(obj: undefined | ioBroker.StringOrTranslated | null): st
if (obj && typeof obj === 'object') {
return obj[lang] || obj.en;
}
return obj || '';
return obj as string || '';
}

export function renderValue(val: any): string {
Expand Down
21 changes: 11 additions & 10 deletions src-editor/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class Editor extends React.Component<EditorProps, EditorState> {
}
this.selectId.callback = cb as (selected: string | string[] | undefined) => void;
this.selectId.initValue = initValue;
this.selectId.type = type;
this.selectId.type = type as any;
this.setState({ showSelectId: true });
},
cronDialog: (initValue, cb) => {
Expand Down Expand Up @@ -827,11 +827,11 @@ class Editor extends React.Component<EditorProps, EditorState> {
const common = this.scripts[selected] || (this.props.objects[selected] && this.props.objects[selected].common);
this.setState({
selected,
rules: common.engineType === 'Rules',
blockly: common.engineType === 'Blockly',
rules: (common as any).engineType === 'Rules',
blockly: (common as any).engineType === 'Blockly',
showCompiledCode: false,
verboseEnabled: common.verbose,
debugEnabled: common.debug,
verboseEnabled: (common as any).verbose,
debugEnabled: (common as any).debug,
});
this.props.onSelectedChange && this.props.onSelectedChange(selected, this.state.editing);
}
Expand Down Expand Up @@ -883,10 +883,10 @@ class Editor extends React.Component<EditorProps, EditorState> {
newState.selected &&
(this.scripts[newState.selected] ||
(this.props.objects[newState.selected] && this.props.objects[newState.selected].common));
newState.blockly = common ? common.engineType === 'Blockly' : false;
newState.rules = common ? common.engineType === 'Rules' : false;
newState.verboseEnabled = common ? common.verbose : false;
newState.debugEnabled = common ? common.debug : false;
newState.blockly = common ? (common as any).engineType === 'Blockly' : false;
newState.rules = common ? (common as any).engineType === 'Rules' : false;
newState.verboseEnabled = common ? (common as any).verbose : false;
newState.debugEnabled = common ? (common as any).debug : false;
newState.showCompiledCode = false;
}

Expand Down Expand Up @@ -1993,10 +1993,11 @@ class Editor extends React.Component<EditorProps, EditorState> {
runningInstances={this.state.runningInstances}
adapterName={this.props.adapterName}
socket={this.props.socket}
// @ts-expect-error fix later
theme={this.props.theme}
themeName={this.props.themeName}
themeType={this.props.themeType}
// @ts-expect-error fix later
// @#ts-expect-error fix later
src={this.props.debugInstance ? this.props.debugInstance.adapter : this.state.selected}
debugInstance={this.props.debugInstance}
/>
Expand Down
1 change: 1 addition & 0 deletions src-editor/src/OpenAi/OpenAiDialog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ Do not import any libraries as all functions are already imported.`,
],
});
const message = chatCompletionPhase1.choices[0].message;
// @ts-expect-error
const m = message.content?.match(/```(javascript|js|typescript)\n?(.*)```(.*)/ms);
let code;
if (!m) {
Expand Down
3 changes: 2 additions & 1 deletion src-editor/src/OpenAi/OpenAiPrompt.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ChannelDetector, { type DetectOptions, Types } from '@iobroker/type-detector';
import { type AdminConnection, I18n } from '@iobroker/adapter-react-v5';
import type { PatternControl } from '@iobroker/type-detector';
// @ts-expect-error
const docs = import(`./docs.md?raw`);

interface DeviceState {
Expand Down Expand Up @@ -65,7 +66,7 @@ function getText(text: ioBroker.StringOrTranslated, lang: ioBroker.Languages): s
if (text && typeof text === 'object') {
return text[lang] || text.en;
}
return text || '';
return text as string || '';
}

async function detectDevices(socket: AdminConnection): Promise<DeviceObject[]> {
Expand Down
2 changes: 2 additions & 0 deletions src-editor/src/bootstrap.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ import { createRoot } from 'react-dom/client';

import './index.css';
import App from './App';
// @ts-expect-error
import * as serviceWorker from './serviceWorker';
// @ts-expect-error
import pgk from '../package.json';
import { DndProvider } from 'react-dnd';
import { HTML5Backend } from 'react-dnd-html5-backend';
Expand Down
2 changes: 1 addition & 1 deletion src-editor/vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export default defineConfig({
name: 'iobroker_javascript',
remotes: {
},
shared: makeShared([
shared: ([
'react', 'react-dom', '@mui/material', '@mui/styles', '@mui/icons-material', 'prop-types', '@iobroker/adapter-react-v5', 'react-ace',
]),
})
Expand Down

0 comments on commit fbd69fc

Please sign in to comment.