Skip to content

Commit

Permalink
fix: update types
Browse files Browse the repository at this point in the history
  • Loading branch information
wwsun committed Aug 1, 2024
1 parent 8dd289c commit 67d602a
Show file tree
Hide file tree
Showing 25 changed files with 57 additions and 42 deletions.
2 changes: 1 addition & 1 deletion packages/core/src/helpers/assert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function isTangoVariable(name: string) {
return /^tango\??\.(stores|services)\??\./.test(name) && name.split('.').length > 2;
}

const templatePattern = /^{(.+)}$/s;
const templatePattern = /^{(.+)}$/;

/**
* 判断给定字符串是否被表达式容器`{expCode}`包裹
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/helpers/object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export function namesToImportDeclarations(
names: string[],
nameMap: Dict<IImportSpecifierSourceData>,
) {
const map = {};
const map: Dict = {};
names.forEach((name) => {
const mod = nameMap[name];
if (mod) {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/helpers/schema-helpers.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { parseDndId, uuid } from '@music163/tango-helpers';
import { Dict, parseDndId, uuid } from '@music163/tango-helpers';

// { id: 1, component, props: { id: 1 }, children: [ { id: 2, component } ] }
export function deepCloneNode(obj: any, component?: string): any {
function deepCloneObject() {
const target = {};
const target: Dict = {};
for (const key in obj) {
if (Object.hasOwn(obj, key)) {
target[key] = deepCloneNode(obj[key], component);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { isValidFunctionCode, url2serviceName } from '@music163/tango-helpers';
import { Dict, isValidFunctionCode, url2serviceName } from '@music163/tango-helpers';
import { InputCode } from '@music163/tango-ui';
import { Button, Dropdown, Form, FormProps, Input, Select, Space } from 'antd';
import { Box } from 'coral-system';
import React, { useState } from 'react';

interface AddServiceFormProps extends FormProps {
initialValues?: object;
initialValues?: Dict;
onSubmit: (values: object) => void;
onCancel: () => void;
serviceModules: object[];
Expand Down
4 changes: 3 additions & 1 deletion packages/designer/src/dnd/hotkey.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import { Dict } from '@music163/tango-helpers';

/**
* 快捷键
*/
export class Hotkey {
private readonly hotkeyMap = {};
private readonly hotkeyMap: Dict = {};

constructor(hotkeys: Record<string, Function>) {
Object.keys(hotkeys).forEach((hotkey) => {
Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/sandbox/sandbox.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useImperativeHandle, ForwardedRef, useRef, useState, useEffect } from 'react';
import { Box } from 'coral-system';
import { CodeSandbox, CodeSandboxProps } from '@music163/tango-sandbox';
import { getValue, isFunction, logger, pick, setValue } from '@music163/tango-helpers';
import { Dict, getValue, isFunction, logger, pick, setValue } from '@music163/tango-helpers';
import { observer, useWorkspace, useDesigner } from '@music163/tango-context';
import { Simulator, Viewport } from '../simulator';
import { useSandboxQuery } from '../context';
Expand Down Expand Up @@ -88,7 +88,7 @@ function useSandbox({
onViewChange: (data) => onViewChange && onViewChange(data, getSandboxConfig()),
});

let files = Array.from(workspace.files.keys()).reduce((prev, filename) => {
let files = Array.from(workspace.files.keys()).reduce<Dict>((prev, filename) => {
let code = workspace.getFile(filename).code;
if (filename === '/tango.config.json') {
code = mergeTangoConfigJson(code, { isPreview, injectScript, formatter: configFormatter });
Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/setters/event-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { AutoComplete } from 'antd';
import { ActionSelect } from '@music163/tango-ui';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { useWorkspace, useWorkspaceData } from '@music163/tango-context';
import { wrapCode } from '@music163/tango-helpers';
import { Dict, wrapCode } from '@music163/tango-helpers';
import { ExpressionPopover } from './expression-setter';
import { value2code } from '@music163/tango-core';

Expand Down Expand Up @@ -141,7 +141,7 @@ export function EventSetter(props: EventSetterProps) {
);
}

const handlerMap = {
const handlerMap: Dict = {
[EventAction.OpenModal]: 'openModal',
[EventAction.CloseModal]: 'closeModal',
[EventAction.NavigateTo]: 'navigateTo',
Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/setters/expression-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function ExpressionPopover({
}));

const sandbox = useSandboxQuery();
const evaluateContext = sandbox.window;
const evaluateContext: any = sandbox.window;

const handleExpInputChange = (val: string) => {
setExp(val?.trim());
Expand Down Expand Up @@ -253,7 +253,7 @@ export function ExpressionPopover({
height="100%"
showViewButton
dataSource={dataSource || expressionVariables}
appContext={sandbox?.window['tango']}
appContext={evaluateContext['tango']}
getStoreNames={() => Object.keys(workspace.storeModules)}
serviceModules={serviceModules}
getServiceData={(serviceKey) => {
Expand Down
5 changes: 3 additions & 2 deletions packages/designer/src/setters/list-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ import { css, Box } from 'coral-system';
import { Form, Input, Button, Popover } from 'antd';
import { DeleteOutlined, EditOutlined, HolderOutlined } from '@ant-design/icons';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { Dict } from '@music163/tango-helpers';
import { DragBox } from '../components';

function copyWithoutUndefined(source: Record<string, any>) {
const ret = {};
function copyWithoutUndefined(source: Dict) {
const ret: Dict = {};
for (const key in source) {
if (source[key] !== undefined) {
ret[key] = source[key];
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/setters/model-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export function ModelSetter({
}: FormItemComponentProps) {
const [inputValue, setInputValue] = useState(value);
const { modelVariables } = useWorkspaceData();
const evaluateContext = useSandboxQuery().window || {};
const evaluateContext: any = useSandboxQuery().window || {};
const workspace = useWorkspace();
const definedVariables = useMemo(() => {
const list: string[] = [];
Expand Down
3 changes: 2 additions & 1 deletion packages/designer/src/setters/render-setter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useMemo, useState } from 'react';
import { ActionSelect, InputCode } from '@music163/tango-ui';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { Box } from 'coral-system';
import { Dict } from '@music163/tango-helpers';

interface IRenderOption {
label: string;
Expand Down Expand Up @@ -37,7 +38,7 @@ export function RenderSetter({
}, [value]);

const optionsMap = useMemo(() => {
return options.reduce((prev, cur) => {
return options.reduce<Dict>((prev, cur) => {
prev[cur.value] = cur;
return prev;
}, {});
Expand Down
10 changes: 8 additions & 2 deletions packages/designer/src/setters/router-setter.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
import React, { useEffect, useState } from 'react';
import { Box } from 'coral-system';
import { Input, Radio } from 'antd';
import { isValidUrl } from '@music163/tango-helpers';
import { Dict, isValidUrl } from '@music163/tango-helpers';
import { FormItemComponentProps } from '@music163/tango-setting-form';
import { useWorkspaceData } from '@music163/tango-context';
import { PickerSetter } from './picker-setter';

const routerModeMap: Dict = {
link: '链接',
router: '路由',
both: '',
};

export function RouterSetter(props: FormItemComponentProps) {
const [type, setType] = useState<'input' | 'select'>(() => {
return isValidUrl(props.value) ? 'input' : 'select';
Expand Down Expand Up @@ -37,7 +43,7 @@ export function RouterSetter(props: FormItemComponentProps) {
)}
{type === 'input' && (
<Input
placeholder={`请输入任意${{ link: '链接', router: '路由', both: '' }[displayType]}地址`}
placeholder={`请输入任意${routerModeMap[displayType]}地址`}
{...props}
value={input}
onChange={(e) => setInput(e.target.value)}
Expand Down
4 changes: 2 additions & 2 deletions packages/designer/src/setting-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React from 'react';
import { Box } from 'coral-system';
import { SettingForm, FormModel, SettingFormProps } from '@music163/tango-setting-form';
import { Panel } from '@music163/tango-ui';
import { clone, parseDndId } from '@music163/tango-helpers';
import { clone, Dict, parseDndId } from '@music163/tango-helpers';
import { observer, useDesigner, useWorkspace } from '@music163/tango-context';
import { registerBuiltinSetters } from './setters';

Expand Down Expand Up @@ -34,7 +34,7 @@ export const SettingPanel = observer((props: SettingPanelProps) => {
}

const getSettingValue = (attributes: Record<string, string>) => {
const ret = {};
const ret: Dict = {};
const keys = Object.keys(attributes);
for (const key of keys) {
if (/^data-/.test(key)) {
Expand Down
5 changes: 3 additions & 2 deletions packages/designer/src/sidebar/components-panel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, { useMemo, useState } from 'react';
import { Box, Grid, Text } from 'coral-system';
import styled, { css } from 'styled-components';
import {
Dict,
IComponentPrototype,
MenuDataType,
MenuValueType,
Expand Down Expand Up @@ -66,7 +67,7 @@ export interface ComponentsPanelProps {
layout?: 'grid' | 'line';
}

const localeMap = {
const localeMap: Dict = {
common: '基础组件',
atom: '原子组件',
snippet: '组合',
Expand Down Expand Up @@ -124,7 +125,7 @@ export const ComponentsPanel = observer(
const tabs = Object.keys(menuData).map((key) => ({
key,
label: localeMap[key],
children: <MaterialList data={menuData[key]} />,
children: <MaterialList data={(menuData as any)[key]} />,
}));

if (showBizComps) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ const DataSourceView = observer(() => {
<Box className="ServiceFunctionList" p="m">
<VariableTree
dataSource={serviceVariables}
appContext={sandbox?.window['tango']}
appContext={(sandbox?.window as any)['tango']}
serviceModules={serviceModules}
onRemoveService={(variableKey) => {
workspace.removeServiceFunction(variableKey);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ConfigGroup, ConfigItem } from '@music163/tango-ui';
import { Box, css } from 'coral-system';
import { Input, Switch, Form, Button, message, FormProps } from 'antd';
import { CloseCircleOutlined, CloseOutlined } from '@ant-design/icons';
import { Dict } from '@music163/tango-helpers';

export default observer(() => {
const workspace = useWorkspace();
Expand Down Expand Up @@ -63,7 +64,7 @@ function ProxyManage({
initialValues: initialValuesProp = {},
onSave,
}: {
initialValues?: object;
initialValues?: Dict;
onSave?: (values: any) => void;
}) {
const initialValues = useMemo(() => {
Expand All @@ -84,7 +85,7 @@ function ProxyManage({
{...proxyManageFormStyle}
initialValues={initialValues}
onFinish={(values) => {
const proxy = values.proxy.reduce((prev: object, { path, ...rest }: any) => {
const proxy = values.proxy.reduce((prev: any, { path, ...rest }: any) => {
prev[path] = rest;
return prev;
}, {});
Expand Down
8 changes: 4 additions & 4 deletions packages/designer/src/sidebar/outline-panel/state-tree.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import React, { useEffect, useReducer } from 'react';
import { observer } from '@music163/tango-context';
import { isFunction, isObject, pick } from '@music163/tango-helpers';
import { Dict, isFunction, isObject, pick } from '@music163/tango-helpers';
import { CollapsePanel, IconButton, JsonView } from '@music163/tango-ui';
import { ReloadOutlined } from '@ant-design/icons';
import { useSandboxQuery } from '../../context';

function processTango(obj: any = {}, index = 0) {
const ret = {};
function processTango(obj: Dict = {}, index = 0) {
const ret: Dict = {};
Object.keys(obj).forEach((key) => {
const val = obj[key];
if (index > 2) {
Expand All @@ -25,7 +25,7 @@ function processTango(obj: any = {}, index = 0) {
export const StateTree = observer(() => {
const sandboxQuery = useSandboxQuery();
const [, forceUpdate] = useReducer((x) => x + 1, 0);
const tangoContext = pick(sandboxQuery.window['tango'] || {}, [
const tangoContext = pick((sandboxQuery.window as any)['tango'] || {}, [
'stores',
'pageStore',
'services',
Expand Down
2 changes: 1 addition & 1 deletion packages/designer/src/sidebar/resizable-box.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const resizeHandleStyle = (axis: ResizableBoxProps['axis'], barStyle: HTMLCoralP
cursor: ${axis === 'x' ? 'col-resize' : 'row-resize'};
${barStyle &&
Object.keys(barStyle)
.map((key) => `${key}: ${barStyle[key]};`)
.map((key) => `${key}: ${(barStyle as any)[key]};`)
.join('')}
&:hover,
&:active {
Expand Down
4 changes: 2 additions & 2 deletions packages/helpers/src/helpers/array.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ export function filterTreeData<T = unknown>(
childrenProp = 'children',
onlyLeaf = false,
) {
const reducer = (result: T[], current: T) => {
const reducer = (result: T[], current: any) => {
if (current[childrenProp]) {
const newChildren = current[childrenProp].reduce(reducer, []);
if (newChildren.length) {
Expand All @@ -70,7 +70,7 @@ export function mapTreeData<T = unknown>(
mapper: (node: T) => any,
childrenProp = 'children',
) {
return treeData.map((node) => {
return treeData.map((node: any) => {
const newNode = mapper(node);
if (node[childrenProp]) {
newNode[childrenProp] = mapTreeData(node[childrenProp], mapper, childrenProp);
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/src/helpers/code-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function isValidFunctionCode(str: string) {
}
}

const templatePattern = /^{{(.+)}}$/s;
const templatePattern = /^{{(.+)}}$/;

/**
* 判断给定代码是否被双花括号包裹
Expand Down
5 changes: 3 additions & 2 deletions packages/helpers/src/helpers/object.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import get from 'lodash.get';
import set from 'lodash.set';
import { Dict } from '../types';

/**
* 合并 target 和 source 对象,source 对象的优先级更高,如存在重名,覆盖 target 中的 key
Expand Down Expand Up @@ -45,7 +46,7 @@ export function clone(obj: any, withUndefined = true) {
return obj;
}

const target = {};
const target: Dict = {};
for (const key in obj) {
if (withUndefined) {
target[key] = obj[key];
Expand All @@ -65,7 +66,7 @@ export function omit(obj: any, keys: string[]) {
}

export function pick(obj: any, keys: string[]) {
const target = {};
const target: Dict = {};
for (const key of keys) {
target[key] = obj[key];
}
Expand Down
2 changes: 1 addition & 1 deletion packages/helpers/src/hoc/with-dnd.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export function withDnd(options: IWithDndOptions<any>) {
const override = options.overrideProps || {};
const renderFooter = options.renderFooter || renderEmpty;

const Component = forwardRef<unknown, P & DraggableComponentProps>((props, refProp) => {
const Component = forwardRef<unknown, P & DraggableComponentProps>((props: any, refProp) => {
const dndProps = {
[SLOT.id]: props.tid, // id 作为唯一标记
[SLOT.dnd]: props[SLOT.dnd], // dnd 作为追踪标记
Expand Down
5 changes: 3 additions & 2 deletions packages/helpers/src/stores/list-store.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { warning } from '../helpers';
import { Dict } from '../types';

type ListStoreOptionsType<T = object> = {
type ListStoreOptionsType<T extends Dict = Dict> = {
data: T[];
keyProp?: string;
labelProp?: string;
childrenProp?: string;
};

export class ListStore<T = object> {
export class ListStore<T extends Dict = Dict> {
private nodeMap: Map<string, T>;
private keyProp: string;
private childrenProp: string;
Expand Down
3 changes: 2 additions & 1 deletion packages/setting-form/src/form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
noop,
filterTreeData,
mapTreeData,
Dict,
} from '@music163/tango-helpers';
import { Action, Search, Tabs } from '@music163/tango-ui';
import { SettingFormItem, register } from './form-item';
Expand All @@ -24,7 +25,7 @@ function normalizeComponentProps(
props: IComponentPrototype['props'],
groupOptions: IFormTabsGroupOption[],
) {
const groups: Record<string, IComponentProp[]> = groupOptions.reduce((prev, cur) => {
const groups: Record<string, IComponentProp[]> = groupOptions.reduce<Dict>((prev, cur) => {
prev[cur.value] = [];
return prev;
}, {});
Expand Down
Loading

0 comments on commit 67d602a

Please sign in to comment.