Skip to content

Commit

Permalink
typescript code
Browse files Browse the repository at this point in the history
  • Loading branch information
DileSoft committed Jun 25, 2024
1 parent 62a002a commit 93f2b1a
Show file tree
Hide file tree
Showing 24 changed files with 60 additions and 46 deletions.
9 changes: 4 additions & 5 deletions packages/iobroker.vis-2/src/src/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
import { DndProvider, useDrop } from 'react-dnd';
import { TouchBackend } from 'react-dnd-touch-backend';
import { HTML5Backend } from 'react-dnd-html5-backend';
import ReactSplit, { SplitDirection, GutterTheme } from '@devbookhq/splitter';
import ReactSplit, { SplitDirection } from '@devbookhq/splitter';

import {
IconButton, Paper, Popper, Tab, Tabs, Tooltip, LinearProgress, Button,
Expand Down Expand Up @@ -38,7 +38,6 @@ import {
import type {
AnyWidgetId, GroupData, GroupWidget, GroupWidgetId, MarketplaceWidgetRevision, Project, RxWidgetInfoGroup, SingleWidget, SingleWidgetId, ViewSettings, Widget, WidgetData, WidgetSetName, WidgetStyle,
} from '@iobroker/types-vis-2';
import { View } from '@iobroker/types-vis-2';
import { recalculateFields, store, updateProject } from './Store';
import {
isGroup, getNewWidgetId, getNewGroupId, pasteGroup, unsyncMultipleWidgets, deepClone, pasteSingleWidget,
Expand All @@ -60,7 +59,6 @@ import { findWidgetUsages } from './Vis/visUtils';
import type { MarketplaceDialogProps } from './Marketplace/MarketplaceDialog';
import MarketplaceDialog from './Marketplace/MarketplaceDialog';
import type { VisEngineHandlers } from './Vis/visView';
import VisEngine from './Vis/visEngine';

const generateClassName = createGenerateClassName({
productionPrefix: 'vis-e',
Expand Down Expand Up @@ -179,7 +177,9 @@ const styles: Styles<IobTheme & {classes: Record<string, CSSProperties>}, any> =
});

interface ViewDropProps {
// eslint-disable-next-line no-use-before-define
addMarketplaceWidget: EditorClass['addMarketplaceWidget'];
// eslint-disable-next-line no-use-before-define
addWidget: EditorClass['addWidget'];
editMode: boolean;
children: React.JSX.Element;
Expand Down Expand Up @@ -1526,6 +1526,7 @@ class Editor extends Runtime<EditorProps, EditorState> {
return null;
}

// eslint-disable-next-line no-shadow
askAboutInclude = (wid: AnyWidgetId, toWid: AnyWidgetId, cb: (wid: AnyWidgetId, toWid: AnyWidgetId) => void) =>
this.setState({ askAboutInclude: { wid, toWid, cb } });

Expand Down Expand Up @@ -1678,7 +1679,6 @@ class Editor extends Runtime<EditorProps, EditorState> {
updateWidgets={this.updateWidgets}
selectedView={this.state.selectedView}
changeView={this.changeView}
project={store.getState().visProject}
changeProject={this.changeProject}
socket={this.socket as unknown as LegacyConnection}
editMode={this.state.editMode}
Expand Down Expand Up @@ -1724,7 +1724,6 @@ class Editor extends Runtime<EditorProps, EditorState> {
pasteWidgets={this.pasteWidgets}
orderWidgets={this.orderWidgets}
widgetsClipboard={this.state.widgetsClipboard}
project={store.getState().visProject}
selectedView={this.state.selectedView}
changeProject={this.changeProject}
lockWidgets={this.lockWidgets}
Expand Down
4 changes: 1 addition & 3 deletions packages/iobroker.vis-2/src/src/Palette/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,12 @@ import type {
ThemeType,
} from '@iobroker/adapter-react-v5';

import type { Marketplace, MarketplaceWidgetRevision, Project } from '@iobroker/types-vis-2';
import type { Marketplace, MarketplaceWidgetRevision } from '@iobroker/types-vis-2';
import { store } from '@/Store';

import type { WidgetType } from '@/Vis/visWidgetsCatalog';
import { getWidgetTypes } from '@/Vis/visWidgetsCatalog';
import { loadComponent } from '@/Vis/visLoadWidgets';
import type { MarketplaceDialogProps } from '@/Marketplace/MarketplaceDialog';
import type { EditorClass } from '../Editor';
import Widget from './Widget';
import MarketplacePalette from '../Marketplace/MarketplacePalette';
Expand Down Expand Up @@ -172,7 +171,6 @@ interface PaletteProps {
themeType: ThemeType;
editMode: boolean;
selectedView: string;
project: Project;
}

interface PaletteState {
Expand Down
4 changes: 1 addition & 3 deletions packages/iobroker.vis-2/src/src/Runtime.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ import type { GenericAppProps, GenericAppState, ThemeName } from '@iobroker/adap
import type {
AnyWidgetId, GroupWidgetId, Project, SingleWidgetId, ViewSettings, VisTheme, WidgetData, WidgetStyle,
} from '@iobroker/types-vis-2';
import {
GroupWidget, SingleWidget, View, Widget,
} from '@iobroker/types-vis-2';
import VisEngine from './Vis/visEngine';
import {
extractBinding,
Expand Down Expand Up @@ -171,6 +168,7 @@ class Runtime<P extends RuntimeProps = RuntimeProps, S extends RuntimeState = Ru

onIgnoreMouseEvents: (ignore: boolean) => void;

// eslint-disable-next-line no-shadow
askAboutInclude: (wid: AnyWidgetId, toWid: AnyWidgetId, cb: (wid: AnyWidgetId, toWid: AnyWidgetId) => void) => void;

showConfirmDialog?(dialog: {
Expand Down
5 changes: 5 additions & 0 deletions packages/iobroker.vis-2/src/src/Toolbar/ToolbarItems.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ export interface TextFieldToolbarItem extends BaseToolbarItem {

export type ToolbarItem = SelectToolbarItem | MultiselectToolbarItem | CheckboxToolbarItem | IconButtonToolbarItem | TextToolbarItem | ButtonToolbarItem | DividerToolbarItem | TextFieldToolbarItem;

// eslint-disable-next-line no-use-before-define
const getItem = (item: ToolbarItem, key: number, props: ToolbarItemsProps, full?: boolean) => {
const { visProject } = store.getState();
const view = visProject[props.selectedView];
Expand Down Expand Up @@ -302,12 +303,16 @@ const getItem = (item: ToolbarItem, key: number, props: ToolbarItemsProps, full?

interface ToolbarItemsProps {
classes: Record<string, string>;
// eslint-disable-next-line react/no-unused-prop-types
themeType: ThemeType;
group: { name: string | React.JSX.Element; doNotTranslateName?: boolean; items: (ToolbarItem[][] | ToolbarItem[] | ToolbarItem)[] };
last?: boolean;
toolbarHeight: 'full' | 'narrow' | 'veryNarrow';
// eslint-disable-next-line react/no-unused-prop-types
changeProject: EditorClass['changeProject'];
// eslint-disable-next-line react/no-unused-prop-types
selectedView: string;
// eslint-disable-next-line react/no-unused-prop-types
setSelectedWidgets: EditorClass['setSelectedWidgets'];
}

Expand Down
4 changes: 3 additions & 1 deletion packages/iobroker.vis-2/src/src/Toolbar/Views.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ interface ViewsProps {

const Views = (props: ViewsProps) => {
const [dialog, setDialog] = useState(null);
const [dialogCallback, setDialogCallback] = useState<{ cb:(dialogName: string) => void }>(null);
// eslint-disable-next-line no-spaced-func, func-call-spacing
const [dialogCallback, setDialogCallback] = useState<{ cb: (dialogName: string) => void }>(null);
const [dialogName, setDialogName] = useState('');
const [dialogView, setDialogView] = useState(null);
const [dialogParentId, setDialogParentId] = useState(null);
Expand All @@ -65,6 +66,7 @@ const Views = (props: ViewsProps) => {
type: 'add' | 'rename' | 'delete' | 'copy',
view?: string,
parentId?: string,
// eslint-disable-next-line no-shadow
cb?: (dialogName: string) => void,
) => {
view = view || props.selectedView;
Expand Down
4 changes: 3 additions & 1 deletion packages/iobroker.vis-2/src/src/Toolbar/Widgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,11 @@ const Widgets: React.FC<WidgetsProps> = props => {
const [importDialog, setImportDialog] = useState(false);
const [filterDialog, setFilterDialog] = useState(false);

// eslint-disable-next-line no-spaced-func
const toolbar = useMemo<{
name: string;
items:(ToolbarItem | ToolbarItem[] | ToolbarItem[][])[];
// eslint-disable-next-line func-call-spacing
items: (ToolbarItem | ToolbarItem[] | ToolbarItem[][])[];
}>(() => {
const project = store.getState().visProject;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

import React from 'react';
import PropTypes from 'prop-types';

// eslint-disable-next-line import/no-cycle
import type { GetRxDataFromWidget, RxRenderWidgetProps } from '@iobroker/types-vis-2';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

import React from 'react';
import PropTypes from 'prop-types';

// eslint-disable-next-line import/no-cycle
import type { GetRxDataFromWidget, RxRenderWidgetProps } from '@iobroker/types-vis-2';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
*/

import React from 'react';
import PropTypes from 'prop-types';

import { Icon } from '@iobroker/adapter-react-v5';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import type { CSSProperties } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import {
DialogContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,11 @@

import type { CSSProperties } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import { I18n } from '@iobroker/adapter-react-v5';

// eslint-disable-next-line import/no-cycle
import type { GetRxDataFromWidget, RxRenderWidgetProps, RxWidgetInfoGroup } from '@iobroker/types-vis-2';
import type { RxRenderWidgetProps, RxWidgetInfoGroup } from '@iobroker/types-vis-2';
import VisRxWidget from '../../visRxWidget';

interface RxData {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import type { CSSProperties } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import {
Button,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import type { CSSProperties } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import {
Button,
Expand All @@ -37,7 +36,7 @@ import {
import type { VisBaseWidgetProps, VisWidgetCommand } from '@/Vis/visBaseWidget';
import VisBaseWidget from '@/Vis/visBaseWidget';
import type {
GetRxDataFromWidget, RxRenderWidgetProps, RxWidgetInfo, RxWidgetInfoAttributesField,
RxRenderWidgetProps, RxWidgetInfo, RxWidgetInfoAttributesField,
RxWidgetInfoWriteable,
Writeable,
} from '@iobroker/types-vis-2';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,11 @@
* Licensees may copy, distribute, display, and perform the work and make derivative works based on it only for noncommercial purposes.
* (Free for non-commercial use).
*/
import PropTypes from 'prop-types';

// eslint-disable-next-line import/no-cycle
import type { RxWidgetInfoAttributesFieldText, RxWidgetInfoWriteable } from '@iobroker/types-vis-2';
import {
type RxWidgetInfo, type RxWidgetInfoAttributesField, type RxWidgetInfoAttributesFieldCheckbox, type RxWidgetInfoAttributesFieldSelect,
type RxWidgetInfo, type RxWidgetInfoAttributesFieldCheckbox, type RxWidgetInfoAttributesFieldSelect,
type RxWidgetInfoAttributesFieldText, type RxWidgetInfoWriteable,
} from '@iobroker/types-vis-2';
import JQuiButton from './JQuiButton';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import type { CSSProperties } from 'react';
import React from 'react';
import PropTypes from 'prop-types';

import {
Autocomplete,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@
* Licensees may copy, distribute, display, and perform the work and make derivative works based on it only for noncommercial purposes.
* (Free for non-commercial use).
*/
import PropTypes from 'prop-types';

// eslint-disable-next-line import/no-cycle
import type {
RxWidgetInfo, RxWidgetInfoAttributesFieldCheckbox, RxWidgetInfoAttributesFieldDefault, RxWidgetInfoAttributesFieldText, RxWidgetInfoWriteable,
} from '@iobroker/types-vis-2';
import type { RxWidgetInfoAttributesFieldAll } from '@/Vis/visWidgetsCatalog';
import JQuiButton from './JQuiButton';

class JQuiButtonNavigation extends JQuiButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
* Licensees may copy, distribute, display, and perform the work and make derivative works based on it only for noncommercial purposes.
* (Free for non-commercial use).
*/
import PropTypes from 'prop-types';

// eslint-disable-next-line import/no-cycle
import { RxWidgetInfo, RxWidgetInfoAttributesFieldCheckbox, RxWidgetInfoAttributesFieldDefault, RxWidgetInfoAttributesFieldText, type RxWidgetInfoWriteable } from '@iobroker/types-vis-2';
import type {
RxWidgetInfo, RxWidgetInfoAttributesFieldCheckbox, RxWidgetInfoAttributesFieldDefault, RxWidgetInfoAttributesFieldText,
RxWidgetInfoWriteable,
} from '@iobroker/types-vis-2';
import JQuiButton from './JQuiButton';

class JQuiButtonPasswordNavigation extends JQuiButton {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@
* Licensees may copy, distribute, display, and perform the work and make derivative works based on it only for noncommercial purposes.
* (Free for non-commercial use).
*/
import PropTypes from 'prop-types';

// eslint-disable-next-line import/no-cycle
import type {
RxWidgetInfo, RxWidgetInfoAttributesFieldDefault, RxWidgetInfoAttributesFieldText, RxWidgetInfoWriteable,
} from '@iobroker/types-vis-2';
import JQuiButton from './JQuiButton';
import { RxWidgetInfo, RxWidgetInfoAttributesFieldDefault, RxWidgetInfoAttributesFieldText, RxWidgetInfoWriteable } from '@iobroker/types-vis-2';

class JQuiContainerButtonDialog extends JQuiButton {
static getWidgetInfo() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import type {
RxRenderWidgetProps,
RxWidgetInfo,
RxWidgetInfoAttributesField,
RxWidgetInfoWriteable,
Writeable,
} from '@iobroker/types-vis-2';

import VisBaseWidget from '@/Vis/visBaseWidget';
Expand Down Expand Up @@ -270,7 +272,7 @@ class JQuiWriteState extends VisRxWidget<RxData, JQuiWriteStateState> {
}
}

static findField(widgetInfo: RxWidgetInfo, name: string): RxWidgetInfoAttributesField | null {
static findField(widgetInfo: RxWidgetInfo | RxWidgetInfoWriteable, name: string): Writeable<RxWidgetInfoAttributesField> | null {
return VisRxWidget.findField(widgetInfo, name);
}

Expand Down
9 changes: 8 additions & 1 deletion packages/iobroker.vis-2/src/src/Vis/visBaseWidget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
this.refService.current.style.cursor = 'crosshair';
this.refService.current.className = addClass(this.refService.current.className, 'vis-editmode-steal-style');
}
// eslint-disable-next-line no-undef
const resizers = this.refService.current?.querySelectorAll('.vis-editmode-resizer') as NodeListOf<HTMLDivElement>;
resizers?.forEach(item => item.style.display = 'none');
return true;
Expand All @@ -332,6 +333,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
if (this.refService.current) {
this.refService.current.className = removeClass(this.refService.current.className, 'vis-editmode-steal-style');
}
// eslint-disable-next-line no-undef
const resizers = this.refService.current?.querySelectorAll('.vis-editmode-resizer') as NodeListOf<HTMLDivElement>;
resizers?.forEach(item => item.style.display = '');
return true;
Expand Down Expand Up @@ -369,6 +371,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
}

// show resizers again
// eslint-disable-next-line no-undef
const resizers = this.refService.current?.querySelectorAll('.vis-editmode-resizer') as NodeListOf<HTMLDivElement>;
resizers?.forEach(item => item.style.display = 'block');

Expand Down Expand Up @@ -712,6 +715,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
height: rect.height,
};
}
// eslint-disable-next-line no-undef
const resizers = this.refService.current.querySelectorAll('.vis-editmode-resizer') as NodeListOf<ResizerElement>;
resizers.forEach(item => {
item._storedOpacity = item.style.opacity;
Expand Down Expand Up @@ -846,6 +850,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt

// end of resize
if (save) {
// eslint-disable-next-line no-undef
const resizers = this.refService.current?.querySelectorAll('.vis-editmode-resizer') as NodeListOf<HTMLDivElementResizers>;
resizers?.forEach(item => {
if (item._storedOpacity !== undefined) {
Expand Down Expand Up @@ -882,6 +887,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
};

// hide resizers
// eslint-disable-next-line no-undef
const resizers = this.refService.current.querySelectorAll('.vis-editmode-resizer') as NodeListOf<HTMLDivElement>;
resizers.forEach(item => item.style.display = 'none');

Expand Down Expand Up @@ -918,6 +924,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
// End of movement
if (save) {
// show resizers
// eslint-disable-next-line no-undef
const resizers = this.refService.current.querySelectorAll('.vis-editmode-resizer') as NodeListOf<HTMLDivElement>;
resizers.forEach(item => item.style.display = 'block');

Expand Down Expand Up @@ -1301,7 +1308,7 @@ class VisBaseWidget<TState extends Partial<VisBaseWidgetState> = VisBaseWidgetSt
*
* @param _props
*/
// eslint-disable-next-line class-methods-use-this,no-unused-vars
// eslint-disable-next-line class-methods-use-this,no-unused-vars, @typescript-eslint/no-unused-vars
renderWidgetBody(_props: RxRenderWidgetProps): React.JSX.Element | null {
// Default render method. Normally it should be overwritten
return <div
Expand Down
1 change: 0 additions & 1 deletion packages/iobroker.vis-2/src/src/Vis/visContextMenu.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ interface VisContextMenuProps {
widgetsClipboard: Record<string, any>;
themeType: 'dark' | 'light';
setMarketplaceDialog: EditorClass['setMarketplaceDialog'];
project: Project;
}

export interface VisMarketplaceProps {
Expand Down
Loading

0 comments on commit 93f2b1a

Please sign in to comment.