From a722dcc34aa54014546b76c14bc845759ab3e971 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 9 Feb 2022 12:50:51 +0800 Subject: [PATCH] extend metadata and set category annotation to core components --- .eslintrc.json | 3 +- .../chakra-ui-lib/src/components/Tabs.tsx | 6 +- packages/core/src/component.ts | 5 +- packages/core/src/metadata.ts | 14 ++- .../JsonSchemaForm/SchemaField.tsx | 1 + .../runtime/src/components/core/Dummy.tsx | 3 + .../src/components/core/GridLayout.tsx | 3 + .../src/components/core/ModuleContainer.tsx | 86 +++++++++---------- packages/runtime/src/components/core/Text.tsx | 3 + 9 files changed, 70 insertions(+), 54 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 71019273..4e8cd4a9 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -25,7 +25,7 @@ "linebreak-style": ["error", "unix"], "no-case-declarations": "off", "no-use-before-define": "off", - "no-unused-vars":"off", + "no-unused-vars": "off", "@typescript-eslint/no-unused-vars": ["error"], "comma-dangle": "off", "space-before-function-paren": "off", @@ -33,6 +33,7 @@ "@typescript-eslint/explicit-module-boundary-types": "off", "@typescript-eslint/no-explicit-any": "off", "@typescript-eslint/no-non-null-assertion": "off", + "@typescript-eslint/ban-types": "off", "react/prop-types": "off", "react/display-name": "off", "react/jsx-uses-react": "off", diff --git a/packages/chakra-ui-lib/src/components/Tabs.tsx b/packages/chakra-ui-lib/src/components/Tabs.tsx index cfe26ea2..0a2bb6a0 100644 --- a/packages/chakra-ui-lib/src/components/Tabs.tsx +++ b/packages/chakra-ui-lib/src/components/Tabs.tsx @@ -1,4 +1,4 @@ -import { useEffect, useState } from 'react'; +import React, { useEffect, useState } from 'react'; import { css } from '@emotion/css'; import { Tabs as BaseTabs, @@ -74,7 +74,9 @@ export default implementRuntimeComponent({ {tabNames.map((_, idx) => { - const ele = slotsElements.content ? ([] as React.ReactElement[]).concat(slotsElements.content)[idx] : placeholder; + const ele = slotsElements.content + ? ([] as React.ReactElement[]).concat(slotsElements.content)[idx] + : placeholder; return ( > = { name: string; description?: string; + annotations?: Record & TAnnotations; }; -export type ComponentMetadata = Metadata & { +type ComponentCategory = + | (string & {}) + | 'Layout' + | 'Input' + | 'Display' + | 'Advance' + | undefined; + +export type ComponentMetadata = Metadata<{ category?: ComponentCategory }> & { + // TODO:(yanzhen): move to annotations isDraggable: boolean; isResizable: boolean; displayName: string; diff --git a/packages/editor/src/components/ComponentForm/JsonSchemaForm/SchemaField.tsx b/packages/editor/src/components/ComponentForm/JsonSchemaForm/SchemaField.tsx index ade3789e..ee9d0d63 100644 --- a/packages/editor/src/components/ComponentForm/JsonSchemaForm/SchemaField.tsx +++ b/packages/editor/src/components/ComponentForm/JsonSchemaForm/SchemaField.tsx @@ -134,6 +134,7 @@ const SchemaField: React.FC = props => { return ( { - if (!type) { - return Please choose a module to render. - } - if (!id) { - return Please set a id for module. - } - - return ( - - ); - }) \ No newline at end of file + }, + spec: { + properties: ModuleSchema, + state: {}, + methods: {}, + slots: [], + styleSlots: [], + events: [], + }, +})(({ id, type, properties, handlers, services, app }) => { + if (!type) { + return Please choose a module to render.; + } + if (!id) { + return Please set a id for module.; + } + + return ( + + ); +}); diff --git a/packages/runtime/src/components/core/Text.tsx b/packages/runtime/src/components/core/Text.tsx index 31739bea..2ef6897e 100644 --- a/packages/runtime/src/components/core/Text.tsx +++ b/packages/runtime/src/components/core/Text.tsx @@ -25,6 +25,9 @@ export default implementRuntimeComponent({ }, }, exampleSize: [4, 1], + annotations: { + category: 'Display', + }, }, spec: { properties: PropsSchema,