From 1f936fc34e199ad70237517aec3ffd5da3522026 Mon Sep 17 00:00:00 2001 From: rdmclin2 Date: Sat, 22 Jul 2023 23:21:50 +0800 Subject: [PATCH] :heavy_minus_sign: chore: remove @c2d2c/utils --- package.json | 1 - src/ComponentAsset/ComponentAsset.tsx | 2 +- src/ComponentAsset/types/index.ts | 2 +- src/LevaPanel/Schema.tsx | 2 +- src/types/catogory.ts | 22 ++++++++++++++++++++++ src/types/index.ts | 24 ++---------------------- src/{ComponentAsset => }/types/schema.ts | 0 src/utils/index.ts | 1 + src/utils/schema.ts | 12 ++++++++++++ 9 files changed, 40 insertions(+), 26 deletions(-) create mode 100644 src/types/catogory.ts rename src/{ComponentAsset => }/types/schema.ts (100%) create mode 100644 src/utils/schema.ts diff --git a/package.json b/package.json index befbec8d..6f5d5179 100644 --- a/package.json +++ b/package.json @@ -62,7 +62,6 @@ "@antv/dw-random": "^1", "@babel/runtime": "^7.21.5", "@c2d2c/types": "^1", - "@c2d2c/utils": "^1", "@dnd-kit/core": "^6", "@dnd-kit/modifiers": "^6", "@dnd-kit/sortable": "^7", diff --git a/src/ComponentAsset/ComponentAsset.tsx b/src/ComponentAsset/ComponentAsset.tsx index 5fc6a643..b24af4a8 100644 --- a/src/ComponentAsset/ComponentAsset.tsx +++ b/src/ComponentAsset/ComponentAsset.tsx @@ -1,8 +1,8 @@ /*eslint no-invalid-this: "error"*/ -import { getDefaultValueFromSchema } from '@c2d2c/utils'; import { FC, ReactNode } from 'react'; import { StoreApi } from 'zustand'; import type { UseBoundStore } from 'zustand/react'; +import { getDefaultValueFromSchema } from '../utils'; import type { EditorMode } from '../ProEditor'; import type { AssetModels, CanvasRule, CodeEmitter, ComponentAssetParams } from './types'; diff --git a/src/ComponentAsset/types/index.ts b/src/ComponentAsset/types/index.ts index 5f142665..f9a82d93 100644 --- a/src/ComponentAsset/types/index.ts +++ b/src/ComponentAsset/types/index.ts @@ -1,5 +1,5 @@ +export * from '../../types/schema'; export * from './asset'; export * from './code'; export * from './model'; export * from './render'; -export * from './schema'; diff --git a/src/LevaPanel/Schema.tsx b/src/LevaPanel/Schema.tsx index a27a9e62..ee655cc1 100644 --- a/src/LevaPanel/Schema.tsx +++ b/src/LevaPanel/Schema.tsx @@ -1,11 +1,11 @@ import { JSONSchema } from '@/ComponentAsset'; -import { getDefaultValueFromSchema } from '@c2d2c/utils'; import { useMemoizedFn } from 'ahooks'; import isEqual from 'fast-deep-equal'; import { useControls, useStoreContext } from 'leva'; import { DataInput } from 'leva/src/types'; import merge from 'lodash.merge'; import { ReactNode, memo, useEffect, useMemo } from 'react'; +import { getDefaultValueFromSchema } from '../utils'; import { SchemaItem, toLevaSchema } from './utils/schema'; diff --git a/src/types/catogory.ts b/src/types/catogory.ts new file mode 100644 index 00000000..a70e706d --- /dev/null +++ b/src/types/catogory.ts @@ -0,0 +1,22 @@ +import type { CategoryConfig } from '@c2d2c/types'; + +export enum CategoryMap { + type = 'type', + content = 'content', + function = 'function', + style = 'style', + status = 'status', + bind = 'bind', + table = 'table', + customStyle = 'customStyle', +} + +export const configCategoryMap: CategoryConfig = { + [CategoryMap.type]: { title: '类型', defaultActive: true }, + [CategoryMap.content]: { title: '内容与功能', defaultActive: true }, + [CategoryMap.style]: { title: '样式', defaultActive: true }, + [CategoryMap.status]: { title: '状态', defaultActive: true }, + [CategoryMap.bind]: { title: '分页字段绑定', defaultActive: true }, + [CategoryMap.table]: { title: '表格要素', defaultActive: true }, + [CategoryMap.customStyle]: { title: '自定义样式', defaultActive: true }, +}; diff --git a/src/types/index.ts b/src/types/index.ts index a70e706d..c21d393b 100644 --- a/src/types/index.ts +++ b/src/types/index.ts @@ -1,22 +1,2 @@ -import type { CategoryConfig } from '@c2d2c/types'; - -export enum CategoryMap { - type = 'type', - content = 'content', - function = 'function', - style = 'style', - status = 'status', - bind = 'bind', - table = 'table', - customStyle = 'customStyle', -} - -export const configCategoryMap: CategoryConfig = { - [CategoryMap.type]: { title: '类型', defaultActive: true }, - [CategoryMap.content]: { title: '内容与功能', defaultActive: true }, - [CategoryMap.style]: { title: '样式', defaultActive: true }, - [CategoryMap.status]: { title: '状态', defaultActive: true }, - [CategoryMap.bind]: { title: '分页字段绑定', defaultActive: true }, - [CategoryMap.table]: { title: '表格要素', defaultActive: true }, - [CategoryMap.customStyle]: { title: '自定义样式', defaultActive: true }, -}; +export * from './catogory'; +export * from './schema'; diff --git a/src/ComponentAsset/types/schema.ts b/src/types/schema.ts similarity index 100% rename from src/ComponentAsset/types/schema.ts rename to src/types/schema.ts diff --git a/src/utils/index.ts b/src/utils/index.ts index 54236a51..7f055051 100644 --- a/src/utils/index.ts +++ b/src/utils/index.ts @@ -1 +1,2 @@ export * from './autoId'; +export * from './schema'; diff --git a/src/utils/schema.ts b/src/utils/schema.ts new file mode 100644 index 00000000..5e0b0996 --- /dev/null +++ b/src/utils/schema.ts @@ -0,0 +1,12 @@ +import { JSONSchema } from '@/types/schema'; +/** + * 从schema 获取预设值 + * @param schema + */ +export const getDefaultValueFromSchema = (schema: JSONSchema) => { + if (!schema.properties) return; + + return Object.fromEntries( + Object.entries(schema.properties).map(([key, value]) => [key, value.default]), + ); +};