mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-21 03:15:49 +08:00
chore: fix code style
This commit is contained in:
parent
b799120fd3
commit
4fc48f6570
@ -26,8 +26,7 @@ import { globalHandlerMap } from './handler';
|
||||
type ArrayElement<ArrayType extends readonly unknown[]> =
|
||||
ArrayType extends readonly (infer ElementType)[] ? ElementType : never;
|
||||
|
||||
type ApplicationComponents = RuntimeApplication['spec']['components'];
|
||||
type ApplicationComponent = ApplicationComponents[0];
|
||||
type ApplicationComponent = RuntimeApplication['spec']['components'][0];
|
||||
type ApplicationTrait = ArrayElement<ApplicationComponent['traits']>;
|
||||
|
||||
export const ImplWrapper = React.forwardRef<
|
||||
|
@ -1,4 +1,4 @@
|
||||
import React, { useEffect, useMemo, useRef } from 'react';
|
||||
import React, { useRef } from 'react';
|
||||
import {
|
||||
Application,
|
||||
createComponent,
|
||||
@ -6,11 +6,9 @@ import {
|
||||
} from '@meta-ui/core';
|
||||
import { Static, Type } from '@sinclair/typebox';
|
||||
import { List as BaseList, ListItem as BaseListItem } from '@chakra-ui/react';
|
||||
import Text, { TextProps, TextPropertySchema } from '../_internal/Text';
|
||||
import { ComponentImplementation } from '../../registry';
|
||||
import { ImplWrapper, resolveAppComponents } from '../../App';
|
||||
import { mapValuesDeep, maskedEval } from '../../store';
|
||||
import { values } from 'lodash';
|
||||
import { parseType } from '../../util-methods';
|
||||
import { LIST_ITEM_EXP, LIST_ITEM_INDEX_EXP } from '../../constants';
|
||||
|
||||
@ -34,7 +32,7 @@ const List: ComponentImplementation<{
|
||||
listData: Static<typeof ListDataPropertySchema>;
|
||||
template: Static<typeof TemplatePropertySchema>;
|
||||
onClick?: () => void;
|
||||
}> = ({ listData, template, mergeState, subscribeMethods, app }) => {
|
||||
}> = ({ listData, template, app }) => {
|
||||
if (!listData) {
|
||||
return null;
|
||||
}
|
||||
@ -42,24 +40,22 @@ const List: ComponentImplementation<{
|
||||
const parsedtemplete = template.map(parseTypeComponents);
|
||||
|
||||
const listItems = listData.map((listItem, i) => {
|
||||
// this memo only diff listItem, dosen't compare expressions
|
||||
if (itemElementMemo.current.has(listItem.id)) {
|
||||
if (itemElementMemo.current.get(listItem.id).value === listItem) {
|
||||
return itemElementMemo.current.get(listItem.id).ele;
|
||||
}
|
||||
}
|
||||
|
||||
const evaledTemplate = mapValuesDeep(
|
||||
{ parsedtemplete },
|
||||
({ value, key }) => {
|
||||
if (typeof value === 'string') {
|
||||
return maskedEval(value, true, {
|
||||
[LIST_ITEM_EXP]: listItem,
|
||||
[LIST_ITEM_INDEX_EXP]: i,
|
||||
});
|
||||
}
|
||||
return value;
|
||||
const evaledTemplate = mapValuesDeep({ parsedtemplete }, ({ value }) => {
|
||||
if (typeof value === 'string') {
|
||||
return maskedEval(value, true, {
|
||||
[LIST_ITEM_EXP]: listItem,
|
||||
[LIST_ITEM_INDEX_EXP]: i,
|
||||
});
|
||||
}
|
||||
).parsedtemplete;
|
||||
return value;
|
||||
}).parsedtemplete;
|
||||
|
||||
const { topLevelComponents, slotComponentsMap } = resolveAppComponents(
|
||||
evaledTemplate,
|
||||
|
@ -61,6 +61,7 @@ export type ComponentMergedProps = {
|
||||
style?: CSSProperties;
|
||||
data?: Record<string, any>;
|
||||
callbackMap?: CallbackMap;
|
||||
app?: RuntimeApplication;
|
||||
};
|
||||
|
||||
export type ComponentImplementation<T = any> = React.FC<
|
||||
|
@ -17,7 +17,6 @@ const ArrayStateTrait: TraitImplementation<{
|
||||
if (!hasInitialized) {
|
||||
mergeState({ [key]: initialValue });
|
||||
|
||||
const upperCaseKey = capitalizeFirstLetter(key);
|
||||
const methods = {
|
||||
setArray({ key, value }: KeyValue) {
|
||||
mergeState({ [key]: value });
|
||||
@ -51,10 +50,6 @@ const ArrayStateTrait: TraitImplementation<{
|
||||
};
|
||||
};
|
||||
|
||||
function capitalizeFirstLetter(str: string) {
|
||||
return str.charAt(0).toUpperCase() + str.slice(1);
|
||||
}
|
||||
|
||||
const KeyPropertySchema = Type.String();
|
||||
const InitialValuePropertySchema = Type.Array(Type.Any());
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user