refactor(style): fix code style for designer

refactor(style): fix code style for editor-core

refactor(style): fix code style for editor-skeleton

refactor(style): fix code style for react-simulator-renderer

refactor(style): fix code style for rax-simulator-renderer
This commit is contained in:
力皓 2020-09-10 20:09:30 +08:00
parent 0d3e7c96b3
commit 30bf21ca04
59 changed files with 299 additions and 157 deletions

View File

@ -0,0 +1,16 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
'no-useless-constructor': 1,
'no-empty-function': 1,
}
}

View File

@ -38,6 +38,7 @@ export class BorderDetectingInstance extends PureComponent<{
} }
@observer @observer
// eslint-disable-next-line react/no-multi-comp
export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> { export class BorderDetecting extends Component<{ host: BuiltinSimulatorHost }> {
shouldComponentUpdate() { shouldComponentUpdate() {
return false; return false;

View File

@ -57,6 +57,7 @@ export default class BoxResizing extends Component<{ host: BuiltinSimulatorHost
} }
@observer @observer
// eslint-disable-next-line react/no-multi-comp
export class BoxResizingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> { export class BoxResizingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> {
static contextType = SimulatorContext; static contextType = SimulatorContext;
@ -104,6 +105,7 @@ export class BoxResizingForNode extends Component<{ host: BuiltinSimulatorHost;
} }
@observer @observer
// eslint-disable-next-line react/no-multi-comp
export class BoxResizingInstance extends Component<{ export class BoxResizingInstance extends Component<{
observed: OffsetObserver; observed: OffsetObserver;
highlight?: boolean; highlight?: boolean;

View File

@ -55,6 +55,7 @@ export class BorderSelectingInstance extends Component<{
} }
@observer @observer
// eslint-disable-next-line react/no-multi-comp
class Toolbar extends Component<{ observed: OffsetObserver }> { class Toolbar extends Component<{ observed: OffsetObserver }> {
shouldComponentUpdate() { shouldComponentUpdate() {
return false; return false;
@ -150,6 +151,7 @@ function createAction(content: ReactNode | ComponentType<any> | ActionContentObj
} }
@observer @observer
// eslint-disable-next-line react/no-multi-comp
export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> { export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHost; node: Node }> {
get host(): BuiltinSimulatorHost { get host(): BuiltinSimulatorHost {
return this.props.host; return this.props.host;
@ -193,6 +195,7 @@ export class BorderSelectingForNode extends Component<{ host: BuiltinSimulatorHo
} }
@observer @observer
// eslint-disable-next-line react/no-multi-comp
export class BorderSelecting extends Component<{ host: BuiltinSimulatorHost }> { export class BorderSelecting extends Component<{ host: BuiltinSimulatorHost }> {
get host(): BuiltinSimulatorHost { get host(): BuiltinSimulatorHost {
return this.props.host; return this.props.host;

View File

@ -1,7 +1,7 @@
import { EventEmitter } from 'events'; import { EventEmitter } from 'events';
import { ISimulatorHost, isSimulatorHost } from '../../simulator'; import { ISimulatorHost } from '../../simulator';
import { Designer, Point } from '../../designer'; import { Designer, Point } from '../../designer';
import { setNativeSelection, cursor } from '@ali/lowcode-utils'; import { cursor } from '@ali/lowcode-utils';
// import Cursor from './cursor'; // import Cursor from './cursor';
// import Pages from './pages'; // import Pages from './pages';
@ -19,7 +19,7 @@ function makeEventsHandler(
// } // }
docs.add(sourceDoc); docs.add(sourceDoc);
// if (sourceDoc !== topDoc || isDragEvent(boostEvent)) { // if (sourceDoc !== topDoc || isDragEvent(boostEvent)) {
sensors.forEach((sim) => { sensors.forEach(sim => {
const sdoc = sim.contentDocument; const sdoc = sim.contentDocument;
if (sdoc) { if (sdoc) {
docs.add(sdoc); docs.add(sdoc);
@ -28,7 +28,7 @@ function makeEventsHandler(
// } // }
return (handle: (sdoc: Document) => void) => { return (handle: (sdoc: Document) => void) => {
docs.forEach((doc) => handle(doc)); docs.forEach(doc => handle(doc));
}; };
} }
@ -38,23 +38,11 @@ export default class DragResizeEngine {
private dragResizing = false; private dragResizing = false;
constructor(readonly designer: Designer) { constructor(designer: Designer) {
this.designer = designer; this.designer = designer;
this.emitter = new EventEmitter(); this.emitter = new EventEmitter();
} }
private getMasterSensors(): ISimulatorHost[] {
return this.designer.project.documents
.map((doc) => {
// TODO: not use actived,
if (doc.actived && doc.simulator?.sensorAvailable) {
return doc.simulator;
}
return null;
})
.filter(Boolean) as any;
}
isDragResizing() { isDragResizing() {
return this.dragResizing; return this.dragResizing;
} }
@ -84,14 +72,12 @@ export default class DragResizeEngine {
const masterSensors = this.getMasterSensors(); const masterSensors = this.getMasterSensors();
const createResizeEvent = (e: MouseEvent | DragEvent): Point => { const createResizeEvent = (e: MouseEvent | DragEvent): Point => {
const evt: any = {};
const sourceDocument = e.view?.document; const sourceDocument = e.view?.document;
if (!sourceDocument || sourceDocument === document) { if (!sourceDocument || sourceDocument === document) {
return e; return e;
} }
const srcSim = masterSensors.find((sim) => sim.contentDocument === sourceDocument); const srcSim = masterSensors.find(sim => sim.contentDocument === sourceDocument);
if (srcSim) { if (srcSim) {
return srcSim.viewport.toGlobalPoint(e); return srcSim.viewport.toGlobalPoint(e);
} }
@ -100,7 +86,7 @@ export default class DragResizeEngine {
const over = (e: MouseEvent) => { const over = (e: MouseEvent) => {
const handleEvents = makeEventsHandler(e, masterSensors); const handleEvents = makeEventsHandler(e, masterSensors);
handleEvents((doc) => { handleEvents(doc => {
doc.removeEventListener('mousemove', move, true); doc.removeEventListener('mousemove', move, true);
doc.removeEventListener('mouseup', over, true); doc.removeEventListener('mouseup', over, true);
}); });
@ -115,7 +101,7 @@ export default class DragResizeEngine {
node = boost(e); node = boost(e);
startEvent = createResizeEvent(e); startEvent = createResizeEvent(e);
const handleEvents = makeEventsHandler(e, masterSensors); const handleEvents = makeEventsHandler(e, masterSensors);
handleEvents((doc) => { handleEvents(doc => {
doc.addEventListener('mousemove', move, true); doc.addEventListener('mousemove', move, true);
doc.addEventListener('mouseup', over, true); doc.addEventListener('mouseup', over, true);
}); });
@ -137,7 +123,9 @@ export default class DragResizeEngine {
}; };
} }
onResize(func: (e: MouseEvent, direction: string, node: any, moveX: number, moveY: number) => any) { onResize(
func: (e: MouseEvent, direction: string, node: any, moveX: number, moveY: number) => any,
) {
this.emitter.on('resize', func); this.emitter.on('resize', func);
return () => { return () => {
this.emitter.removeListener('resize', func); this.emitter.removeListener('resize', func);
@ -150,6 +138,18 @@ export default class DragResizeEngine {
this.emitter.removeListener('resizeEnd', func); this.emitter.removeListener('resizeEnd', func);
}; };
} }
private getMasterSensors(): ISimulatorHost[] {
return this.designer.project.documents
.map(doc => {
// TODO: not use actived,
if (doc.actived && doc.simulator?.sensorAvailable) {
return doc.simulator;
}
return null;
})
.filter(Boolean) as any;
}
} }
// new DragResizeEngine(); // new DragResizeEngine();

View File

@ -1,6 +1,5 @@
import { Component } from 'react'; import { Component } from 'react';
import { computed, observer } from '@ali/lowcode-editor-core'; import { observer } from '@ali/lowcode-editor-core';
import { SimulatorContext } from '../context';
import { BuiltinSimulatorHost } from '../host'; import { BuiltinSimulatorHost } from '../host';
import { import {
DropLocation, DropLocation,

View File

@ -2,7 +2,6 @@ import { Component } from 'react';
import { observer } from '@ali/lowcode-editor-core'; import { observer } from '@ali/lowcode-editor-core';
import { BuiltinSimulatorHost, BuiltinSimulatorProps } from './host'; import { BuiltinSimulatorHost, BuiltinSimulatorProps } from './host';
import { DocumentModel } from '../document'; import { DocumentModel } from '../document';
import { SimulatorContext } from './context';
import { BemTools } from './bem-tools'; import { BemTools } from './bem-tools';
import './host.less'; import './host.less';
@ -51,6 +50,7 @@ export class BuiltinSimulatorHostView extends Component<SimulatorHostProps> {
} }
} }
// eslint-disable-next-line react/no-multi-comp
@observer @observer
class Canvas extends Component<{ host: BuiltinSimulatorHost }> { class Canvas extends Component<{ host: BuiltinSimulatorHost }> {
render() { render() {
@ -73,6 +73,7 @@ class Canvas extends Component<{ host: BuiltinSimulatorHost }> {
} }
} }
// eslint-disable-next-line react/no-multi-comp
@observer @observer
class Content extends Component<{ host: BuiltinSimulatorHost }> { class Content extends Component<{ host: BuiltinSimulatorHost }> {
render() { render() {

View File

@ -60,6 +60,7 @@ export interface BuiltinSimulatorProps {
const defaultSimulatorUrl = (() => { const defaultSimulatorUrl = (() => {
const publicPath = getPublicPath(); const publicPath = getPublicPath();
let urls; let urls;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, prefix = '', dev] = /^(.+?)(\/js)?\/?$/.exec(publicPath) || []; const [_, prefix = '', dev] = /^(.+?)(\/js)?\/?$/.exec(publicPath) || [];
if (dev) { if (dev) {
urls = [`${prefix}/css/react-simulator-renderer.css`, `${prefix}/js/react-simulator-renderer.js`]; urls = [`${prefix}/css/react-simulator-renderer.css`, `${prefix}/js/react-simulator-renderer.js`];
@ -74,6 +75,7 @@ const defaultSimulatorUrl = (() => {
const defaultRaxSimulatorUrl = (() => { const defaultRaxSimulatorUrl = (() => {
const publicPath = getPublicPath(); const publicPath = getPublicPath();
let urls; let urls;
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, prefix = '', dev] = /^(.+?)(\/js)?\/?$/.exec(publicPath) || []; const [_, prefix = '', dev] = /^(.+?)(\/js)?\/?$/.exec(publicPath) || [];
if (dev) { if (dev) {
urls = [`${prefix}/css/rax-simulator-renderer.css`, `${prefix}/js/rax-simulator-renderer.js`]; urls = [`${prefix}/css/rax-simulator-renderer.css`, `${prefix}/js/rax-simulator-renderer.js`];
@ -503,11 +505,9 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
this.disableHovering(); this.disableHovering();
} }
// sleep some autorun reaction // sleep some autorun reaction
} else { } else if (!this.disableHovering) {
// weekup some autorun reaction // weekup some autorun reaction
if (!this.disableHovering) { this.setupDetecting();
this.setupDetecting();
}
} }
} }
@ -596,14 +596,14 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
/** /**
* @see ISimulator * @see ISimulator
*/ */
getComponentInstanceId(instance: ComponentInstance) { getComponentInstanceId(/* instance: ComponentInstance */) {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
/** /**
* @see ISimulator * @see ISimulator
*/ */
getComponentContext(node: Node): object { getComponentContext(/* node: Node */): any {
throw new Error('Method not implemented.'); throw new Error('Method not implemented.');
} }
@ -638,7 +638,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
const elems = elements.slice(); const elems = elements.slice();
let rects: DOMRect[] | undefined; let rects: DOMRect[] | undefined;
let last: { x: number; y: number; r: number; b: number } | undefined; let last: { x: number; y: number; r: number; b: number } | undefined;
let computed = false; let _computed = false;
while (true) { while (true) {
if (!rects || rects.length < 1) { if (!rects || rects.length < 1) {
const elem = elems.pop(); const elem = elems.pop();
@ -665,26 +665,26 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
} }
if (rect.left < last.x) { if (rect.left < last.x) {
last.x = rect.left; last.x = rect.left;
computed = true; _computed = true;
} }
if (rect.top < last.y) { if (rect.top < last.y) {
last.y = rect.top; last.y = rect.top;
computed = true; _computed = true;
} }
if (rect.right > last.r) { if (rect.right > last.r) {
last.r = rect.right; last.r = rect.right;
computed = true; _computed = true;
} }
if (rect.bottom > last.b) { if (rect.bottom > last.b) {
last.b = rect.bottom; last.b = rect.bottom;
computed = true; _computed = true;
} }
} }
if (last) { if (last) {
const r: any = new DOMRect(last.x, last.y, last.r - last.x, last.b - last.y); const r: any = new DOMRect(last.x, last.y, last.r - last.x, last.b - last.y);
r.elements = elements; r.elements = elements;
r.computed = computed; r.computed = _computed;
return r; return r;
} }
@ -734,7 +734,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
/** /**
* @see ISimulator * @see ISimulator
*/ */
scrollToNode(node: Node, detail?: any, tryTimes = 0) { scrollToNode(node: Node, detail?: any/* , tryTimes = 0 */) {
this.tryScrollAgain = null; this.tryScrollAgain = null;
if (this.sensing) { if (this.sensing) {
// actived sensor // actived sensor
@ -973,7 +973,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
const instances = this.getComponentInstances(node); const instances = this.getComponentInstances(node);
const inst = instances const inst = instances
? instances.length > 1 ? instances.length > 1
? instances.find((inst) => this.getClosestNodeInstance(inst, container.id)?.instance === containerInstance) ? instances.find((_inst) => this.getClosestNodeInstance(_inst, container.id)?.instance === containerInstance)
: instances[0] : instances[0]
: null; : null;
const rect = inst ? this.computeComponentInstanceRect(inst, node.componentMeta.rootSelector) : null; const rect = inst ? this.computeComponentInstanceRect(inst, node.componentMeta.rootSelector) : null;
@ -1164,7 +1164,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
return null; return null;
} }
isAcceptable(container: ParentalNode): boolean { isAcceptable(/* container: ParentalNode */): boolean {
return false; return false;
/* /*
const meta = container.componentMeta; const meta = container.componentMeta;
@ -1179,7 +1179,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
/** /**
* *
*/ */
handleAccept({ container, instance }: DropContainer, e: LocateEvent) { handleAccept({ container/* , instance */ }: DropContainer, e: LocateEvent) {
const { dragObject } = e; const { dragObject } = e;
if (isRootNode(container)) { if (isRootNode(container)) {
return this.document.checkDropTarget(container, dragObject as any); return this.document.checkDropTarget(container, dragObject as any);
@ -1227,7 +1227,7 @@ export class BuiltinSimulatorHost implements ISimulatorHost<BuiltinSimulatorProp
/** /**
* *
*/ */
getNearByContainer(container: ParentalNode, e: LocateEvent) { getNearByContainer(/* container: ParentalNode, e: LocateEvent */) {
/* /*
const children = container.children; const children = container.children;
if (!children || children.length < 1) { if (!children || children.length < 1) {

View File

@ -81,15 +81,15 @@ export class LiveEditing {
} }
} }
if (!propTarget) { // if (!propTarget) {
// 自动纯文本编辑满足一下情况: // // 自动纯文本编辑满足一下情况:
// 1. children 内容都是 Leaf 且都是文本(一期) // // 1. children 内容都是 Leaf 且都是文本(一期)
// 2. DOM 节点是单层容器,子集都是文本节点 (已满足) // // 2. DOM 节点是单层容器,子集都是文本节点 (已满足)
const isAllText = node.children?.every(item => { // const isAllText = node.children?.every(item => {
return item.isLeaf() && item.getProp('children')?.type === 'literal'; // return item.isLeaf() && item.getProp('children')?.type === 'literal';
}); // });
// TODO: // // TODO:
} // }
if (propTarget && setterPropElement) { if (propTarget && setterPropElement) {
const prop = node.getProp(propTarget, true)!; const prop = node.getProp(propTarget, true)!;
@ -121,8 +121,10 @@ export class LiveEditing {
console.info(e.code); console.info(e.code);
switch (e.code) { switch (e.code) {
case 'Enter': case 'Enter':
break;
// TODO: check is richtext? // TODO: check is richtext?
case 'Escape': case 'Escape':
break;
case 'Tab': case 'Tab':
setterPropElement?.blur(); setterPropElement?.blur();
} }
@ -130,7 +132,7 @@ export class LiveEditing {
// enter // enter
// tab // tab
}; };
const focusout = (e: FocusEvent) => { const focusout = (/* e: FocusEvent */) => {
this.saveAndDispose(); this.saveAndDispose();
}; };
setterPropElement.addEventListener('focusout', focusout); setterPropElement.addEventListener('focusout', focusout);

View File

@ -71,7 +71,7 @@ export default class InstanceNodeSelector extends React.Component<IProps, IState
} }
}; };
renderNodes = (node: Node) => { renderNodes = (/* node: Node */) => {
const nodes = this.state.parentNodes || []; const nodes = this.state.parentNodes || [];
const children = nodes.map((node, key) => { const children = nodes.map((node, key) => {
return ( return (

View File

@ -26,14 +26,14 @@ export default class ResourceConsumer<T = any> {
private _providing?: () => void; private _providing?: () => void;
private _consuming?: () => void;
constructor(provider: () => T, private consumer?: RendererConsumer<T>) { constructor(provider: () => T, private consumer?: RendererConsumer<T>) {
this._providing = autorun(() => { this._providing = autorun(() => {
this._data = provider(); this._data = provider();
}); });
} }
private _consuming?: () => void;
consume(consumerOrRenderer: BuiltinSimulatorRenderer | ((data: T) => any)) { consume(consumerOrRenderer: BuiltinSimulatorRenderer | ((data: T) => any)) {
if (this._consuming) { if (this._consuming) {
return; return;

View File

@ -16,6 +16,7 @@ export const primitiveTypes = [
'any', 'any',
]; ];
// eslint-disable-next-line @typescript-eslint/ban-types
function makeRequired(propType: any, lowcodeType: string | object) { function makeRequired(propType: any, lowcodeType: string | object) {
function lowcodeCheckTypeIsRequired(...rest: any[]) { function lowcodeCheckTypeIsRequired(...rest: any[]) {
return propType.isRequired(...rest); return propType.isRequired(...rest);
@ -32,6 +33,7 @@ function makeRequired(propType: any, lowcodeType: string | object) {
return lowcodeCheckTypeIsRequired; return lowcodeCheckTypeIsRequired;
} }
// eslint-disable-next-line @typescript-eslint/ban-types
function define(propType: any = PropTypes.any, lowcodeType: string | object = {}) { function define(propType: any = PropTypes.any, lowcodeType: string | object = {}) {
if (!propType._inner && propType.name !== 'lowcodeCheckType') { if (!propType._inner && propType.name !== 'lowcodeCheckType') {
propType.lowcodeType = lowcodeType; propType.lowcodeType = lowcodeType;

View File

@ -1,5 +1,6 @@
const useRAF = typeof requestAnimationFrame === 'function'; const useRAF = typeof requestAnimationFrame === 'function';
// eslint-disable-next-line @typescript-eslint/ban-types
export function throttle(func: Function, delay: number) { export function throttle(func: Function, delay: number) {
let lastArgs: any; let lastArgs: any;
let lastThis: any; let lastThis: any;

View File

@ -13,7 +13,7 @@ import {
FieldConfig, FieldConfig,
} from '@ali/lowcode-types'; } from '@ali/lowcode-types';
import { computed } from '@ali/lowcode-editor-core'; import { computed } from '@ali/lowcode-editor-core';
import { Node, ParentalNode, TransformStage } from './document'; import { Node, ParentalNode } from './document';
import { Designer } from './designer'; import { Designer } from './designer';
import { intlNode } from './locale'; import { intlNode } from './locale';
import { IconContainer } from './icons/container'; import { IconContainer } from './icons/container';
@ -231,6 +231,7 @@ export class ComponentMeta {
} }
@computed get availableActions() { @computed get availableActions() {
// eslint-disable-next-line prefer-const
let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {}; let { disableBehaviors, actions } = this._transformedMetadata?.configure.component || {};
const disabled = ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null); const disabled = ensureAList(disableBehaviors) || (this.isRootComponent(false) ? ['copy', 'remove'] : null);
actions = builtinComponentActions.concat(this.designer.getGlobalComponentActions() || [], actions || []); actions = builtinComponentActions.concat(this.designer.getGlobalComponentActions() || [], actions || []);
@ -331,6 +332,7 @@ registerMetadataTransducer((metadata) => {
if (!component.nestingRule) { if (!component.nestingRule) {
let m; let m;
// uri match xx.Group set subcontrolling: true, childWhiteList // uri match xx.Group set subcontrolling: true, childWhiteList
// eslint-disable-next-line no-cond-assign
if ((m = /^(.+)\.Group$/.exec(componentName))) { if ((m = /^(.+)\.Group$/.exec(componentName))) {
// component.subControlling = true; // component.subControlling = true;
if (!component.nestingRule) { if (!component.nestingRule) {
@ -338,16 +340,16 @@ registerMetadataTransducer((metadata) => {
childWhitelist: [`${m[1]}`], childWhitelist: [`${m[1]}`],
}; };
} }
} // eslint-disable-next-line no-cond-assign
// uri match xx.Node set selfControlled: false, parentWhiteList } else if ((m = /^(.+)\.Node$/.exec(componentName))) {
else if ((m = /^(.+)\.Node$/.exec(componentName))) { // uri match xx.Node set selfControlled: false, parentWhiteList
// component.selfControlled = false; // component.selfControlled = false;
component.nestingRule = { component.nestingRule = {
parentWhitelist: [`${m[1]}`, componentName], parentWhitelist: [`${m[1]}`, componentName],
}; };
} // eslint-disable-next-line no-cond-assign
// uri match .Item .Node .Option set parentWhiteList } else if ((m = /^(.+)\.(Item|Node|Option)$/.exec(componentName))) {
else if ((m = /^(.+)\.(Item|Node|Option)$/.exec(componentName))) { // uri match .Item .Node .Option set parentWhiteList
component.nestingRule = { component.nestingRule = {
parentWhitelist: [`${m[1]}`], parentWhitelist: [`${m[1]}`],
}; };

View File

@ -245,7 +245,7 @@ hotkey.bind(['option+left', 'option+right'], (e, action) => {
} }
}); });
hotkey.bind(['option+up'], (e, action) => { hotkey.bind(['option+up'], (e) => {
const designer = focusing.focusDesigner; const designer = focusing.focusDesigner;
const doc = designer?.currentDocument; const doc = designer?.currentDocument;
if (isFormEvent(e) || !doc) { if (isFormEvent(e) || !doc) {
@ -283,7 +283,7 @@ hotkey.bind(['option+up'], (e, action) => {
} }
}); });
hotkey.bind(['option+down'], (e, action) => { hotkey.bind(['option+down'], (e) => {
const designer = focusing.focusDesigner; const designer = focusing.focusDesigner;
const doc = designer?.currentDocument; const doc = designer?.currentDocument;
if (isFormEvent(e) || !doc) { if (isFormEvent(e) || !doc) {

View File

@ -44,7 +44,7 @@ export class DesignerView extends Component<DesignerProps & {
this.designer.postEvent('mount', this.designer); this.designer.postEvent('mount', this.designer);
} }
componentWillMount() { UNSAFE_componentWillMount() {
this.designer.purge(); this.designer.purge();
} }

View File

@ -136,6 +136,7 @@ export class Designer {
[npm?.package, npm?.componentName].filter((item) => !!item).join('-') || [npm?.package, npm?.componentName].filter((item) => !!item).join('-') ||
parent?.componentMeta?.componentName || parent?.componentMeta?.componentName ||
''; '';
// eslint-disable-next-line no-unused-expressions
this.editor?.emit('designer.drag', { this.editor?.emit('designer.drag', {
time: (endTime - startTime).toFixed(2), time: (endTime - startTime).toFixed(2),
selected: nodes selected: nodes
@ -143,6 +144,7 @@ export class Designer {
if (!n) { if (!n) {
return; return;
} }
// eslint-disable-next-line no-shadow
const npm = n?.componentMeta?.npm; const npm = n?.componentMeta?.npm;
return ( return (
[npm?.package, npm?.componentName].filter((item) => !!item).join('-') || [npm?.package, npm?.componentName].filter((item) => !!item).join('-') ||

View File

@ -77,6 +77,7 @@ export interface ISensor {
export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject; export type DragObject = DragNodeObject | DragNodeDataObject | DragAnyObject;
export enum DragObjectType { export enum DragObjectType {
// eslint-disable-next-line no-shadow
Node = 'node', Node = 'node',
NodeData = 'nodedata', NodeData = 'nodedata',
} }
@ -204,8 +205,7 @@ export class Dragon {
private emitter = new EventEmitter(); private emitter = new EventEmitter();
constructor(readonly designer: Designer) { constructor(readonly designer: Designer) {}
}
/** /**
* Quick listen a shell(container element) drag behavior * Quick listen a shell(container element) drag behavior

View File

@ -134,7 +134,8 @@ export class OffsetObserver {
this._bottom = rect.bottom; this._bottom = rect.bottom;
this.hasOffset = true; this.hasOffset = true;
} }
this.pid = pid = (window as any).requestIdleCallback(compute); this.pid = (window as any).requestIdleCallback(compute);
pid = this.pid;
}; };
this.compute = compute; this.compute = compute;
@ -142,7 +143,8 @@ export class OffsetObserver {
// try first // try first
compute(); compute();
// try second, ensure the dom mounted // try second, ensure the dom mounted
this.pid = pid = (window as any).requestIdleCallback(compute); this.pid = (window as any).requestIdleCallback(compute);
pid = this.pid;
} }
purge() { purge() {

View File

@ -53,6 +53,8 @@ export interface IScrollable {
export class Scroller { export class Scroller {
private pid: number | undefined; private pid: number | undefined;
constructor(private scrollable: IScrollable) {}
get scrollTarget(): ScrollTarget | null { get scrollTarget(): ScrollTarget | null {
let target = this.scrollable.scrollTarget; let target = this.scrollable.scrollTarget;
if (!target) { if (!target) {
@ -65,8 +67,6 @@ export class Scroller {
return target; return target;
} }
constructor(private scrollable: IScrollable) {}
scrollTo(options: { left?: number; top?: number }) { scrollTo(options: { left?: number; top?: number }) {
this.cancel(); this.cancel();
@ -109,13 +109,15 @@ export class Scroller {
scrollTarget.scrollTo(opt); scrollTarget.scrollTo(opt);
if (time < 1) { if (time < 1) {
this.pid = pid = requestAnimationFrame(animate); this.pid = requestAnimationFrame(animate);
pid = this.pid;
} else { } else {
end(); end();
} }
}; };
this.pid = pid = requestAnimationFrame(animate); this.pid = requestAnimationFrame(animate);
pid = this.pid;
} }
scrolling(point: { globalX: number; globalY: number }) { scrolling(point: { globalX: number; globalY: number }) {

View File

@ -1,4 +1,4 @@
import { obx, computed, autorun } from '@ali/lowcode-editor-core'; import { obx, computed } from '@ali/lowcode-editor-core';
import { IEditor, isJSExpression } from '@ali/lowcode-types'; import { IEditor, isJSExpression } from '@ali/lowcode-types';
import { uniqueId } from '@ali/lowcode-utils'; import { uniqueId } from '@ali/lowcode-utils';
import { SettingEntry } from './setting-entry'; import { SettingEntry } from './setting-entry';

View File

@ -2,7 +2,7 @@ import { EventEmitter } from 'events';
import { CustomView, isCustomView, IEditor } from '@ali/lowcode-types'; import { CustomView, isCustomView, IEditor } from '@ali/lowcode-types';
import { computed } from '@ali/lowcode-editor-core'; import { computed } from '@ali/lowcode-editor-core';
import { SettingEntry } from './setting-entry'; import { SettingEntry } from './setting-entry';
import { SettingField, isSettingField } from './setting-field'; import { SettingField } from './setting-field';
import { SettingPropEntry } from './setting-prop-entry'; import { SettingPropEntry } from './setting-prop-entry';
import { Node } from '../../document'; import { Node } from '../../document';
import { ComponentMeta } from '../../component-meta'; import { ComponentMeta } from '../../component-meta';

View File

@ -672,7 +672,7 @@ export class DocumentModel {
/** /**
* @deprecated * @deprecated
*/ */
onRefresh(func: () => void) { onRefresh(/* func: () => void */) {
console.warn('onRefresh method is deprecated'); console.warn('onRefresh method is deprecated');
} }
} }

View File

@ -112,7 +112,7 @@ export class ModalNodesManager {
private addNodeEvent(node: Node) { private addNodeEvent(node: Node) {
this.nodeRemoveEvents[node.getId()] = this.nodeRemoveEvents[node.getId()] =
node.onVisibleChange((flag) => { node.onVisibleChange(() => {
this.emitter.emit('visibleChange'); this.emitter.emit('visibleChange');
}); });
} }

View File

@ -129,7 +129,7 @@ export class NodeChildren {
node.internalSetParent(null, useMutator); node.internalSetParent(null, useMutator);
try { try {
node.purge(useMutator); node.purge(useMutator);
} catch(err) { } catch (err) {
console.error(err); console.error(err);
} }
} }

View File

@ -431,7 +431,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
return false; return false;
} }
wrapWith(schema: Schema) { wrapWith(/* schema: Schema */) {
// todo // todo
} }
@ -725,7 +725,7 @@ export class Node<Schema extends NodeSchema = NodeSchema> {
/** /**
* *
*/ */
purge(useMutator = true) { purge() {
if (this.purged) { if (this.purged) {
return; return;
} }
@ -1066,7 +1066,7 @@ export function insertChildren(
let index = at; let index = at;
let node: any; let node: any;
const results: Node[] = []; const results: Node[] = [];
// tslint:disable-next-line // eslint-disable-next-line no-cond-assign
while ((node = nodes.pop())) { while ((node = nodes.pop())) {
node = insertChild(container, node, index, copy); node = insertChild(container, node, index, copy);
results.push(node); results.push(node);

View File

@ -153,41 +153,41 @@ export class Props implements IPropParent {
query(path: string, stash = true): Prop | null { query(path: string, stash = true): Prop | null {
return this.get(path, stash); return this.get(path, stash);
// todo: future support list search // todo: future support list search
let matchedLength = 0; // let matchedLength = 0;
let firstMatched = null; // let firstMatched = null;
if (this.items) { // if (this.items) {
// target: a.b.c // // target: a.b.c
// trys: a.b.c, a.b, a // // trys: a.b.c, a.b, a
let i = this.items.length; // let i = this.items.length;
while (i-- > 0) { // while (i-- > 0) {
const expr = this.items[i]; // const expr = this.items[i];
if (!expr.key) { // if (!expr.key) {
continue; // continue;
} // }
const name = String(expr.key); // const name = String(expr.key);
if (name === path) { // if (name === path) {
// completely match // // completely match
return expr; // return expr;
} // }
// fisrt match // // fisrt match
const l = name.length; // const l = name.length;
if (path.slice(0, l + 1) === `${name}.`) { // if (path.slice(0, l + 1) === `${name}.`) {
matchedLength = l; // matchedLength = l;
firstMatched = expr; // firstMatched = expr;
} // }
} // }
} // }
let ret = null; // let ret = null;
if (firstMatched) { // if (firstMatched) {
ret = firstMatched.get(path.slice(matchedLength + 1), true); // ret = firstMatched.get(path.slice(matchedLength + 1), true);
} // }
if (!ret && stash) { // if (!ret && stash) {
return this.stash.get(path); // return this.stash.get(path);
} // }
return ret; // return ret;
} }
/** /**

View File

@ -4,6 +4,7 @@ function propertyNameRequiresQuotes(propertyName: string) {
worksWithoutQuotes: false, worksWithoutQuotes: false,
}; };
// eslint-disable-next-line no-new-func
new Function('ctx', `ctx.worksWithoutQuotes = {${propertyName}: true}['${propertyName}']`)(); new Function('ctx', `ctx.worksWithoutQuotes = {${propertyName}: true}['${propertyName}']`)();
return !context.worksWithoutQuotes; return !context.worksWithoutQuotes;
@ -225,7 +226,9 @@ export function getSource(value: any): string {
if (value) { if (value) {
try { try {
value.__source = source; value.__source = source;
} catch (ex) {} } catch (ex) {
console.error(ex);
}
} }
return source; return source;
} }

View File

@ -8,6 +8,8 @@ export class Selection {
@obx.val private _selected: string[] = []; @obx.val private _selected: string[] = [];
constructor(readonly doc: DocumentModel) {}
/** /**
* id * id
*/ */
@ -15,8 +17,6 @@ export class Selection {
return this._selected; return this._selected;
} }
constructor(readonly doc: DocumentModel) {}
/** /**
* *
*/ */

View File

@ -38,8 +38,8 @@ export class Project {
* document的schema,render * document的schema,render
* @param schema * @param schema
*/ */
setSchema(schema?: ProjectSchema){ setSchema(schema?: ProjectSchema) {
let doc = this.documents.find((doc) => doc.actived); const doc = this.documents.find((doc) => doc.actived);
doc && doc.import(schema?.componentsTree[0]); doc && doc.import(schema?.componentsTree[0]);
} }
@ -91,6 +91,7 @@ export class Project {
* *
*/ */
set( set(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
key: key:
| 'version' | 'version'
| 'componentsTree' | 'componentsTree'
@ -101,6 +102,7 @@ export class Project {
| 'css' | 'css'
| 'dataSource' | 'dataSource'
| string, | string,
// eslint-disable-next-line @typescript-eslint/no-unused-vars
value: any, value: any,
): void {} ): void {}
@ -108,6 +110,7 @@ export class Project {
* *
*/ */
get( get(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
key: key:
| 'version' | 'version'
| 'componentsTree' | 'componentsTree'

View File

@ -0,0 +1,14 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
}
}

View File

@ -1,5 +1,4 @@
const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin'); const TsconfigPathsPlugin = require('tsconfig-paths-webpack-plugin');
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
module.exports = ({ onGetWebpackConfig }) => { module.exports = ({ onGetWebpackConfig }) => {
onGetWebpackConfig((config) => { onGetWebpackConfig((config) => {

View File

@ -11,7 +11,7 @@ import {
import { IocContext, RegisterOptions } from './di'; import { IocContext, RegisterOptions } from './di';
import { globalLocale } from './intl'; import { globalLocale } from './intl';
import * as utils from './utils'; import * as utils from './utils';
import { tipHandler } from './widgets/tip/tip-handler'; // import { tipHandler } from './widgets/tip/tip-handler';
EventEmitter.defaultMaxListeners = 100; EventEmitter.defaultMaxListeners = 100;
@ -22,7 +22,7 @@ export class Editor extends EventEmitter implements IEditor {
* Ioc Container * Ioc Container
*/ */
private context = new IocContext({ private context = new IocContext({
notFoundHandler: (type: KeyType) => NOT_FOUND, notFoundHandler: (/* type: KeyType */) => NOT_FOUND,
}); });
get locale() { get locale() {
@ -92,7 +92,7 @@ export class Editor extends EventEmitter implements IEditor {
async init(config?: EditorConfig, components?: PluginClassSet): Promise<any> { async init(config?: EditorConfig, components?: PluginClassSet): Promise<any> {
this.config = config || {}; this.config = config || {};
this.components = components || {}; this.components = components || {};
const { shortCuts = [], hooks = [], lifeCycles } = this.config; const { hooks = [], lifeCycles } = this.config;
this.emit('editor.beforeInit'); this.emit('editor.beforeInit');
const init = (lifeCycles && lifeCycles.init) || ((): void => {}); const init = (lifeCycles && lifeCycles.init) || ((): void => {});
@ -116,7 +116,7 @@ export class Editor extends EventEmitter implements IEditor {
return; return;
} }
try { try {
const { shortCuts = [], lifeCycles = {} } = this.config; const { lifeCycles = {} } = this.config;
// unRegistShortCuts(shortCuts); // unRegistShortCuts(shortCuts);
this.unregisterHooks(); this.unregisterHooks();

View File

@ -588,7 +588,6 @@ export class Hotkey {
combination = combination.replace(/\s+/g, ' '); combination = combination.replace(/\s+/g, ' ');
const sequence: string[] = combination.split(' '); const sequence: string[] = combination.split(' ');
let info: KeyInfo;
// if this pattern is a sequence of keys then run through this method // if this pattern is a sequence of keys then run through this method
// to reprocess each pattern one key at a time // to reprocess each pattern one key at a time
@ -597,7 +596,7 @@ export class Hotkey {
return; return;
} }
info = getKeyInfo(combination, action); const info: KeyInfo = getKeyInfo(combination, action);
// make sure to initialize array if this is the first time // make sure to initialize array if this is the first time
// a callback is added for this key // a callback is added for this key

View File

@ -20,7 +20,7 @@ export class TipContainer extends Component {
}; };
} }
componentWillMount() { UNSAFE_componentWillMount() {
if (this.dispose) { if (this.dispose) {
this.dispose(); this.dispose();
} }

View File

@ -25,6 +25,7 @@ export class Title extends Component<{ title: TitleContent; className?: string;
} }
render() { render() {
// eslint-disable-next-line prefer-const
let { title, className } = this.props; let { title, className } = this.props;
if (title == null) { if (title == null) {
return null; return null;

View File

@ -0,0 +1,14 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
}
}

View File

@ -0,0 +1,16 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
'no-confusing-arrow': 1,
'no-case-declarations': 1,
}
}

View File

@ -74,7 +74,7 @@ export class ListSetter extends Component<ArraySetterProps, ArraySetterState> {
onSort(sortedIds: Array<string | number>) { onSort(sortedIds: Array<string | number>) {
const { itemsMap } = this.state; const { itemsMap } = this.state;
const { onChange, itemSetter, field } = this.props; const { onChange, itemSetter, field } = this.props;
const items = sortedIds.map((id, index) => { const items = sortedIds.map((id) => {
const item = itemsMap.get(id)!; const item = itemsMap.get(id)!;
// item.setKey(index); // item.setKey(index);
return item; return item;
@ -85,7 +85,8 @@ export class ListSetter extends Component<ArraySetterProps, ArraySetterState> {
}); });
// 对itemsMap重新生成并刷新当前setter数据 // 对itemsMap重新生成并刷新当前setter数据
const newItems = []; const newItemsMap = {}; const newItems = [];
// const newItemsMap = {};
itemsMap.clear(); itemsMap.clear();
for (let i = 0; i < items.length; i++) { for (let i = 0; i < items.length; i++) {
const newItem = field.createField({ const newItem = field.createField({
@ -128,7 +129,7 @@ export class ListSetter extends Component<ArraySetterProps, ArraySetterState> {
} }
onRemove(field: SettingField) { onRemove(field: SettingField) {
const { onChange, itemSetter } = this.props; const { onChange } = this.props;
const { items, itemsMap } = this.state; const { items, itemsMap } = this.state;
let i = items.indexOf(field); let i = items.indexOf(field);
const values = items.map((item) => { const values = items.map((item) => {
@ -235,7 +236,7 @@ class ArrayItem extends Component<{
render() { render() {
const { onRemove, field } = this.props; const { onRemove, field } = this.props;
return ( return (
<div className="lc-listitem" ref={(ref) => (this.shell = ref)}> <div className="lc-listitem" ref={(ref) => { this.shell = ref; }}>
<div draggable className="lc-listitem-handler"> <div draggable className="lc-listitem-handler">
<Icon type="ellipsis" size="small" /> <Icon type="ellipsis" size="small" />
</div> </div>

View File

@ -35,6 +35,7 @@ export class Field extends Component<FieldProps> {
private toggleExpand = () => { private toggleExpand = () => {
const { onExpandChange } = this.props; const { onExpandChange } = this.props;
// eslint-disable-next-line react/no-access-state-in-setstate
const collapsed = !this.state.collapsed; const collapsed = !this.state.collapsed;
this.setState({ this.setState({
collapsed, collapsed,
@ -130,7 +131,7 @@ export class Field extends Component<FieldProps> {
return null; return null;
} }
const { className, children, meta, title, valueState, onClear, name: propName, tip } = this.props; const { className, children, meta, title, valueState, name: propName, tip } = this.props;
const { display, collapsed } = this.state; const { display, collapsed } = this.state;
const isAccordion = display === 'accordion'; const isAccordion = display === 'accordion';
let hostName = ''; let hostName = '';
@ -160,7 +161,7 @@ export class Field extends Component<FieldProps> {
</div> </div>
) )
} }
<div key="body" ref={(shell) => (this.body = shell)} className="lc-field-body"> <div key="body" ref={(shell) => { this.body = shell; }} className="lc-field-body">
{children} {children}
</div> </div>
</div> </div>
@ -179,7 +180,7 @@ export class Field extends Component<FieldProps> {
* *
* TODO: turn number to enum * TODO: turn number to enum
*/ */
function createValueState(valueState?: number, onClear?: (e: React.MouseEvent) => void) { function createValueState(/* valueState?: number, onClear?: (e: React.MouseEvent) => void */) {
return null; return null;
/* /*
let tip: any = null; let tip: any = null;

View File

@ -146,7 +146,7 @@ export default class MixedSetter extends Component<{
private hasVariableSetter = this.setters.some((item) => item.name === 'VariableSetter'); private hasVariableSetter = this.setters.some((item) => item.name === 'VariableSetter');
private useSetter = (name: string) => { private useSetter = (name: string) => {
const { field, onChange } = this.props; const { field } = this.props;
if (name === 'VariableSetter') { if (name === 'VariableSetter') {
const setterComponent = getSetter('VariableSetter')?.component as any; const setterComponent = getSetter('VariableSetter')?.component as any;
if (setterComponent && setterComponent.isPopup) { if (setterComponent && setterComponent.isPopup) {
@ -350,7 +350,7 @@ export default class MixedSetter extends Component<{
} }
return ( return (
<div ref={(shell) => (this.shell = shell)} className={classNames('lc-setter-mixed', className)}> <div ref={(shell) => { this.shell = shell; }} className={classNames('lc-setter-mixed', className)}>
{contents.setterContent} {contents.setterContent}
<div className="lc-setter-actions">{contents.actions}</div> <div className="lc-setter-actions">{contents.actions}</div>
</div> </div>

View File

@ -1,5 +1,5 @@
import { Component, MouseEvent, Fragment } from 'react'; import { Component, MouseEvent, Fragment } from 'react';
import { shallowIntl, createSetterContent, observer, obx, Title } from '@ali/lowcode-editor-core'; import { shallowIntl, createSetterContent, observer, obx } from '@ali/lowcode-editor-core';
import { createContent } from '@ali/lowcode-utils'; import { createContent } from '@ali/lowcode-utils';
import { createField } from '../field'; import { createField } from '../field';
import PopupService, { PopupPipe } from '../popup'; import PopupService, { PopupPipe } from '../popup';
@ -12,6 +12,7 @@ import { Skeleton } from 'editor-skeleton/src/skeleton';
function transformStringToFunction(str) { function transformStringToFunction(str) {
if (typeof str !== 'string') return str; if (typeof str !== 'string') return str;
// eslint-disable-next-line no-new-func
return new Function(`"use strict"; return ${str}`)(); return new Function(`"use strict"; return ${str}`)();
} }
@ -128,6 +129,7 @@ class SettingFieldView extends Component<{ field: SettingField }> {
value, // reaction point value, // reaction point
onChange: (value: any) => { onChange: (value: any) => {
this.setState({ this.setState({
// eslint-disable-next-line react/no-unused-state
value, value,
}); });
field.setValue(value); field.setValue(value);
@ -139,6 +141,7 @@ class SettingFieldView extends Component<{ field: SettingField }> {
} }
const value = typeof initialValue === 'function' ? initialValue(field) : initialValue; const value = typeof initialValue === 'function' ? initialValue(field) : initialValue;
this.setState({ this.setState({
// eslint-disable-next-line react/no-unused-state
value, value,
}); });
field.setValue(value); field.setValue(value);

View File

@ -11,7 +11,7 @@ export default class SlotSetter extends Component<{
supportParams?: boolean; supportParams?: boolean;
}> { }> {
private handleInitial = () => { private handleInitial = () => {
const { value, onChange, onInitial } = this.props; const { onChange, onInitial } = this.props;
if (onInitial) { if (onInitial) {
onInitial(); onInitial();
return; return;

View File

@ -7,7 +7,7 @@ import { isPlainObject } from '@ali/lowcode-utils';
import parseProps from './transducers/parse-props'; import parseProps from './transducers/parse-props';
import addonCombine from './transducers/addon-combine'; import addonCombine from './transducers/addon-combine';
import SlotSetter from './components/slot-setter'; import SlotSetter from './components/slot-setter';
import { isJSSlot, isJSExpression } from '@ali/lowcode-types'; import { isJSSlot } from '@ali/lowcode-types';
export const registerDefaults = () => { export const registerDefaults = () => {
registerSetter('ArraySetter', { registerSetter('ArraySetter', {

View File

@ -4,7 +4,6 @@ import {
PropType, PropType,
SetterType, SetterType,
OneOf, OneOf,
Shape,
ObjectOf, ObjectOf,
ArrayOf, ArrayOf,
TransformedComponentMetadata, TransformedComponentMetadata,

View File

@ -52,6 +52,7 @@ export default class PanelDock implements IWidget {
} }
getDOMNode() { getDOMNode() {
// eslint-disable-next-line react/no-find-dom-node
return this._shell ? findDOMNode(this._shell) : null; return this._shell ? findDOMNode(this._shell) : null;
} }

View File

@ -82,7 +82,7 @@ export default class Panel implements IWidget {
constructor(readonly skeleton: Skeleton, readonly config: PanelConfig) { constructor(readonly skeleton: Skeleton, readonly config: PanelConfig) {
const { name, content, props = {} } = config; const { name, content, props = {} } = config;
const { hideTitleBar, title, icon, description, help, shortcut } = props; const { hideTitleBar, title, icon, description, help } = props;
this.name = name; this.name = name;
this.id = uniqueId(`pane:${name}$`); this.id = uniqueId(`pane:${name}$`);
this.title = composeTitle(title || name, icon, description); this.title = composeTitle(title || name, icon, description);
@ -207,7 +207,7 @@ export default class Panel implements IWidget {
/** /**
* @deprecated * @deprecated
*/ */
setPosition(position: string) { setPosition(/* position: string */) {
// noop // noop
} }

View File

@ -1,4 +1,4 @@
import { uniqueId } from '@ali/lowcode-utils'; // import { uniqueId } from '@ali/lowcode-utils';
import Widget from './widget'; import Widget from './widget';
import { Skeleton } from '../skeleton'; import { Skeleton } from '../skeleton';
import { WidgetConfig } from '../types'; import { WidgetConfig } from '../types';

View File

@ -25,12 +25,14 @@ export default class WidgetContainer<T extends WidgetItem = any, G extends Widge
return this._current; return this._current;
} }
// eslint-disable-next-line no-useless-constructor
constructor( constructor(
readonly name: string, readonly name: string,
private handle: (item: T | G) => T, private handle: (item: T | G) => T,
private exclusive: boolean = false, private exclusive: boolean = false,
private checkVisible: () => boolean = () => true, private checkVisible: () => boolean = () => true,
private defaultSetCurrent: boolean = false, private defaultSetCurrent: boolean = false,
// eslint-disable-next-line no-empty-function
) {} ) {}
@computed get visible() { @computed get visible() {

View File

@ -0,0 +1,14 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
}
}

View File

@ -0,0 +1,14 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
}
}

View File

@ -20,7 +20,9 @@ const originCloneElement = (window as any).Rax.cloneElement;
} else { } else {
try { try {
cRef.current = x; cRef.current = x;
} catch (e) {} } catch (e) {
console.error(e);
}
} }
} }
if (dRef) { if (dRef) {
@ -29,7 +31,9 @@ const originCloneElement = (window as any).Rax.cloneElement;
} else { } else {
try { try {
dRef.current = x; dRef.current = x;
} catch (e) {} } catch (e) {
console.error(e);
}
} }
} }
}; };

View File

@ -2,7 +2,7 @@ import { BuiltinSimulatorRenderer, NodeInstance, Component } from '@ali/lowcode-
import { shared, render as raxRender, createElement } from 'rax'; import { shared, render as raxRender, createElement } from 'rax';
import DriverUniversal from 'driver-universal'; import DriverUniversal from 'driver-universal';
import { computed, obx } from '@recore/obx'; import { computed, obx } from '@recore/obx';
import { RootSchema, NpmInfo, ComponentSchema } from '@ali/lowcode-types'; import { RootSchema, NpmInfo } from '@ali/lowcode-types';
import { Asset, isReactComponent, isESModule, setNativeSelection, cursor, isElement } from '@ali/lowcode-utils'; import { Asset, isReactComponent, isESModule, setNativeSelection, cursor, isElement } from '@ali/lowcode-utils';
import SimulatorRendererView from './renderer-view'; import SimulatorRendererView from './renderer-view';
@ -135,7 +135,7 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer {
this.buildComponents(); this.buildComponents();
} }
}); });
host.injectionConsumer.consume((data) => { host.injectionConsumer.consume(() => {
// sync utils, i18n, contants,... config // sync utils, i18n, contants,... config
this._appContext = { this._appContext = {
utils: {}, utils: {},
@ -183,7 +183,7 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer {
// return null; // return null;
} }
createComponent(schema: ComponentSchema): Component | null { createComponent(/* schema: ComponentSchema */): Component | null {
return null; return null;
} }
@ -404,7 +404,7 @@ function buildComponents(libraryMap: LibraryMap, componentsMap: { [componentName
return components; return components;
} }
function getClosestNodeInstance(from: any, specId?: string): NodeInstance<any> | null { function getClosestNodeInstance(from: any): NodeInstance<any> | null {
const el: any = from; const el: any = from;
if (el) { if (el) {
// if (isElement(el)) { // if (isElement(el)) {

View File

@ -9,6 +9,7 @@ export function raxFindDOMNodes(instance: any): Array<Element | Text> | null {
if (isElement(instance)) { if (isElement(instance)) {
return [instance]; return [instance];
} }
// eslint-disable-next-line react/no-find-dom-node
const result = findDOMNode(instance); const result = findDOMNode(instance);
if (Array.isArray(result)) { if (Array.isArray(result)) {
return result; return result;

View File

@ -53,5 +53,5 @@
"publishConfig": { "publishConfig": {
"registry": "http://registry.npm.alibaba-inc.com" "registry": "http://registry.npm.alibaba-inc.com"
}, },
"homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.7-0/build/index.html" "homepage": "https://unpkg.alibaba-inc.com/@ali/lowcode-react-renderer@1.0.8-0/build/index.html"
} }

View File

@ -0,0 +1,15 @@
module.exports = {
extends: 'eslint-config-ali/typescript/react',
rules: {
'react/no-multi-comp': 1,
'no-unused-expressions': 1,
'implicit-arrow-linebreak': 1,
'no-nested-ternary': 1,
'no-mixed-operators': 1,
'@typescript-eslint/no-parameter-properties': 1,
'@typescript-eslint/ban-types': 1,
'no-shadow': 1,
'no-prototype-builtins': 1,
'array-callback-return': 1,
}
}

View File

@ -152,6 +152,7 @@ const supportedEvents = [
}, },
]; ];
// eslint-disable-next-line func-call-spacing
const builtinComponents = new Map<string, (props: any) => ReactElement>(); const builtinComponents = new Map<string, (props: any) => ReactElement>();
function getBlockElement(tag: string): (props: any) => ReactElement { function getBlockElement(tag: string): (props: any) => ReactElement {
if (builtinComponents.has(tag)) { if (builtinComponents.has(tag)) {

View File

@ -19,7 +19,9 @@ const originCloneElement = window.React.cloneElement;
} else { } else {
try { try {
cRef.current = x; cRef.current = x;
} catch (e) {} } catch (e) {
console.error(e);
}
} }
} }
if (dRef) { if (dRef) {
@ -28,7 +30,9 @@ const originCloneElement = window.React.cloneElement;
} else { } else {
try { try {
dRef.current = x; dRef.current = x;
} catch (e) {} } catch (e) {
console.error(e);
}
} }
} }
}; };

View File

@ -1,4 +1,4 @@
import React, { createElement, ReactInstance, ComponentType, ReactElement, FunctionComponent } from 'react'; import React, { createElement, ReactInstance } from 'react';
import { render as reactRender } from 'react-dom'; import { render as reactRender } from 'react-dom';
import { host } from './host'; import { host } from './host';
import SimulatorRendererView from './renderer-view'; import SimulatorRendererView from './renderer-view';
@ -63,7 +63,7 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer {
this.buildComponents(); this.buildComponents();
} }
}); });
host.injectionConsumer.consume((data) => { host.injectionConsumer.consume(() => {
// sync utils, i18n, contants,... config // sync utils, i18n, contants,... config
this._appContext = { this._appContext = {
utils: {}, utils: {},
@ -237,8 +237,6 @@ export class SimulatorRenderer implements BuiltinSimulatorRenderer {
subs.unshift(sub); subs.unshift(sub);
componentName = paths.join('.'); componentName = paths.join('.');
} }
return null;
} }
getComponentInstances(id: string): ReactInstance[] | null { getComponentInstances(id: string): ReactInstance[] | null {