mirror of
https://github.com/NetEase/tango.git
synced 2026-08-29 02:01:34 +08:00
fix: update types
This commit is contained in:
@@ -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}`包裹
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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[];
|
||||
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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';
|
||||
@@ -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 });
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -141,7 +141,7 @@ export function EventSetter(props: EventSetterProps) {
|
||||
);
|
||||
}
|
||||
|
||||
const handlerMap = {
|
||||
const handlerMap: Dict = {
|
||||
[EventAction.OpenModal]: 'openModal',
|
||||
[EventAction.CloseModal]: 'closeModal',
|
||||
[EventAction.NavigateTo]: 'navigateTo',
|
||||
|
||||
@@ -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());
|
||||
@@ -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) => {
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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[] = [];
|
||||
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}, {});
|
||||
|
||||
@@ -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';
|
||||
@@ -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)}
|
||||
|
||||
@@ -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';
|
||||
|
||||
@@ -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)) {
|
||||
|
||||
@@ -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,
|
||||
@@ -66,7 +67,7 @@ export interface ComponentsPanelProps {
|
||||
layout?: 'grid' | 'line';
|
||||
}
|
||||
|
||||
const localeMap = {
|
||||
const localeMap: Dict = {
|
||||
common: '基础组件',
|
||||
atom: '原子组件',
|
||||
snippet: '组合',
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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();
|
||||
@@ -63,7 +64,7 @@ function ProxyManage({
|
||||
initialValues: initialValuesProp = {},
|
||||
onSave,
|
||||
}: {
|
||||
initialValues?: object;
|
||||
initialValues?: Dict;
|
||||
onSave?: (values: any) => void;
|
||||
}) {
|
||||
const initialValues = useMemo(() => {
|
||||
@@ -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;
|
||||
}, {});
|
||||
|
||||
@@ -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) {
|
||||
@@ -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',
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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) {
|
||||
@@ -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);
|
||||
|
||||
@@ -32,7 +32,7 @@ export function isValidFunctionCode(str: string) {
|
||||
}
|
||||
}
|
||||
|
||||
const templatePattern = /^{{(.+)}}$/s;
|
||||
const templatePattern = /^{{(.+)}}$/;
|
||||
|
||||
/**
|
||||
* 判断给定代码是否被双花括号包裹
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import get from 'lodash.get';
|
||||
import set from 'lodash.set';
|
||||
import { Dict } from '../types';
|
||||
|
||||
/**
|
||||
* 合并 target 和 source 对象,source 对象的优先级更高,如存在重名,覆盖 target 中的 key
|
||||
@@ -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];
|
||||
@@ -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];
|
||||
}
|
||||
|
||||
@@ -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 作为追踪标记
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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';
|
||||
@@ -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;
|
||||
}, {});
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { Menu, Space } from 'antd';
|
||||
import { Box, css } from 'coral-system';
|
||||
import { isApplePlatform } from '@music163/tango-helpers';
|
||||
import { Dict, isApplePlatform } from '@music163/tango-helpers';
|
||||
|
||||
const contextActionStyle = css`
|
||||
display: flex;
|
||||
@@ -46,7 +46,7 @@ export function ContextAction({
|
||||
if (!hotkey) {
|
||||
return null;
|
||||
}
|
||||
const keyMap = isApplePlatform()
|
||||
const keyMap: Dict = isApplePlatform()
|
||||
? {
|
||||
command: '⌘',
|
||||
meta: '⌘',
|
||||
|
||||
Reference in New Issue
Block a user