Skip to content

Commit

Permalink
chore: init
Browse files Browse the repository at this point in the history
  • Loading branch information
imcuttle committed Nov 3, 2023
1 parent 8dac667 commit a9586ff
Show file tree
Hide file tree
Showing 9 changed files with 888 additions and 981 deletions.
9 changes: 7 additions & 2 deletions packages/editor/example/config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ function getSingleConfig(
let entries = entry || paths.appIndexJs

return {
ignoreWarnings: [/Failed to parse source map/],
ignoreWarnings: [/./],
target: target || ['browserslist'],
mode: isEnvProduction ? 'production' : isEnvDevelopment && 'development',
// Stop compilation early in production
Expand Down Expand Up @@ -441,7 +441,7 @@ function getSingleConfig(
// The preset includes JSX, Flow, TypeScript, and some ESnext features.
{
test: /\.(js|mjs|jsx|ts|tsx)$/,
include: paths.appSrc,
include: [paths.appSrc, /@formily\/antd/],
loader: require.resolve('babel-loader'),
options: {
customize: require.resolve('babel-preset-react-app/webpack-overrides'),
Expand All @@ -458,6 +458,11 @@ function getSingleConfig(
plugins: [
...babelPlugins,
['babel-plugin-import', { libraryName: 'antd', style: true }],
[
'babel-plugin-import',
{ libraryName: '@formily/antd', style: true, libraryDirectory: 'esm' },
'babel-plugin-import-formily/antd'
],
isEnvDevelopment && shouldUseReactRefresh && require.resolve('react-refresh/babel')
].filter(Boolean),
// This is a feature of `babel-loader` for webpack (not Babel itself).
Expand Down
9 changes: 7 additions & 2 deletions packages/editor/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
"name": "@mometa/editor",
"version": "0.0.33",
"publishConfig": {
"access": "public"
"access": "public",
"main": "lib",
"module": "es"
},
"author": "imcuttle <imcuttle@163.com>",
"description": "编辑器",
"main": "lib",
"types": "types",
"main": "lib",
"module": "es",
"files": [
"webpack",
Expand Down Expand Up @@ -74,6 +76,9 @@
"@babel/core": "^7.16.7",
"@emotion/css": "^11.7.1",
"@floating-ui/dom": "^0.1.7",
"@formily/antd": "^2.3.0",
"@formily/core": "^2.3.0",
"@formily/react": "^2.3.0",
"@monaco-editor/react": "^4.3.1",
"@rcp/c.preventfastop": "^1.2.0",
"@rcp/use.behaviorsubject": "^1.0.2",
Expand Down
126 changes: 126 additions & 0 deletions packages/editor/src/module/render/components/attr-panel-view/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,126 @@
import { CLS_PREFIX, useSelectedNode } from '../../../config/const'
import { Button, Tooltip, Typography } from 'antd'
import { useShared } from '@rcp/use.shared'
import { ApiServerPack } from '../stage/create-api'
import usePersistFn from '@rcp/use.persistfn'
import { PreventFastClick } from '@rcp/c.preventfastop'
import { isMatch } from 'lodash-es'
import './style.scss'
import p from 'prefix-classname'
import React from 'react'

import { Form, FormItem, Input, Select } from '@formily/antd'
import { createForm } from '@formily/core'
import { Form as AntdForm } from 'antd'
import { createSchemaField, FormProvider } from '@formily/react'

const AntdFormItem = AntdForm.Item

const cn = p('')
const c = p(`${CLS_PREFIX}-attr-panel-view`)

const SchemaField = createSchemaField({
components: {
Input,
Select,
FormItem
}
})

export interface AttrPanelViewProps {}

export default function AttrPanelView({}: AttrPanelViewProps) {
const [selectedNode] = useSelectedNode()
const mometaData = selectedNode?.__mometa?.getMometaData()
const form = React.useMemo(() => createForm(), [])
const [api] = useShared<ApiServerPack>('api' as any)

const UpdateBtn = React.useCallback(
({ onClick, loading, disabled }: any) => (
<Tooltip title={disabled && '未发生更改,不能修改'}>
<Button disabled={disabled} type={'primary'} onClick={onClick} loading={loading}>
更新
</Button>
</Tooltip>
),
[]
)

React.useLayoutEffect(() => {
if (form && mometaData) {
// form.setFieldsValue(cloneDeep(mometaData))
}
}, [form, mometaData])

const onUpdate = usePersistFn(async () => {
// const editData = form.getFieldsValue()
})

if (!mometaData) {
return null
}

return (
<FormProvider form={form}>
<Form layout="vertical">
<FormItem label={'定位'}>
<Typography.Title level={5}>
<Tooltip title={`${mometaData.relativeFilename}:${mometaData.start?.line}:${mometaData.start?.column}`}>
<Typography.Link
onClick={() =>
api.openEditor({
fileName: mometaData.filename,
lineNumber: mometaData.start?.line,
colNumber: mometaData.start?.column
})
}
>
{'📌 '}
{mometaData.name}
</Typography.Link>
</Tooltip>
</Typography.Title>
</FormItem>

<SchemaField
schema={{
type: 'object',
properties: {
input: {
title: 'abc',
type: 'string',
'x-decorator': 'FormItem',
'x-component': 'Input'
},
select: {
title: 'abcxx',
type: 'string',
'x-component': 'Select',
'x-decorator': 'FormItem',
'x-component-props': {
style: {
width: 200,
marginTop: 20
}
}
}
}
}}
/>

<div className={c('__btns')}>
<AntdFormItem noStyle shouldUpdate>
{({ getFieldsValue }) => {
const editData = getFieldsValue()
return (
<PreventFastClick onClick={onUpdate}>
<UpdateBtn disabled={isMatch(mometaData, editData)} />
</PreventFastClick>
)
}}
</AntdFormItem>
</div>
</Form>
</FormProvider>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
@import '../../style/_var';

.#{$prefix}-attr-panel-view {
padding: 0 10px;

&__btns {
display: flex;
justify-content: flex-end;
}
}
27 changes: 6 additions & 21 deletions packages/editor/src/module/render/components/right-panel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import React from 'react'
import p from 'prefix-classname'
import { isEqual, cloneDeep, isMatch } from 'lodash-es'
import { Button, Empty, Form, Input, Tabs, Tooltip, Typography } from 'antd'
import { NumberOutlined } from '@ant-design/icons'
import { CLS_PREFIX, useSelectedNode } from '../../../config/const'

import './style.scss'
Expand All @@ -13,6 +12,7 @@ import { ApiServerPack } from '../stage/create-api'
import { OpType } from '@mometa/fs-handler/const'
import { CodeEditor } from '../../../../shared/code-editor'
import { createPreload } from '../../utils/utils'
import AttrPanelView from '../attr-panel-view'

const cn = p('')
const c = p(`${CLS_PREFIX}-rpanel`)
Expand All @@ -21,7 +21,7 @@ export interface RightPanelProps {
className?: string
}

const BaseInfoForm = () => {
const CodeView = () => {
const [selectedNode] = useSelectedNode()
const mometaData = selectedNode?.__mometa?.getMometaData()
const [form] = Form.useForm()
Expand Down Expand Up @@ -81,24 +81,6 @@ const BaseInfoForm = () => {
// !isDirty && setIsDirty(true)
}}
>
<Form.Item label={'定位'}>
<Typography.Title level={5}>
<Tooltip title={`${mometaData.relativeFilename}:${mometaData.start?.line}:${mometaData.start?.column}`}>
<Typography.Link
onClick={() =>
api.openEditor({
fileName: mometaData.filename,
lineNumber: mometaData.start?.line,
colNumber: mometaData.start?.column
})
}
>
{'📌 '}
{mometaData.name}
</Typography.Link>
</Tooltip>
</Typography.Title>
</Form.Item>
<Form.Item name={'text'} label={'代码'}>
<CodeEditor language={'typescript'} height={'200px'} />
</Form.Item>
Expand Down Expand Up @@ -142,7 +124,10 @@ const RightPanel: React.FC<RightPanelProps> = React.memo(({ className }) => {
{!!mometaData ? (
<Tabs className={c('__tabs')}>
<Tabs.TabPane key={'attr'} tab={'属性'}>
<BaseInfoForm />
<AttrPanelView />
</Tabs.TabPane>
<Tabs.TabPane key={'code'} tab={'代码'}>
<CodeView />
</Tabs.TabPane>
<Tabs.TabPane key={'meta'} tab={'元信息'}>
<MetaInfo />
Expand Down
4 changes: 4 additions & 0 deletions packages/editor/webpack/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ module.exports = class MometaEditorPlugin extends CommonPlugin {
}

if (this.options.react && this.options.react.refresh !== false) {
compiler.options.plugins = compiler.options.plugins.filter(
(plg) => plg?.constructor?.name !== 'ReactRefreshPlugin'
)

const opts = Object.assign(
{
__webpack: this.getWebpack(compiler),
Expand Down
5 changes: 4 additions & 1 deletion packages/materials-generator/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,8 @@
"url": "git+https://github.com/imcuttle/mometa.git",
"directory": "packages/materials-generator"
},
"gitHead": "333b833f49286bef901694a6f84b1248131098a0"
"gitHead": "333b833f49286bef901694a6f84b1248131098a0",
"devDependencies": {
"@formily/json-schema": "^2.3.0"
}
}
4 changes: 4 additions & 0 deletions packages/materials-generator/src/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { SchemaProperties } from '@formily/json-schema'

export interface Material {
name: string
key: any
Expand Down Expand Up @@ -28,6 +30,8 @@ export interface Asset {
code: string // '<Button></Button>'
dependencies?: Record<string, AssetImport> // { Button: { mode: 'named', source: 'antd' } }
sideEffectDependencies?: Array<string>

propsFields?: SchemaProperties<any, any, any, any, any, any, any, any>
}

runtime?: {
Expand Down
Loading

0 comments on commit a9586ff

Please sign in to comment.