Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor code smells #255

Open
wants to merge 23 commits into
base: feature/renewal
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c7a32dc
Added onInteraction callback props
salgum1114 Sep 27, 2022
6511587
Added .npmrc legacy-peer-deps
salgum1114 Sep 27, 2022
80622da
Bug fix
salgum1114 Oct 11, 2022
8517e54
Change the size limit of FileUpload to 100mb
salgum1114 Sep 7, 2023
6f03098
feat: add a canvas save description
henoktx Nov 2, 2023
af237a9
feat: update image map header toolbar image icon description
henoktx Nov 2, 2023
c1d15a5
refactor: remove BoxProps interface declaration 'any type' smell by s…
henoktx Nov 14, 2023
ece8d8b
refactor: remove 'any type' smell in 'newSytle' const by cast 'Object…
henoktx Nov 14, 2023
5acd200
refactor: remove 'any type' smell in App declaration by removing 'any…
henoktx Nov 14, 2023
fbe5991
refactor: remove 'any type' smell in 'newSytle' const by cast 'Object…
henoktx Nov 14, 2023
5c4416d
feat: add work flow descriptors class
henoktx Nov 14, 2023
96fb49e
refactor: remove 'any type' smell in handdleAddNode, renderItems and …
henoktx Nov 14, 2023
5300c18
refactor: remove 'any type' smell in WorkFlowEditor class in containe…
henoktx Nov 14, 2023
d48c45e
refactor: remove 'JSX outside the method render' smell by extract ren…
henoktx Nov 14, 2023
860551a
refactor: remove 'JSX outside the method render' smell by moving rend…
henoktx Nov 14, 2023
c7e18bf
refactor: remove 'JSX outside the method render' smell by extract met…
henoktx Nov 15, 2023
0224507
refactor: remove 'JSX outside the method render' smell by extract met…
henoktx Nov 15, 2023
9b63251
refactor: refactor too many props and large component smell by not de…
henoktx Nov 27, 2023
01235f8
refactor: refactor too many props and large component smell by add So…
henoktx Nov 27, 2023
4d49b6d
refactor: refactor too many props and large component smell by create…
henoktx Nov 27, 2023
9943c1e
refactor: refactor too many props and large component smell by create…
henoktx Nov 27, 2023
b788935
refactor: refactor too many props and large component smell by not de…
henoktx Nov 27, 2023
a273627
refactor: update title import and component name
henoktx Nov 27, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .npmrc
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
package-lock=false
package-lock=false
legacy-peer-deps=true
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-design-editor",
"version": "0.0.50",
"version": "0.0.53",
"description": "Design Editor Tools with React.js + ant.design + fabric.js",
"main": "dist/react-design-editor.min.js",
"typings": "lib/index.d.ts",
Expand Down
6 changes: 3 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { Helmet } from 'react-helmet';
import Title from './components/layout/Title';
import TitleBar from './components/layout/TitleBar';
import FlowContainer from './containers/FlowContainer';
import { FiberEditor, FlowEditor, HexGridEditor, ImageMapEditor, WorkflowEditor } from './editors';

Expand All @@ -10,7 +10,7 @@ interface IState {
activeEditor?: EditorType;
}

class App extends Component<any, IState> {
class App extends Component<IState> {
state: IState = {
activeEditor: 'imagemap',
};
Expand Down Expand Up @@ -63,7 +63,7 @@ class App extends Component<any, IState> {
<script async={true} src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js" />
</Helmet>
<div className="rde-title">
<Title onChangeEditor={this.handleChangeEditor} currentEditor={activeEditor} />
<TitleBar onChangeEditor={this.handleChangeEditor} currentEditor={activeEditor} />
</div>
<FlowContainer>
<div className="rde-content">{this.renderEditor(activeEditor)}</div>
Expand Down
2 changes: 1 addition & 1 deletion src/canvas/Canvas.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class InternalCanvas extends Component<CanvasProps, IState> implements CanvasIns
const mergedCanvasOption = Object.assign({}, defaults.canvasOption, canvasOption, {
width,
height,
selection: editable,
selection: (typeof canvasOption?.selection !== 'undefined' && canvasOption?.selection) || editable,
});
this.canvas = new fabric.Canvas(`canvas_${id}`, mergedCanvasOption);
this.canvas.setBackgroundColor(mergedCanvasOption.backgroundColor, this.canvas.renderAll.bind(this.canvas));
Expand Down
4 changes: 2 additions & 2 deletions src/canvas/handlers/EventHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -337,9 +337,9 @@ class EventHandler {
const delta = event.e.deltaY;
let zoomRatio = this.handler.canvas.getZoom();
if (delta > 0) {
zoomRatio -= 0.05;
zoomRatio -= this.handler.zoomStep;
} else {
zoomRatio += 0.05;
zoomRatio += this.handler.zoomStep;
}
this.handler.zoomHandler.zoomToPoint(
new fabric.Point(this.handler.canvas.getWidth() / 2, this.handler.canvas.getHeight() / 2),
Expand Down
79 changes: 43 additions & 36 deletions src/canvas/handlers/Handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,48 +3,48 @@ import { union } from 'lodash';
import { uuid } from 'uuidv4';
import warning from 'warning';
import {
AlignmentHandler,
AnimationHandler,
ChartHandler,
ContextmenuHandler,
CropHandler,
CustomHandler,
DrawingHandler,
ElementHandler,
EventHandler,
GridHandler,
GuidelineHandler,
ImageHandler,
InteractionHandler,
LinkHandler,
NodeHandler,
PortHandler,
ShortcutHandler,
TooltipHandler,
TransactionHandler,
WorkareaHandler,
ZoomHandler,
AlignmentHandler,
AnimationHandler,
ChartHandler,
ContextmenuHandler,
CropHandler,
CustomHandler,
DrawingHandler,
ElementHandler,
EventHandler,
GridHandler,
GuidelineHandler,
ImageHandler,
InteractionHandler,
LinkHandler,
NodeHandler,
PortHandler,
ShortcutHandler,
TooltipHandler,
TransactionHandler,
WorkareaHandler,
ZoomHandler,
} from '.';
import CanvasObject from '../CanvasObject';
import { defaults } from '../constants';
import { LinkObject } from '../objects/Link';
import { NodeObject } from '../objects/Node';
import { PortObject } from '../objects/Port';
import {
CanvasOption,
FabricCanvas,
FabricElement,
FabricGroup,
FabricImage,
FabricObject,
FabricObjectOption,
FabricObjects,
GridOption,
GuidelineOption,
InteractionMode,
KeyEvent,
WorkareaObject,
WorkareaOption,
CanvasOption,
FabricCanvas,
FabricElement,
FabricGroup,
FabricImage,
FabricObject,
FabricObjectOption,
FabricObjects,
GridOption,
GuidelineOption,
InteractionMode,
KeyEvent,
WorkareaObject,
WorkareaOption,
} from '../utils';
import { LinkOption } from './LinkHandler';
import { TransactionEvent } from './TransactionHandler';
Expand Down Expand Up @@ -151,6 +151,11 @@ export interface HandlerOption {
* @type {number}
*/
maxZoom?: number;
/**
* Zoom ratio step
* @type {number}
*/
zoomStep?: number;
/**
* Workarea option
* @type {WorkareaOption}
Expand Down Expand Up @@ -226,6 +231,7 @@ class Handler implements HandlerOptions {
public interactionMode: InteractionMode;
public minZoom: number;
public maxZoom: number;
public zoomStep: number = 0.05;
public propertiesToInclude?: string[] = defaults.propertiesToInclude;
public workareaOption?: WorkareaOption = defaults.workareaOption;
public canvasOption?: CanvasOption = defaults.canvasOption;
Expand Down Expand Up @@ -323,6 +329,7 @@ class Handler implements HandlerOptions {
this.interactionMode = options.interactionMode;
this.minZoom = options.minZoom;
this.maxZoom = options.maxZoom;
this.zoomStep = options.zoomStep || 0.05;
this.zoomEnabled = options.zoomEnabled;
this.width = options.width;
this.height = options.height;
Expand Down Expand Up @@ -370,7 +377,7 @@ class Handler implements HandlerOptions {
this.animationHandler = new AnimationHandler(this);
this.contextmenuHandler = new ContextmenuHandler(this);
this.tooltipHandler = new TooltipHandler(this);
this.zoomHandler = new ZoomHandler(this);
this.zoomHandler = new ZoomHandler(this, this.zoomStep);
this.interactionHandler = new InteractionHandler(this);
this.transactionHandler = new TransactionHandler(this);
this.gridHandler = new GridHandler(this);
Expand Down
4 changes: 4 additions & 0 deletions src/canvas/handlers/InteractionHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ class InteractionHandler {
}
});
this.handler.canvas.renderAll();
this.handler.onInteraction?.('selection');
};

/**
Expand All @@ -74,6 +75,7 @@ class InteractionHandler {
}
});
this.handler.canvas.renderAll();
this.handler.onInteraction?.('grab');
};

/**
Expand All @@ -98,6 +100,7 @@ class InteractionHandler {
}
});
this.handler.canvas.renderAll();
this.handler.onInteraction?.(type);
};

public linking = (callback?: (obj: FabricObject) => IReturnType) => {
Expand All @@ -123,6 +126,7 @@ class InteractionHandler {
}
});
this.handler.canvas.renderAll();
this.handler.onInteraction?.('link');
};

/**
Expand Down
10 changes: 6 additions & 4 deletions src/canvas/handlers/ZoomHandler.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
import { fabric } from 'fabric';

import Handler from './Handler';
import { VideoObject } from '../objects/Video';
import { FabricObject } from '../utils';
import Handler from './Handler';

class ZoomHandler {
handler?: Handler;
private _zoomStep?: number;

constructor(handler: Handler) {
constructor(handler: Handler, zoomStep: number = 0.05) {
this.handler = handler;
this._zoomStep = zoomStep;
}

/**
Expand Down Expand Up @@ -83,7 +85,7 @@ class ZoomHandler {
*/
public zoomIn = () => {
let zoomRatio = this.handler.canvas.getZoom();
zoomRatio += 0.05;
zoomRatio += this._zoomStep;
const center = this.handler.canvas.getCenter();
this.zoomToPoint(new fabric.Point(center.left, center.top), zoomRatio);
};
Expand All @@ -94,7 +96,7 @@ class ZoomHandler {
*/
public zoomOut = () => {
let zoomRatio = this.handler.canvas.getZoom();
zoomRatio -= 0.05;
zoomRatio -= this._zoomStep;
const center = this.handler.canvas.getCenter();
this.zoomToPoint(new fabric.Point(center.left, center.top), zoomRatio);
};
Expand Down
4 changes: 2 additions & 2 deletions src/components/common/FileUpload.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, { Component } from 'react';
import { Icon, Upload, message } from 'antd';
import PropTypes from 'prop-types';
import { Upload, Icon } from 'antd';
import React, { Component } from 'react';

const { Dragger } = Upload;

Expand Down
11 changes: 3 additions & 8 deletions src/components/common/UrlModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Form, Modal, Button, Input } from 'antd';
import i18n from 'i18next';

import Icon from '../icon/Icon';
import { UrlModalLabel } from './UrlModalLabel';

class UrlModal extends Component {
handlers = {
Expand Down Expand Up @@ -56,17 +57,11 @@ class UrlModal extends Component {
}

render() {
const { onOk, onCancel, onClick } = this.handlers;
const { form } = this.props;
const { getFieldDecorator } = form;
const { url, visible } = this.state;
const label = (
<React.Fragment>
<span style={{ marginRight: 8 }}>{i18n.t('common.url')}</span>
<Button onClick={onClick} shape="circle" className="rde-action-btn">
<Icon name="edit" />
</Button>
</React.Fragment>
<UrlModalLabel onclick={this.handlers.onClick}/>
);
return (
<React.Fragment>
Expand All @@ -81,7 +76,7 @@ class UrlModal extends Component {
initialValue: url || '',
})(<span style={{ wordBreak: 'break-all' }}>{url}</span>)}
</Form.Item>
<Modal onCancel={onCancel} onOk={onOk} visible={visible}>
<Modal onCancel={this.handlers.onCancel} onOk={this.handlers.onOk} visible={visible}>
<Form.Item label={i18n.t('common.url')} colon={false}>
<Input
defaultValue={url}
Expand Down
14 changes: 14 additions & 0 deletions src/components/common/UrlModalLabel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from "react";
import Icon from '../icon/Icon';
import { Button } from "antd";

export function UrlModalLabel(props) {
return (
<React.Fragment>
<span style={{ marginRight: 8 }}>{i18n.t('common.url')}</span>
<Button onClick={props.onClick} shape="circle" className="rde-action-btn">
<Icon name="edit" />
</Button>
</React.Fragment>
)
}
4 changes: 2 additions & 2 deletions src/components/flex/Flex.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { Component } from 'react';
import Item from './Item';

export interface BoxProps extends React.HTMLAttributes<any> {
export interface BoxProps extends React.HTMLAttributes<HTMLDivElement> {
display?: 'flex' | 'inline-flex';
flexDirection?: 'column-reverse' | 'column' | 'row-reverse' | 'row';
flexWrap?: 'nowrap' | 'wrap-reverse' | 'wrap';
Expand Down Expand Up @@ -56,7 +56,7 @@ class Flex extends Component<BoxProps> {
flex,
},
style,
) as any;
) as BoxProps;
return (
<div
style={Object.keys(newStyle).reduce((prev, key) => {
Expand Down
2 changes: 1 addition & 1 deletion src/components/flex/Item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const Item: React.SFC<ItemProps> = props => {
flex,
},
style,
) as any;
) as ItemProps;
return (
<div
style={Object.keys(newStyle).reduce((prev, key) => {
Expand Down
15 changes: 15 additions & 0 deletions src/components/layout/Ads.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import React from "react";
import { Flex } from "../flex";

export function Ads() {
return (
<Flex flex="1" justifyContent="flex-end">
<ins
className="adsbygoogle"
style={{ display: 'inline-block', width: 600, height: 60 }}
data-ad-client="ca-pub-8569372752842198"
data-ad-slot="5790685139"
/>
</Flex>
)
}
22 changes: 22 additions & 0 deletions src/components/layout/DocsButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Button, Tooltip } from "antd";
import i18next from "i18next";
import React from "react";
import Icon from "../icon/Icon";

export function DocsButton(props) {
return (
<Tooltip title={i18next.t('action.go-docs')} overlayStyle={{ fontSize: 16 }}>
<Button
className="rde-action-btn"
style={{
color: 'white',
}}
shape="circle"
size="large"
onClick={props.onClick}
>
<Icon name="book" prefix="fas" size={1.5} />
</Button>
</Tooltip>
)
}
Loading